rippled
Loading...
Searching...
No Matches
Message.h
1#ifndef XRPL_OVERLAY_MESSAGE_H_INCLUDED
2#define XRPL_OVERLAY_MESSAGE_H_INCLUDED
3
4#include <xrpld/overlay/Compression.h>
5
6#include <xrpl/basics/ByteUtilities.h>
7#include <xrpl/protocol/PublicKey.h>
8#include <xrpl/protocol/messages.h>
9
10#include <algorithm>
11#include <cstdint>
12
13namespace ripple {
14
16
17// VFALCO NOTE If we forward declare Message and write out shared_ptr
18// instead of using the in-class type alias, we can remove the
19// entire ripple.pb.h from the main headers.
20//
21
22// packaging of messages into length/type-prepended buffers
23// ready for transmission.
24//
25// Message implements simple "packing" of protocol buffers Messages into
26// a string prepended by a header specifying the message length.
27// MessageType should be a Message class generated by the protobuf compiler.
28//
29
31{
34
35public:
42 Message(
43 ::google::protobuf::Message const& message,
44 protocol::MessageType type,
45 std::optional<PublicKey> const& validator = {});
46
50
51 static std::size_t
52 messageSize(::google::protobuf::Message const& message);
53
54 static std::size_t
55 totalSize(::google::protobuf::Message const& message);
56
64 getBuffer(Compressed tryCompressed);
65
69 {
70 return category_;
71 }
72
76 {
77 return validatorKey_;
78 }
79
80private:
86
95 void
98 std::uint32_t payloadBytes,
99 int type,
100 Algorithm compression,
101 std::uint32_t uncompressedBytes);
102
107 void
108 compress();
109
116 int
117 getType(std::uint8_t const* in) const;
118};
119
120} // namespace ripple
121
122#endif
std::size_t category_
Definition Message.h:83
std::once_flag once_flag_
Definition Message.h:84
std::size_t getCategory() const
Get the traffic category.
Definition Message.h:68
compression::Compressed Compressed
Definition Message.h:32
void setHeader(std::uint8_t *in, std::uint32_t payloadBytes, int type, Algorithm compression, std::uint32_t uncompressedBytes)
Set the payload header.
Definition Message.cpp:155
std::vector< uint8_t > const & getBuffer(Compressed tryCompressed)
Retrieve the packed message data.
Definition Message.cpp:191
std::size_t getBufferSize()
Retrieve the size of the packed but uncompressed message data.
Definition Message.cpp:185
std::optional< PublicKey > const & getValidatorKey() const
Get the validator's key.
Definition Message.h:75
static std::size_t totalSize(::google::protobuf::Message const &message)
Definition Message.cpp:47
std::optional< PublicKey > validatorKey_
Definition Message.h:85
std::vector< uint8_t > buffer_
Definition Message.h:81
std::vector< uint8_t > bufferCompressed_
Definition Message.h:82
int getType(std::uint8_t const *in) const
Get the message type from the payload header.
Definition Message.cpp:205
void compress()
Try to compress the payload.
Definition Message.cpp:53
static std::size_t messageSize(::google::protobuf::Message const &message)
Definition Message.cpp:36
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
constexpr auto megabytes(T value) noexcept
constexpr std::size_t maximiumMessageSize
Definition Message.h:15