mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Split peer connect logic to another class (RIPD-711):
All of the logic for establishing an outbound peer connection including the initial HTTP handshake exchange is moved into a separate class. This allows PeerImp to have a strong invariant: All PeerImp objects that exist represent active peer connections that have already gone through the handshake process.
This commit is contained in:
committed by
Nik Bougalis
parent
930a0beaf1
commit
32062e439f
@@ -136,6 +136,29 @@ invokeProtocolMessage (Buffers const& buffers, Handler& handler)
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Write a protocol message to a streambuf. */
|
||||
template <class Streambuf>
|
||||
void
|
||||
write (Streambuf& streambuf,
|
||||
::google::protobuf::Message const& m, int type,
|
||||
std::size_t blockBytes)
|
||||
{
|
||||
auto const size = m.ByteSize();
|
||||
std::array<std::uint8_t, 6> v;
|
||||
v[0] = static_cast<std::uint8_t> ((size >> 24) & 0xFF);
|
||||
v[1] = static_cast<std::uint8_t> ((size >> 16) & 0xFF);
|
||||
v[2] = static_cast<std::uint8_t> ((size >> 8) & 0xFF);
|
||||
v[3] = static_cast<std::uint8_t> ( size & 0xFF);
|
||||
v[4] = static_cast<std::uint8_t> ((type >> 8) & 0xFF);
|
||||
v[5] = static_cast<std::uint8_t> ( type & 0xFF);
|
||||
|
||||
streambuf.commit(boost::asio::buffer_copy(
|
||||
streambuf.prepare(Message::kHeaderBytes), boost::asio::buffer(v)));
|
||||
ZeroCopyOutputStream<Streambuf> stream (
|
||||
streambuf, blockBytes);
|
||||
m.SerializeToZeroCopyStream(&stream);
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user