rippled
Loading...
Searching...
No Matches
Message.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_OVERLAY_MESSAGE_H_INCLUDED
21#define RIPPLE_OVERLAY_MESSAGE_H_INCLUDED
22
23#include <xrpld/overlay/Compression.h>
24
25#include <xrpl/basics/ByteUtilities.h>
26#include <xrpl/protocol/PublicKey.h>
27#include <xrpl/protocol/messages.h>
28
29#include <algorithm>
30#include <cstdint>
31
32namespace ripple {
33
35
36// VFALCO NOTE If we forward declare Message and write out shared_ptr
37// instead of using the in-class type alias, we can remove the
38// entire ripple.pb.h from the main headers.
39//
40
41// packaging of messages into length/type-prepended buffers
42// ready for transmission.
43//
44// Message implements simple "packing" of protocol buffers Messages into
45// a string prepended by a header specifying the message length.
46// MessageType should be a Message class generated by the protobuf compiler.
47//
48
50{
53
54public:
61 Message(
62 ::google::protobuf::Message const& message,
63 protocol::MessageType type,
65
69
70 static std::size_t
71 messageSize(::google::protobuf::Message const& message);
72
73 static std::size_t
74 totalSize(::google::protobuf::Message const& message);
75
83 getBuffer(Compressed tryCompressed);
84
88 {
89 return category_;
90 }
91
95 {
96 return validatorKey_;
97 }
98
99private:
105
114 void
115 setHeader(
117 std::uint32_t payloadBytes,
118 int type,
119 Algorithm compression,
120 std::uint32_t uncompressedBytes);
121
126 void
127 compress();
128
135 int
136 getType(std::uint8_t const* in) const;
137};
138
139} // namespace ripple
140
141#endif
std::size_t category_
Definition: Message.h:102
std::once_flag once_flag_
Definition: Message.h:103
std::size_t getCategory() const
Get the traffic category.
Definition: Message.h:87
compression::Compressed Compressed
Definition: Message.h:51
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:174
std::vector< uint8_t > const & getBuffer(Compressed tryCompressed)
Retrieve the packed message data.
Definition: Message.cpp:210
std::size_t getBufferSize()
Retrieve the size of the packed but uncompressed message data.
Definition: Message.cpp:204
std::optional< PublicKey > const & getValidatorKey() const
Get the validator's key.
Definition: Message.h:94
static std::size_t totalSize(::google::protobuf::Message const &message)
Definition: Message.cpp:66
std::optional< PublicKey > validatorKey_
Definition: Message.h:104
std::vector< uint8_t > buffer_
Definition: Message.h:100
std::vector< uint8_t > bufferCompressed_
Definition: Message.h:101
int getType(std::uint8_t const *in) const
Get the message type from the payload header.
Definition: Message.cpp:224
void compress()
Try to compress the payload.
Definition: Message.cpp:72
static std::size_t messageSize(::google::protobuf::Message const &message)
Definition: Message.cpp:55
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
Definition: envconfig.cpp:113
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr auto megabytes(T value) noexcept
Definition: ByteUtilities.h:34
constexpr std::size_t maximiumMessageSize
Definition: Message.h:34