rippled
Loading...
Searching...
No Matches
Handshake.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_HANDSHAKE_H_INCLUDED
21#define RIPPLE_OVERLAY_HANDSHAKE_H_INCLUDED
22
23#include <xrpld/app/main/Application.h>
24#include <xrpld/overlay/detail/ProtocolVersion.h>
25
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/protocol/BuildInfo.h>
28
29#include <boost/asio/ssl.hpp>
30#include <boost/beast/core/tcp_stream.hpp>
31#include <boost/beast/http/dynamic_body.hpp>
32#include <boost/beast/http/empty_body.hpp>
33#include <boost/beast/http/fields.hpp>
34#include <boost/beast/ssl/ssl_stream.hpp>
35
36#include <optional>
37#include <utility>
38
39namespace ripple {
40
41using socket_type = boost::beast::tcp_stream;
42using stream_type = boost::beast::ssl_stream<socket_type>;
44 boost::beast::http::request<boost::beast::http::empty_body>;
46 boost::beast::http::request<boost::beast::http::dynamic_body>;
48 boost::beast::http::response<boost::beast::http::dynamic_body>;
49
61
64void
66 boost::beast::http::fields& h,
67 uint256 const& sharedValue,
69 beast::IP::Address public_ip,
70 beast::IP::Address remote_ip,
71 Application& app);
72
86 boost::beast::http::fields const& headers,
87 uint256 const& sharedValue,
89 beast::IP::Address public_ip,
90 beast::IP::Address remote,
91 Application& app);
92
106 bool crawlPublic,
107 bool comprEnabled,
108 bool ledgerReplayEnabled,
109 bool txReduceRelayEnabled,
110 bool vpReduceRelayEnabled);
111
126 bool crawlPublic,
127 http_request_type const& req,
128 beast::IP::Address public_ip,
129 beast::IP::Address remote_ip,
130 uint256 const& sharedValue,
132 ProtocolVersion version,
133 Application& app);
134
135// Protocol features negotiated via HTTP handshake.
136// The format is:
137// X-Protocol-Ctl: feature1=value1[,value2]*[\s*;\s*feature2=value1[,value2]*]*
138// value: \S+
139
140// compression feature
141static constexpr char FEATURE_COMPR[] = "compr";
142// validation/proposal reduce-relay base squelch feature
143static constexpr char FEATURE_VPRR[] = "vprr";
144// transaction reduce-relay feature
145static constexpr char FEATURE_TXRR[] = "txrr";
146// ledger replay
147static constexpr char FEATURE_LEDGER_REPLAY[] = "ledgerreplay";
148static constexpr char DELIM_FEATURE[] = ";";
149static constexpr char DELIM_VALUE[] = ",";
150
159 boost::beast::http::fields const& headers,
160 std::string const& feature);
161
170bool
172 boost::beast::http::fields const& headers,
173 std::string const& feature,
174 std::string const& value);
175
181bool
183 boost::beast::http::fields const& headers,
184 std::string const& feature);
185
196template <typename headers>
197bool
199 headers const& request,
200 std::string const& feature,
201 std::string value,
202 bool config)
203{
204 return config && isFeatureValue(request, feature, value);
205}
206
208template <typename headers>
209bool
211 headers const& request,
212 std::string const& feature,
213 bool config)
214{
215 return config && peerFeatureEnabled(request, feature, "1", config);
216}
217
229 bool comprEnabled,
230 bool ledgerReplayEnabled,
231 bool txReduceRelayEnabled,
232 bool vpReduceRelayEnabled);
233
249 http_request_type const& headers,
250 bool comprEnabled,
251 bool ledgerReplayEnabled,
252 bool txReduceRelayEnabled,
253 bool vpReduceRelayEnabled);
254
255} // namespace ripple
256
257#endif
A generic endpoint for log messages.
Definition Journal.h:60
A public key.
Definition PublicKey.h:62
boost::asio::ip::address Address
Definition IPAddress.h:39
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
boost::beast::ssl_stream< socket_type > stream_type
Definition Handshake.h:42
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:94
static constexpr char DELIM_FEATURE[]
Definition Handshake.h:148
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_type
Definition Handoff.h:36
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:141
static constexpr char DELIM_VALUE[]
Definition Handshake.h:149
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
Definition Handshake.cpp:75
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:147
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:55
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:33
bool featureEnabled(boost::beast::http::fields const &headers, std::string const &feature)
Check if a feature is enabled.
Definition Handshake.cpp:67
std::optional< std::string > getFeatureValue(boost::beast::http::fields const &headers, std::string const &feature)
Get feature's header value.
Definition Handshake.cpp:39
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:198
static constexpr char FEATURE_TXRR[]
Definition Handshake.h:145
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:44
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:41
static constexpr char FEATURE_VPRR[]
Definition Handshake.h:143