rippled
Loading...
Searching...
No Matches
Overlay.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_OVERLAY_H_INCLUDED
21#define RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
22
23#include <xrpld/overlay/Peer.h>
24#include <xrpl/beast/utility/PropertyStream.h>
25#include <xrpl/json/json_value.h>
26#include <xrpl/server/Handoff.h>
27
28#include <boost/asio/ip/tcp.hpp>
29#include <boost/asio/ssl/context.hpp>
30#include <boost/beast/core/tcp_stream.hpp>
31#include <boost/beast/ssl/ssl_stream.hpp>
32
33#include <functional>
34#include <optional>
35
36namespace boost {
37namespace asio {
38namespace ssl {
39class context;
40}
41} // namespace asio
42} // namespace boost
43
44namespace ripple {
45
48{
49protected:
50 using socket_type = boost::beast::tcp_stream;
51 using stream_type = boost::beast::ssl_stream<socket_type>;
52
53 // VFALCO NOTE The requirement of this constructor is an
54 // unfortunate problem with the API for
55 // PropertyStream
56 Overlay() : beast::PropertyStream::Source("peers")
57 {
58 }
59
60public:
61 enum class Promote { automatic, never, always };
62
63 struct Setup
64 {
65 explicit Setup() = default;
66
69 int ipLimit = 0;
72 bool vlEnabled = true;
73 };
74
76
77 virtual ~Overlay() = default;
78
79 virtual void
81 {
82 }
83
84 virtual void
86 {
87 }
88
90 virtual Handoff
93 http_request_type&& request,
94 boost::asio::ip::tcp::endpoint remote_address) = 0;
95
100 virtual void
101 connect(beast::IP::Endpoint const& address) = 0;
102
104 virtual int
105 limit() = 0;
106
111 virtual std::size_t
112 size() const = 0;
113
117 virtual Json::Value
118 json() = 0;
119
123 virtual PeerSequence
124 getActivePeers() const = 0;
125
129 virtual void
131
134 findPeerByShortID(Peer::id_t const& id) const = 0;
135
138 findPeerByPublicKey(PublicKey const& pubKey) = 0;
139
141 virtual void
142 broadcast(protocol::TMProposeSet& m) = 0;
143
145 virtual void
146 broadcast(protocol::TMValidation& m) = 0;
147
156 protocol::TMProposeSet& m,
157 uint256 const& uid,
158 PublicKey const& validator) = 0;
159
168 protocol::TMValidation& m,
169 uint256 const& uid,
170 PublicKey const& validator) = 0;
171
179 virtual void
181 uint256 const& hash,
183 std::set<Peer::id_t> const& toSkip) = 0;
184
192 template <class Function>
193 void
194 foreach(Function f) const
195 {
196 for (auto const& p : getActivePeers())
197 f(p);
198 }
199
201 virtual void
203 virtual std::uint64_t
205
209 virtual void
211 virtual std::uint64_t
212 getPeerDisconnect() const = 0;
213 virtual void
215 virtual std::uint64_t
217
227 networkID() const = 0;
228
232 virtual Json::Value
233 txMetrics() const = 0;
234};
235
236} // namespace ripple
237
238#endif
Represents a JSON value.
Definition: json_value.h:148
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
Subclasses can be called to write to a stream and have children.
Manages the set of connected peers.
Definition: Overlay.h:48
boost::beast::ssl_stream< socket_type > stream_type
Definition: Overlay.h:51
virtual void relay(uint256 const &hash, std::optional< std::reference_wrapper< protocol::TMTransaction > > m, std::set< Peer::id_t > const &toSkip)=0
Relay a transaction.
virtual void broadcast(protocol::TMProposeSet &m)=0
Broadcast a proposal.
virtual void broadcast(protocol::TMValidation &m)=0
Broadcast a validation.
virtual void start()
Definition: Overlay.h:80
virtual std::shared_ptr< Peer > findPeerByPublicKey(PublicKey const &pubKey)=0
Returns the peer with the matching public key, or null.
virtual void stop()
Definition: Overlay.h:85
virtual int limit()=0
Returns the maximum number of peers we are configured to allow.
virtual PeerSequence getActivePeers() const =0
Returns a sequence representing the current list of peers.
virtual std::shared_ptr< Peer > findPeerByShortID(Peer::id_t const &id) const =0
Returns the peer with the matching short id, or null.
virtual Json::Value json()=0
Return diagnostics on the status of all peers.
virtual std::set< Peer::id_t > relay(protocol::TMProposeSet &m, uint256 const &uid, PublicKey const &validator)=0
Relay a proposal.
virtual std::optional< std::uint32_t > networkID() const =0
Returns the ID of the network this server is configured for, if any.
boost::beast::tcp_stream socket_type
Definition: Overlay.h:50
virtual void checkTracking(std::uint32_t index)=0
Calls the checkTracking function on each peer.
virtual Json::Value txMetrics() const =0
Returns tx reduce-relay metrics.
virtual std::uint64_t getPeerDisconnect() const =0
virtual std::size_t size() const =0
Returns the number of active peers.
virtual ~Overlay()=default
virtual void incPeerDisconnect()=0
Increment and retrieve counters for total peer disconnects, and disconnects we initiate for excessive...
virtual Handoff onHandoff(std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint remote_address)=0
Conditionally accept an incoming HTTP request.
virtual std::uint64_t getJqTransOverflow() const =0
virtual std::set< Peer::id_t > relay(protocol::TMValidation &m, uint256 const &uid, PublicKey const &validator)=0
Relay a validation.
virtual void connect(beast::IP::Endpoint const &address)=0
Establish a peer connection to the specified endpoint.
virtual void incJqTransOverflow()=0
Increment and retrieve counter for transaction job queue overflows.
virtual void incPeerDisconnectCharges()=0
virtual std::uint64_t getPeerDisconnectCharges() const =0
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::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:33
Used to indicate the result of a server connection handoff.
Definition: Handoff.h:40
beast::IP::Address public_ip
Definition: Overlay.h:68
std::uint32_t crawlOptions
Definition: Overlay.h:70
std::shared_ptr< boost::asio::ssl::context > context
Definition: Overlay.h:67
std::optional< std::uint32_t > networkID
Definition: Overlay.h:71