29 uint32_t
const RLPXSocketIO::MinFrameSize =
h128::size * 3;
30 uint32_t
const RLPXSocketIO::MaxPacketSize = 1 << 24;
31 uint16_t
const RLPXSocketIO::DefaultInitialCapacity = 8 << 8;
33 RLPXSocketIO::RLPXSocketIO(
unsigned _protCount,
RLPXFrameCoder& _coder, bi::tcp::socket& _socket,
bool _flowControl,
size_t _initialCapacity):
34 m_flowControl(_flowControl),
37 m_writers(writers(_protCount)),
38 m_egressCapacity(m_flowControl ? _initialCapacity : MaxPacketSize * m_writers.
size())
43 vector<RLPXFrameWriter> ret;
44 for (
unsigned i = 0; i < _capacity; i++)
53 m_writers.at(_protocolType).enque(_type, _payload);
54 bool wasEmtpy =
false;
74 size_t protFrameSize = capacity / active;
76 for (
auto& w: m_writers)
87 auto self(shared_from_this());
89 m_congestion->expires_from_now(boost::posix_time::milliseconds(50));
95 auto self(shared_from_this());
99 ba::async_write(
m_socket, ba::buffer(
m_toSend[0]), [
this,
self, _dequed](boost::system::error_code ec,
size_t written)
104 bool reschedule =
false;
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
static std::vector< RLPXFrameWriter > writers(unsigned _capacity)
std::deque< bytes > m_toSend
Reusable byte buffer for pending socket writes.
unsigned m_queued
Track total queued packets to ensure single write loop.
std::hash for asio::adress
std::unique_ptr< ba::deadline_timer > m_congestion
Scheduled when writes are deferred due to congestion.
std::vector< RLPXFrameWriter > m_writers
Write queues for each protocol. TODO: map to bytes (of capability)
void send(unsigned _protocolType, unsigned _type, RLPStream &_payload)
bi::tcp::socket & m_socket
#define DEV_GUARDED(MUTEX)
Simple block guard.
static uint32_t const MinFrameSize
bool const m_flowControl
True if flow control is enabled.
void write(size_t _dequed)
RLPXFrameCoder & m_coder
Encoder/decoder of frame payloads.
uint8_t const size_t const size
uint32_t m_egressCapacity
Class for writing to an RLP bytestream.
Encoder/decoder transport for RLPx connection established by RLPXHandshake.
static uint32_t const MaxPacketSize
Multiplex packets into encrypted RLPX frames.