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 <xrpld/overlay/PeerSet.h>
25#include <xrpl/beast/utility/PropertyStream.h>
26#include <xrpl/json/json_value.h>
27#include <xrpl/server/Handoff.h>
28#include <boost/asio/buffer.hpp>
29#include <boost/asio/ip/tcp.hpp>
30#include <boost/asio/ssl/context.hpp>
31#include <boost/asio/ssl/stream.hpp>
32#include <boost/beast/core/tcp_stream.hpp>
33#include <boost/beast/http/message.hpp>
34#include <boost/beast/ssl/ssl_stream.hpp>
35#include <functional>
36#include <memory>
37#include <optional>
38#include <type_traits>
39
40namespace boost {
41namespace asio {
42namespace ssl {
43class context;
44}
45} // namespace asio
46} // namespace boost
47
48namespace ripple {
49
52{
53protected:
54 using socket_type = boost::beast::tcp_stream;
55 using stream_type = boost::beast::ssl_stream<socket_type>;
56
57 // VFALCO NOTE The requirement of this constructor is an
58 // unfortunate problem with the API for
59 // PropertyStream
60 Overlay() : beast::PropertyStream::Source("peers")
61 {
62 }
63
64public:
65 enum class Promote { automatic, never, always };
66
67 struct Setup
68 {
69 explicit Setup() = default;
70
73 int ipLimit = 0;
76 bool vlEnabled = true;
77 };
78
80
81 virtual ~Overlay() = default;
82
83 virtual void
85 {
86 }
87
88 virtual void
90 {
91 }
92
94 virtual Handoff
97 http_request_type&& request,
98 boost::asio::ip::tcp::endpoint remote_address) = 0;
99
104 virtual void
105 connect(beast::IP::Endpoint const& address) = 0;
106
108 virtual int
109 limit() = 0;
110
115 virtual std::size_t
116 size() const = 0;
117
121 virtual Json::Value
122 json() = 0;
123
127 virtual PeerSequence
128 getActivePeers() const = 0;
129
133 virtual void
135
138 findPeerByShortID(Peer::id_t const& id) const = 0;
139
142 findPeerByPublicKey(PublicKey const& pubKey) = 0;
143
145 virtual void
146 broadcast(protocol::TMProposeSet& m) = 0;
147
149 virtual void
150 broadcast(protocol::TMValidation& m) = 0;
151
160 protocol::TMProposeSet& m,
161 uint256 const& uid,
162 PublicKey const& validator) = 0;
163
172 protocol::TMValidation& m,
173 uint256 const& uid,
174 PublicKey const& validator) = 0;
175
183 virtual void
185 uint256 const& hash,
187 std::set<Peer::id_t> const& toSkip) = 0;
188
196 template <class Function>
197 void
198 foreach(Function f) const
199 {
200 for (auto const& p : getActivePeers())
201 f(p);
202 }
203
205 virtual void
207 virtual std::uint64_t
209
213 virtual void
215 virtual std::uint64_t
216 getPeerDisconnect() const = 0;
217 virtual void
219 virtual std::uint64_t
221
231 networkID() const = 0;
232
236 virtual Json::Value
237 txMetrics() const = 0;
238};
239
240} // namespace ripple
241
242#endif
Represents a JSON value.
Definition: json_value.h:147
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:52
boost::beast::ssl_stream< socket_type > stream_type
Definition: Overlay.h:55
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:84
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:89
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:54
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:41
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:31
Used to indicate the result of a server connection handoff.
Definition: Handoff.h:38
beast::IP::Address public_ip
Definition: Overlay.h:72
std::uint32_t crawlOptions
Definition: Overlay.h:74
std::shared_ptr< boost::asio::ssl::context > context
Definition: Overlay.h:71
std::optional< std::uint32_t > networkID
Definition: Overlay.h:75