TARAXA
dev::p2p::RLPXFrameCoder Class Reference

Encoder/decoder transport for RLPx connection established by RLPXHandshake. More...

#include <RLPXFrameCoder.h>

Collaboration diagram for dev::p2p::RLPXFrameCoder:

Public Member Functions

 RLPXFrameCoder (RLPXHandshake const &_init)
 
 RLPXFrameCoder (bool _originated, h512 const &_remoteEphemeral, h256 const &_remoteNonce, KeyPair const &_ecdheLocal, h256 const &_nonce, bytesConstRef _ackCipher, bytesConstRef _authCipher)
 Construct with external key material. More...
 
 ~RLPXFrameCoder ()
 
void writeSingleFramePacket (bytesConstRef _packet, bytes &o_bytes)
 Legacy. Encrypt _packet as ill-defined legacy RLPx frame. More...
 
bool authAndDecryptHeader (bytesRef io_cipherWithMac)
 Authenticate and decrypt header in-place. More...
 
bool authAndDecryptFrame (bytesRef io_cipherWithMac)
 Authenticate and decrypt frame in-place. More...
 
h128 egressDigest ()
 Return first 16 bytes of current digest from egress mac. More...
 
h128 ingressDigest ()
 Return first 16 bytes of current digest from ingress mac. More...
 

Private Types

enum class  ProtocolIdType : uint16_t { Normal = 0 , Compressed }
 

Private Member Functions

void writeFrame (uint16_t _seqId, bytesConstRef _payload, bytes &o_bytes)
 Write continuation frame of segmented payload. More...
 
void writeFrame (bytesConstRef _header, bytesConstRef _payload, bytes &o_bytes)
 
uint32_t decompressFrame (bytesRef payload, bytes &output) const
 Compression. More...
 
void LZ4compress (bytesConstRef payload, bytes &output) const
 
void writeCompressedFrame (uint16_t _seqId, bytesConstRef _payload, bytes &o_bytes)
 
void writeCompressedFrame (uint16_t _seqId, uint32_t _totalSize, bytesConstRef _payload, bytes &o_bytes)
 
void updateEgressMACWithHeader (bytesConstRef _headerCipher)
 Update state of egress MAC with frame header. More...
 
void updateEgressMACWithFrame (bytesConstRef _cipher)
 Update state of egress MAC with frame. More...
 
void updateIngressMACWithHeader (bytesConstRef _headerCipher)
 Update state of ingress MAC with frame header. More...
 
void updateIngressMACWithFrame (bytesConstRef _cipher)
 Update state of ingress MAC with frame. More...
 
void setup (bool _originated, h512 const &_remoteEphemeral, h256 const &_remoteNonce, KeyPair const &_ecdheLocal, h256 const &_nonce, bytesConstRef _ackCipher, bytesConstRef _authCipher)
 Establish shared secrets and setup AES and MAC states. More...
 

Private Attributes

std::unique_ptr< class RLPXFrameCoderImplm_impl
 

Static Private Attributes

static constexpr size_t MAX_PACKET_SIZE = 15 * 1024 * 1024
 

Friends

struct Session
 

Detailed Description

Encoder/decoder transport for RLPx connection established by RLPXHandshake.

Todo:

rename to RLPXTranscoder

Remove 'Frame' nomenclature and expect caller to provide RLPXFrame

Remove handshake as friend, remove handshake-based constructor

Thread Safety Distinct Objects: Unsafe. Shared objects: Unsafe.

Member Enumeration Documentation

◆ ProtocolIdType

enum dev::p2p::RLPXFrameCoder::ProtocolIdType : uint16_t
strongprivate
Enumerator
Normal 
Compressed 

Constructor & Destructor Documentation

◆ RLPXFrameCoder() [1/2]

RLPXFrameCoder::RLPXFrameCoder ( RLPXHandshake const &  _init)
explicit

Construct; requires instance of RLPXHandshake which has encrypted ECDH key exchange (first two phases of handshake).

◆ RLPXFrameCoder() [2/2]

RLPXFrameCoder::RLPXFrameCoder ( bool  _originated,
h512 const &  _remoteEphemeral,
h256 const &  _remoteNonce,
KeyPair const &  _ecdheLocal,
h256 const &  _nonce,
bytesConstRef  _ackCipher,
bytesConstRef  _authCipher 
)

Construct with external key material.

◆ ~RLPXFrameCoder()

RLPXFrameCoder::~RLPXFrameCoder ( )

Member Function Documentation

◆ authAndDecryptFrame()

bool RLPXFrameCoder::authAndDecryptFrame ( bytesRef  io_cipherWithMac)

Authenticate and decrypt frame in-place.

◆ authAndDecryptHeader()

bool RLPXFrameCoder::authAndDecryptHeader ( bytesRef  io_cipherWithMac)

Authenticate and decrypt header in-place.

◆ decompressFrame()

uint32_t RLPXFrameCoder::decompressFrame ( bytesRef  payload,
bytes output 
) const
private

Compression.

◆ egressDigest()

dev::h128 RLPXFrameCoder::egressDigest ( )

Return first 16 bytes of current digest from egress mac.

◆ ingressDigest()

dev::h128 RLPXFrameCoder::ingressDigest ( )

Return first 16 bytes of current digest from ingress mac.

◆ LZ4compress()

void RLPXFrameCoder::LZ4compress ( bytesConstRef  payload,
bytes output 
) const
private

◆ setup()

void RLPXFrameCoder::setup ( bool  _originated,
h512 const &  _remoteEphemeral,
h256 const &  _remoteNonce,
KeyPair const &  _ecdheLocal,
h256 const &  _nonce,
bytesConstRef  _ackCipher,
bytesConstRef  _authCipher 
)
private

Establish shared secrets and setup AES and MAC states.

◆ updateEgressMACWithFrame()

void RLPXFrameCoder::updateEgressMACWithFrame ( bytesConstRef  _cipher)
private

Update state of egress MAC with frame.

◆ updateEgressMACWithHeader()

void RLPXFrameCoder::updateEgressMACWithHeader ( bytesConstRef  _headerCipher)
private

Update state of egress MAC with frame header.

◆ updateIngressMACWithFrame()

void RLPXFrameCoder::updateIngressMACWithFrame ( bytesConstRef  _cipher)
private

Update state of ingress MAC with frame.

◆ updateIngressMACWithHeader()

void RLPXFrameCoder::updateIngressMACWithHeader ( bytesConstRef  _headerCipher)
private

Update state of ingress MAC with frame header.

◆ writeCompressedFrame() [1/2]

void RLPXFrameCoder::writeCompressedFrame ( uint16_t  _seqId,
bytesConstRef  _payload,
bytes o_bytes 
)
private

◆ writeCompressedFrame() [2/2]

void RLPXFrameCoder::writeCompressedFrame ( uint16_t  _seqId,
uint32_t  _totalSize,
bytesConstRef  _payload,
bytes o_bytes 
)
private

◆ writeFrame() [1/2]

void RLPXFrameCoder::writeFrame ( bytesConstRef  _header,
bytesConstRef  _payload,
bytes o_bytes 
)
private

◆ writeFrame() [2/2]

void RLPXFrameCoder::writeFrame ( uint16_t  _seqId,
bytesConstRef  _payload,
bytes o_bytes 
)
private

Write continuation frame of segmented payload.

◆ writeSingleFramePacket()

void RLPXFrameCoder::writeSingleFramePacket ( bytesConstRef  _packet,
bytes o_bytes 
)

Legacy. Encrypt _packet as ill-defined legacy RLPx frame.

Friends And Related Function Documentation

◆ Session

friend struct Session
friend

Member Data Documentation

◆ m_impl

std::unique_ptr<class RLPXFrameCoderImpl> dev::p2p::RLPXFrameCoder::m_impl
private

◆ MAX_PACKET_SIZE

constexpr size_t dev::p2p::RLPXFrameCoder::MAX_PACKET_SIZE = 15 * 1024 * 1024
staticconstexprprivate

The documentation for this class was generated from the following files: