rippled
Loading...
Searching...
No Matches
Handshake.h
1#ifndef XRPL_OVERLAY_HANDSHAKE_H_INCLUDED
2#define XRPL_OVERLAY_HANDSHAKE_H_INCLUDED
3
4#include <xrpld/app/main/Application.h>
5#include <xrpld/overlay/detail/ProtocolVersion.h>
6
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/protocol/BuildInfo.h>
9
10#include <boost/asio/ssl.hpp>
11#include <boost/beast/core/tcp_stream.hpp>
12#include <boost/beast/http/dynamic_body.hpp>
13#include <boost/beast/http/empty_body.hpp>
14#include <boost/beast/http/fields.hpp>
15#include <boost/beast/ssl/ssl_stream.hpp>
16
17#include <optional>
18#include <utility>
19
20namespace ripple {
21
22using socket_type = boost::beast::tcp_stream;
23using stream_type = boost::beast::ssl_stream<socket_type>;
25 boost::beast::http::request<boost::beast::http::empty_body>;
27 boost::beast::http::request<boost::beast::http::dynamic_body>;
29 boost::beast::http::response<boost::beast::http::dynamic_body>;
30
42
45void
47 boost::beast::http::fields& h,
48 uint256 const& sharedValue,
50 beast::IP::Address public_ip,
51 beast::IP::Address remote_ip,
52 Application& app);
53
67 boost::beast::http::fields const& headers,
68 uint256 const& sharedValue,
70 beast::IP::Address public_ip,
71 beast::IP::Address remote,
72 Application& app);
73
87 bool crawlPublic,
88 bool comprEnabled,
89 bool ledgerReplayEnabled,
90 bool txReduceRelayEnabled,
91 bool vpReduceRelayEnabled);
92
107 bool crawlPublic,
108 http_request_type const& req,
109 beast::IP::Address public_ip,
110 beast::IP::Address remote_ip,
111 uint256 const& sharedValue,
113 ProtocolVersion version,
114 Application& app);
115
116// Protocol features negotiated via HTTP handshake.
117// The format is:
118// X-Protocol-Ctl: feature1=value1[,value2]*[\s*;\s*feature2=value1[,value2]*]*
119// value: \S+
120
121// compression feature
122static constexpr char FEATURE_COMPR[] = "compr";
123// validation/proposal reduce-relay base squelch feature
124static constexpr char FEATURE_VPRR[] = "vprr";
125// transaction reduce-relay feature
126static constexpr char FEATURE_TXRR[] = "txrr";
127// ledger replay
128static constexpr char FEATURE_LEDGER_REPLAY[] = "ledgerreplay";
129static constexpr char DELIM_FEATURE[] = ";";
130static constexpr char DELIM_VALUE[] = ",";
131
140 boost::beast::http::fields const& headers,
141 std::string const& feature);
142
151bool
153 boost::beast::http::fields const& headers,
154 std::string const& feature,
155 std::string const& value);
156
162bool
164 boost::beast::http::fields const& headers,
165 std::string const& feature);
166
177template <typename headers>
178bool
180 headers const& request,
181 std::string const& feature,
182 std::string value,
183 bool config)
184{
185 return config && isFeatureValue(request, feature, value);
186}
187
189template <typename headers>
190bool
192 headers const& request,
193 std::string const& feature,
194 bool config)
195{
196 return config && peerFeatureEnabled(request, feature, "1", config);
197}
198
210 bool comprEnabled,
211 bool ledgerReplayEnabled,
212 bool txReduceRelayEnabled,
213 bool vpReduceRelayEnabled);
214
230 http_request_type const& headers,
231 bool comprEnabled,
232 bool ledgerReplayEnabled,
233 bool txReduceRelayEnabled,
234 bool vpReduceRelayEnabled);
235
236} // namespace ripple
237
238#endif
A generic endpoint for log messages.
Definition Journal.h:41
A public key.
Definition PublicKey.h:43
boost::asio::ip::address Address
Definition IPAddress.h:20
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
boost::beast::ssl_stream< socket_type > stream_type
Definition Handshake.h:23
std::string makeFeaturesResponseHeader(http_request_type const &headers, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make response header X-Protocol-Ctl value with supported features.
Definition Handshake.cpp:75
static constexpr char DELIM_FEATURE[]
Definition Handshake.h:129
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_type
Definition Handoff.h:17
void buildHandshake(boost::beast::http::fields &h, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote_ip, Application &app)
Insert fields headers necessary for upgrading the link to the peer protocol.
static constexpr char FEATURE_COMPR[]
Definition Handshake.h:122
static constexpr char DELIM_VALUE[]
Definition Handshake.h:130
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
Definition Handshake.cpp:56
http_response_type makeResponse(bool crawlPublic, http_request_type const &req, beast::IP::Address public_ip, beast::IP::Address remote_ip, uint256 const &sharedValue, std::optional< std::uint32_t > networkID, ProtocolVersion protocol, Application &app)
Make http response.
static constexpr char FEATURE_LEDGER_REPLAY[]
Definition Handshake.h:128
bool isFeatureValue(boost::beast::http::fields const &headers, std::string const &feature, std::string const &value)
Check if a feature's value is equal to the specified value.
Definition Handshake.cpp:36
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:14
bool featureEnabled(boost::beast::http::fields const &headers, std::string const &feature)
Check if a feature is enabled.
Definition Handshake.cpp:48
std::optional< std::string > getFeatureValue(boost::beast::http::fields const &headers, std::string const &feature)
Get feature's header value.
Definition Handshake.cpp:20
bool peerFeatureEnabled(headers const &request, std::string const &feature, std::string value, bool config)
Check if a feature should be enabled for a peer.
Definition Handshake.h:179
static constexpr char FEATURE_TXRR[]
Definition Handshake.h:126
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
boost::beast::http::request< boost::beast::http::empty_body > request_type
Definition Handshake.h:25
PublicKey verifyHandshake(boost::beast::http::fields const &headers, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote, Application &app)
Validate header fields necessary for upgrading the link to the peer protocol.
boost::beast::tcp_stream socket_type
Definition Handshake.h:22
static constexpr char FEATURE_VPRR[]
Definition Handshake.h:124