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
25#include <xrpl/beast/utility/PropertyStream.h>
26#include <xrpl/json/json_value.h>
27#include <xrpl/server/Handoff.h>
28
29#include <boost/asio/ip/tcp.hpp>
30#include <boost/asio/ssl/context.hpp>
31#include <boost/beast/core/tcp_stream.hpp>
32#include <boost/beast/ssl/ssl_stream.hpp>
33
34#include <functional>
35#include <optional>
36
37namespace boost {
38namespace asio {
39namespace ssl {
40class context;
41}
42} // namespace asio
43} // namespace boost
44
45namespace ripple {
46
49{
50protected:
51 using socket_type = boost::beast::tcp_stream;
52 using stream_type = boost::beast::ssl_stream<socket_type>;
53
54 // VFALCO NOTE The requirement of this constructor is an
55 // unfortunate problem with the API for
56 // PropertyStream
57 Overlay() : beast::PropertyStream::Source("peers")
58 {
59 }
60
61public:
62 enum class Promote { automatic, never, always };
63
75
77
78 virtual ~Overlay() = default;
79
80 virtual void
82 {
83 }
84
85 virtual void
87 {
88 }
89
91 virtual Handoff
94 http_request_type&& request,
95 boost::asio::ip::tcp::endpoint remote_address) = 0;
96
101 virtual void
102 connect(beast::IP::Endpoint const& address) = 0;
103
105 virtual int
106 limit() = 0;
107
112 virtual std::size_t
113 size() const = 0;
114
118 virtual Json::Value
119 json() = 0;
120
124 virtual PeerSequence
125 getActivePeers() const = 0;
126
130 virtual void
132
135 findPeerByShortID(Peer::id_t const& id) const = 0;
136
139 findPeerByPublicKey(PublicKey const& pubKey) = 0;
140
142 virtual void
143 broadcast(protocol::TMProposeSet& m) = 0;
144
146 virtual void
147 broadcast(protocol::TMValidation& m) = 0;
148
157 protocol::TMProposeSet& m,
158 uint256 const& uid,
159 PublicKey const& validator) = 0;
160
169 protocol::TMValidation& m,
170 uint256 const& uid,
171 PublicKey const& validator) = 0;
172
180 virtual void
182 uint256 const& hash,
184 std::set<Peer::id_t> const& toSkip) = 0;
185
193 template <class Function>
194 void
195 foreach(Function f) const
196 {
197 for (auto const& p : getActivePeers())
198 f(p);
199 }
200
202 virtual void
204 virtual std::uint64_t
206
210 virtual void
212 virtual std::uint64_t
213 getPeerDisconnect() const = 0;
214 virtual void
216 virtual std::uint64_t
218
228 networkID() const = 0;
229
233 virtual Json::Value
234 txMetrics() const = 0;
235};
236
237} // namespace ripple
238
239#endif
Represents a JSON value.
Definition json_value.h:149
A version-independent IP address and port combination.
Definition IPEndpoint.h:38
Subclasses can be called to write to a stream and have children.
Manages the set of connected peers.
Definition Overlay.h:49
boost::beast::ssl_stream< socket_type > stream_type
Definition Overlay.h:52
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:81
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:86
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:51
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:61
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::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:69
std::uint32_t crawlOptions
Definition Overlay.h:71
std::shared_ptr< boost::asio::ssl::context > context
Definition Overlay.h:68
std::optional< std::uint32_t > networkID
Definition Overlay.h:72