|
@ -33,6 +33,22 @@ namespace dev |
|
|
namespace p2p |
|
|
namespace p2p |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
struct RLPXFrameDecrytFailed: virtual dev::Exception {}; |
|
|
|
|
|
|
|
|
|
|
|
struct RLPXFrameInfo |
|
|
|
|
|
{ |
|
|
|
|
|
RLPXFrameInfo() = default; |
|
|
|
|
|
/// Constructor. frame-size || protocol-type, [sequence-id[, total-packet-size]]
|
|
|
|
|
|
RLPXFrameInfo(bytesConstRef _frameHeader); |
|
|
|
|
|
uint32_t length = 0; ///< Max: 2**24
|
|
|
|
|
|
uint8_t padding = 0; |
|
|
|
|
|
|
|
|
|
|
|
uint16_t protocolId = 0; |
|
|
|
|
|
bool hasSequence = false; |
|
|
|
|
|
uint16_t sequenceId = 0; |
|
|
|
|
|
uint32_t totalLength = 0; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* RLPFrameReader |
|
|
* RLPFrameReader |
|
|
* Reads and assembles RLPX frame byte buffers into RLPX packets. Additionally |
|
|
* Reads and assembles RLPX frame byte buffers into RLPX packets. Additionally |
|
@ -43,11 +59,15 @@ namespace p2p |
|
|
*/ |
|
|
*/ |
|
|
class RLPXFrameReader |
|
|
class RLPXFrameReader |
|
|
{ |
|
|
{ |
|
|
|
|
|
public: |
|
|
RLPXFrameReader(uint16_t _protocolType): m_protocolType(_protocolType) {} |
|
|
RLPXFrameReader(uint16_t _protocolType): m_protocolType(_protocolType) {} |
|
|
|
|
|
|
|
|
/// Processes a single frame returning complete packets.
|
|
|
/// Processes a single frame returning complete packets.
|
|
|
std::vector<RLPXPacket> demux(bytes& _frame, bool _sequence = false, uint16_t _seq = 0, uint32_t _totalSize = 0) |
|
|
std::vector<RLPXPacket> demux(RLPXFrameCoder& _coder, bytes& _frame, bool _sequence = false, uint16_t _seq = 0, uint32_t _totalSize = 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!_coder.authAndDecryptFrame(&_frame)) |
|
|
|
|
|
BOOST_THROW_EXCEPTION(RLPXFrameDecrytFailed()); |
|
|
|
|
|
|
|
|
std::vector<RLPXPacket> ret; |
|
|
std::vector<RLPXPacket> ret; |
|
|
if (!_frame.size() || _frame.size() > _totalSize) |
|
|
if (!_frame.size() || _frame.size() > _totalSize) |
|
|
return ret; |
|
|
return ret; |
|
@ -100,6 +120,11 @@ protected: |
|
|
std::map<uint16_t, std::pair<RLPXPacket, uint32_t>> m_incomplete; ///< Incomplete packets and bytes remaining.
|
|
|
std::map<uint16_t, std::pair<RLPXPacket, uint32_t>> m_incomplete; ///< Incomplete packets and bytes remaining.
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* RLPXFrameWriter |
|
|
|
|
|
* Multiplex and encrypted packets into RLPX frames. |
|
|
|
|
|
* @todo flag to disable multiple packets per frame |
|
|
|
|
|
*/ |
|
|
class RLPXFrameWriter |
|
|
class RLPXFrameWriter |
|
|
{ |
|
|
{ |
|
|
struct QueueState |
|
|
struct QueueState |
|
|