rippled
Loading...
Searching...
No Matches
Handshake.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/overlay/detail/ProtocolVersion.h>
5
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/protocol/BuildInfo.h>
8
9#include <boost/asio/ssl.hpp>
10#include <boost/beast/core/tcp_stream.hpp>
11#include <boost/beast/http/dynamic_body.hpp>
12#include <boost/beast/http/empty_body.hpp>
13#include <boost/beast/http/fields.hpp>
14#include <boost/beast/ssl/ssl_stream.hpp>
15
16#include <optional>
17#include <utility>
18
19namespace xrpl {
20
21using socket_type = boost::beast::tcp_stream;
22using stream_type = boost::beast::ssl_stream<socket_type>;
23using request_type = boost::beast::http::request<boost::beast::http::empty_body>;
24using http_request_type = boost::beast::http::request<boost::beast::http::dynamic_body>;
25using http_response_type = boost::beast::http::response<boost::beast::http::dynamic_body>;
26
38
41void
43 boost::beast::http::fields& h,
44 uint256 const& sharedValue,
46 beast::IP::Address public_ip,
47 beast::IP::Address remote_ip,
48 Application& app);
49
63 boost::beast::http::fields const& headers,
64 uint256 const& sharedValue,
66 beast::IP::Address public_ip,
67 beast::IP::Address remote,
68 Application& app);
69
83 bool crawlPublic,
84 bool comprEnabled,
85 bool ledgerReplayEnabled,
86 bool txReduceRelayEnabled,
87 bool vpReduceRelayEnabled);
88
103 bool crawlPublic,
104 http_request_type const& req,
105 beast::IP::Address public_ip,
106 beast::IP::Address remote_ip,
107 uint256 const& sharedValue,
109 ProtocolVersion version,
110 Application& app);
111
112// Protocol features negotiated via HTTP handshake.
113// The format is:
114// X-Protocol-Ctl: feature1=value1[,value2]*[\s*;\s*feature2=value1[,value2]*]*
115// value: \S+
116
117// compression feature
118static constexpr char FEATURE_COMPR[] = "compr";
119// validation/proposal reduce-relay base squelch feature
120static constexpr char FEATURE_VPRR[] = "vprr";
121// transaction reduce-relay feature
122static constexpr char FEATURE_TXRR[] = "txrr";
123// ledger replay
124static constexpr char FEATURE_LEDGER_REPLAY[] = "ledgerreplay";
125static constexpr char DELIM_FEATURE[] = ";";
126static constexpr char DELIM_VALUE[] = ",";
127
135getFeatureValue(boost::beast::http::fields const& headers, std::string const& feature);
136
145bool
146isFeatureValue(boost::beast::http::fields const& headers, std::string const& feature, std::string const& value);
147
153bool
154featureEnabled(boost::beast::http::fields const& headers, std::string const& feature);
155
166template <typename headers>
167bool
168peerFeatureEnabled(headers const& request, std::string const& feature, std::string value, bool config)
169{
170 return config && isFeatureValue(request, feature, value);
171}
172
174template <typename headers>
175bool
176peerFeatureEnabled(headers const& request, std::string const& feature, bool config)
177{
178 return config && peerFeatureEnabled(request, feature, "1", config);
179}
180
192 bool comprEnabled,
193 bool ledgerReplayEnabled,
194 bool txReduceRelayEnabled,
195 bool vpReduceRelayEnabled);
196
212 http_request_type const& headers,
213 bool comprEnabled,
214 bool ledgerReplayEnabled,
215 bool txReduceRelayEnabled,
216 bool vpReduceRelayEnabled);
217
218} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
A public key.
Definition PublicKey.h:42
boost::asio::ip::address Address
Definition IPAddress.h:19
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_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:43
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
static constexpr char FEATURE_COMPR[]
Definition Handshake.h:118
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:12
boost::beast::ssl_stream< socket_type > stream_type
Definition Handshake.h:22
boost::beast::tcp_stream socket_type
Definition Handshake.h:21
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
static constexpr char DELIM_VALUE[]
Definition Handshake.h:126
boost::beast::http::request< boost::beast::http::empty_body > request_type
Definition Handshake.h:23
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:168
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
Definition Handshake.cpp:49
static constexpr char DELIM_FEATURE[]
Definition Handshake.h:125
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.
std::optional< std::string > getFeatureValue(boost::beast::http::fields const &headers, std::string const &feature)
Get feature's header value.
Definition Handshake.cpp:20
static constexpr char FEATURE_LEDGER_REPLAY[]
Definition Handshake.h:124
static constexpr char FEATURE_VPRR[]
Definition Handshake.h:120
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:68
PublicKey verifyHandshake(boost::beast::http::fields const &headers, xrpl::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.
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:34
static constexpr char FEATURE_TXRR[]
Definition Handshake.h:122
void buildHandshake(boost::beast::http::fields &h, xrpl::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.