rippled
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ripple::Message Class Reference
Inheritance diagram for ripple::Message:
Inheritance graph
[legend]
Collaboration diagram for ripple::Message:
Collaboration graph
[legend]

Public Member Functions

 Message (::google::protobuf::Message const &message, int type, std::optional< PublicKey > const &validator={})
 Constructor. More...
 
std::size_t getBufferSize ()
 Retrieve the size of the packed but uncompressed message data. More...
 
std::vector< uint8_t > const & getBuffer (Compressed tryCompressed)
 Retrieve the packed message data. More...
 
std::size_t getCategory () const
 Get the traffic category. More...
 
std::optional< PublicKey > const & getValidatorKey () const
 Get the validator's key. More...
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 

Static Public Member Functions

static std::size_t messageSize (::google::protobuf::Message const &message)
 
static std::size_t totalSize (::google::protobuf::Message const &message)
 

Private Types

using Compressed = compression::Compressed
 
using Algorithm = compression::Algorithm
 

Private Member Functions

void setHeader (std::uint8_t *in, std::uint32_t payloadBytes, int type, Algorithm compression, std::uint32_t uncompressedBytes)
 Set the payload header. More...
 
void compress ()
 Try to compress the payload. More...
 
int getType (std::uint8_t const *in) const
 Get the message type from the payload header. More...
 

Private Attributes

std::vector< uint8_t > buffer_
 
std::vector< uint8_t > bufferCompressed_
 
std::size_t category_
 
std::once_flag once_flag_
 
std::optional< PublicKeyvalidatorKey_
 

Detailed Description

Definition at line 53 of file overlay/Message.h.

Member Typedef Documentation

◆ Compressed

Definition at line 55 of file overlay/Message.h.

◆ Algorithm

Definition at line 56 of file overlay/Message.h.

Constructor & Destructor Documentation

◆ Message()

ripple::Message::Message ( ::google::protobuf::Message const &  message,
int  type,
std::optional< PublicKey > const &  validator = {} 
)

Constructor.

Parameters
messageProtocol message to serialize
typeProtocol message type
validatorPublic Key of the source validator for Validation or Proposal message. Used to check if the message should be squelched.

Definition at line 26 of file Message.cpp.

Member Function Documentation

◆ getBufferSize()

std::size_t ripple::Message::getBufferSize ( )

Retrieve the size of the packed but uncompressed message data.

Definition at line 204 of file Message.cpp.

◆ messageSize()

std::size_t ripple::Message::messageSize ( ::google::protobuf::Message const &  message)
static

Definition at line 51 of file Message.cpp.

◆ totalSize()

std::size_t ripple::Message::totalSize ( ::google::protobuf::Message const &  message)
static

Definition at line 62 of file Message.cpp.

◆ getBuffer()

std::vector< uint8_t > const & ripple::Message::getBuffer ( Compressed  tryCompressed)

Retrieve the packed message data.

If compressed message is requested but the message is not compressible then the uncompressed buffer is returned.

Parameters
compressedRequest compressed (Compress::On) or uncompressed (Compress::Off) payload buffer
Returns
Payload buffer

Definition at line 210 of file Message.cpp.

◆ getCategory()

std::size_t ripple::Message::getCategory ( ) const

Get the traffic category.

Definition at line 91 of file overlay/Message.h.

◆ getValidatorKey()

std::optional<PublicKey> const& ripple::Message::getValidatorKey ( ) const

Get the validator's key.

Definition at line 98 of file overlay/Message.h.

◆ setHeader()

void ripple::Message::setHeader ( std::uint8_t in,
std::uint32_t  payloadBytes,
int  type,
Algorithm  compression,
std::uint32_t  uncompressedBytes 
)
private

Set the payload header.

Set payload header.

Parameters
inPointer to the payload
payloadBytesSize of the payload excluding the header size
typeProtocol message type
compressionCompression algorithm used in compression, currently LZ4 only. If None then the message is uncompressed.
uncompressedBytesSize of the uncompressed message

The header is a variable-sized structure that contains information about the type of the message and the length and encoding of the payload.

The first bit determines whether a message is compressed or uncompressed; for compressed messages, the next three bits identify the compression algorithm.

All multi-byte values are represented in big endian.

For uncompressed messages (6 bytes), numbering bits from left to right:

- The first 6 bits are set to 0.
- The next 26 bits represent the payload size.
- The remaining 16 bits represent the message type.

For compressed messages (10 bytes), numbering bits from left to right:

- The first 32 bits, together, represent the compression algorithm
  and payload size:
    - The first bit is set to 1 to indicate the message is compressed.
    - The next 3 bits indicate the compression algorithm.
    - The next 2 bits are reserved at this time and set to 0.
    - The remaining 26 bits represent the payload size.
- The next 16 bits represent the message type.
- The remaining 32 bits are the uncompressed message size.

The maximum size of a message at this time is 64 MB. Messages larger than this will be dropped and the recipient may, at its option, sever the link.

Note
While nominally a part of the wire protocol, the framing is subject to change; future versions of the code may negotiate the use of substantially different framing.

Definition at line 174 of file Message.cpp.

◆ compress()

void ripple::Message::compress ( )
private

Try to compress the payload.

Can be called concurrently by multiple peers but is compressed once. If the message is not compressible then the serialized buffer_ is used.

Definition at line 68 of file Message.cpp.

◆ getType()

int ripple::Message::getType ( std::uint8_t const *  in) const
private

Get the message type from the payload header.

First four bytes are the compression/algorithm flag and the payload size. Next two bytes are the message type

Parameters
inPayload header pointer
Returns
Message type

Definition at line 224 of file Message.cpp.

Member Data Documentation

◆ buffer_

std::vector<uint8_t> ripple::Message::buffer_
private

Definition at line 104 of file overlay/Message.h.

◆ bufferCompressed_

std::vector<uint8_t> ripple::Message::bufferCompressed_
private

Definition at line 105 of file overlay/Message.h.

◆ category_

std::size_t ripple::Message::category_
private

Definition at line 106 of file overlay/Message.h.

◆ once_flag_

std::once_flag ripple::Message::once_flag_
private

Definition at line 107 of file overlay/Message.h.

◆ validatorKey_

std::optional<PublicKey> ripple::Message::validatorKey_
private

Definition at line 108 of file overlay/Message.h.