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#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/protocol/BuildInfo.h>
27
28#include <boost/asio/ssl.hpp>
29#include <boost/beast/core/tcp_stream.hpp>
30#include <boost/beast/http/dynamic_body.hpp>
31#include <boost/beast/http/empty_body.hpp>
32#include <boost/beast/http/fields.hpp>
33#include <boost/beast/ssl/ssl_stream.hpp>
34
35#include <optional>
36#include <utility>
37
38namespace ripple {
39
40using socket_type = boost::beast::tcp_stream;
41using stream_type = boost::beast::ssl_stream<socket_type>;
43 boost::beast::http::request<boost::beast::http::empty_body>;
45 boost::beast::http::request<boost::beast::http::dynamic_body>;
47 boost::beast::http::response<boost::beast::http::dynamic_body>;
48
60
63void
65 boost::beast::http::fields& h,
66 uint256 const& sharedValue,
68 beast::IP::Address public_ip,
69 beast::IP::Address remote_ip,
70 Application& app);
71
85 boost::beast::http::fields const& headers,
86 uint256 const& sharedValue,
88 beast::IP::Address public_ip,
89 beast::IP::Address remote,
90 Application& app);
91
105 bool crawlPublic,
106 bool comprEnabled,
107 bool ledgerReplayEnabled,
108 bool txReduceRelayEnabled,
109 bool vpReduceRelayEnabled);
110
125 bool crawlPublic,
126 http_request_type const& req,
127 beast::IP::Address public_ip,
128 beast::IP::Address remote_ip,
129 uint256 const& sharedValue,
131 ProtocolVersion version,
132 Application& app);
133
134// Protocol features negotiated via HTTP handshake.
135// The format is:
136// X-Protocol-Ctl: feature1=value1[,value2]*[\s*;\s*feature2=value1[,value2]*]*
137// value: \S+
138
139// compression feature
140static constexpr char FEATURE_COMPR[] = "compr";
141// validation/proposal reduce-relay feature
142static constexpr char FEATURE_VPRR[] = "vprr";
143// transaction reduce-relay feature
144static constexpr char FEATURE_TXRR[] = "txrr";
145// ledger replay
146static constexpr char FEATURE_LEDGER_REPLAY[] = "ledgerreplay";
147static constexpr char DELIM_FEATURE[] = ";";
148static constexpr char DELIM_VALUE[] = ",";
149
158 boost::beast::http::fields const& headers,
159 std::string const& feature);
160
169bool
171 boost::beast::http::fields const& headers,
172 std::string const& feature,
173 std::string const& value);
174
180bool
182 boost::beast::http::fields const& headers,
183 std::string const& feature);
184
195template <typename headers>
196bool
198 headers const& request,
199 std::string const& feature,
200 std::string value,
201 bool config)
202{
203 return config && isFeatureValue(request, feature, value);
204}
205
207template <typename headers>
208bool
210 headers const& request,
211 std::string const& feature,
212 bool config)
213{
214 return config && peerFeatureEnabled(request, feature, "1", config);
215}
216
228 bool comprEnabled,
229 bool ledgerReplayEnabled,
230 bool txReduceRelayEnabled,
231 bool vpReduceRelayEnabled);
232
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:43
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
boost::beast::ssl_stream< socket_type > stream_type
Definition: Handshake.h:41
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:93
static constexpr char DELIM_FEATURE[]
Definition: Handshake.h:147
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.
Definition: Handshake.cpp:177
static constexpr char FEATURE_COMPR[]
Definition: Handshake.h:140
static constexpr char DELIM_VALUE[]
Definition: Handshake.h:148
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
Definition: Handshake.cpp:74
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.
Definition: Handshake.cpp:391
static constexpr char FEATURE_LEDGER_REPLAY[]
Definition: Handshake.h:146
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:54
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
Definition: Handshake.cpp:145
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:66
std::optional< std::string > getFeatureValue(boost::beast::http::fields const &headers, std::string const &feature)
Get feature's header value.
Definition: Handshake.cpp:38
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:197
static constexpr char FEATURE_TXRR[]
Definition: Handshake.h:144
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
Definition: Handshake.cpp:364
boost::beast::http::request< boost::beast::http::empty_body > request_type
Definition: Handshake.h:43
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.
Definition: Handshake.cpp:226
boost::beast::tcp_stream socket_type
Definition: Handshake.h:40
static constexpr char FEATURE_VPRR[]
Definition: Handshake.h:142