xrpld
Loading...
Searching...
No Matches
include/xrpl/peerfinder/PeerfinderManager.h
1#pragma once
2
3#include <xrpl/beast/net/IPEndpoint.h>
4#include <xrpl/beast/utility/PropertyStream.h>
5#include <xrpl/peerfinder/Config.h>
6#include <xrpl/peerfinder/Slot.h>
7#include <xrpl/peerfinder/Types.h>
8#include <xrpl/protocol/PublicKey.h>
9
10#include <boost/asio/ip/tcp.hpp>
11
12#include <memory>
13#include <string>
14#include <string_view>
15#include <utility>
16#include <vector>
17
18namespace xrpl::peer_finder {
19
24{
25protected:
26 Manager() noexcept;
27
28public:
35 ~Manager() override = default;
36
43 virtual void
44 setConfig(Config const& config) = 0;
45
49 virtual void
50 start() = 0;
51
55 virtual void
56 stop() = 0;
57
61 virtual Config
62 config() = 0;
63
70 virtual void
72
77 virtual void
79
84 /* VFALCO NOTE Unimplemented
85 virtual void addFallbackURL (std::string const& name,
86 std::string const& url) = 0;
87 */
88
89 //--------------------------------------------------------------------------
90
98 beast::ip::Endpoint const& localEndpoint,
99 beast::ip::Endpoint const& remoteEndpoint) = 0;
100
107 newOutboundSlot(beast::ip::Endpoint const& remoteEndpoint) = 0;
108
112 virtual void
113 onEndpoints(std::shared_ptr<Slot> const& slot, Endpoints const& endpoints) = 0;
114
120 virtual void
122
126 virtual void
128
132 virtual void
134 boost::asio::ip::tcp::endpoint const& remoteAddress,
136
137 //--------------------------------------------------------------------------
138
147 virtual bool
148 onConnected(std::shared_ptr<Slot> const& slot, beast::ip::Endpoint const& localEndpoint) = 0;
149
153 virtual Result
154 activate(std::shared_ptr<Slot> const& slot, PublicKey const& key, bool reserved) = 0;
155
161
167
170
175 virtual void
177};
178
179} // namespace xrpl::peer_finder
Subclasses can be called to write to a stream and have children.
std::string const & name() const
Returns the name of this source.
A version-independent IP address and port combination.
Definition IPEndpoint.h:24
A public key.
Definition PublicKey.h:53
virtual void onEndpoints(std::shared_ptr< Slot > const &slot, Endpoints const &endpoints)=0
Called when mtENDPOINTS is received.
virtual std::pair< std::shared_ptr< Slot >, Result > newInboundSlot(beast::ip::Endpoint const &localEndpoint, beast::ip::Endpoint const &remoteEndpoint)=0
Add a URL as a fallback location to obtain ip::Endpoint sources.
virtual void onRedirects(boost::asio::ip::tcp::endpoint const &remoteAddress, std::vector< boost::asio::ip::tcp::endpoint > const &eps)=0
Called when we received redirect IPs from a busy peer.
virtual void oncePerSecond()=0
Perform periodic activity.
virtual void setConfig(Config const &config)=0
Set the configuration for the manager.
virtual std::vector< beast::ip::Endpoint > autoconnect()=0
Return a set of addresses we should connect to.
virtual std::vector< Endpoint > redirect(std::shared_ptr< Slot > const &slot)=0
Returns a set of endpoints suitable for redirection.
virtual Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved)=0
Request an active slot type.
virtual Config config()=0
Returns the configuration for the manager.
virtual std::pair< std::shared_ptr< Slot >, Result > newOutboundSlot(beast::ip::Endpoint const &remoteEndpoint)=0
Create a new outbound slot with the specified remote endpoint.
virtual bool onConnected(std::shared_ptr< Slot > const &slot, beast::ip::Endpoint const &localEndpoint)=0
Called when an outbound connection attempt succeeds.
virtual std::vector< std::pair< std::shared_ptr< Slot >, std::vector< Endpoint > > > buildEndpointsForPeers()=0
~Manager() override=default
Destroy the object.
virtual void stop()=0
Transition to the stopped state, synchronously.
virtual void onFailure(std::shared_ptr< Slot > const &slot)=0
Called when an outbound connection is deemed to have failed.
virtual void addFixedPeer(std::string_view name, std::vector< beast::ip::Endpoint > const &addresses)=0
Add a peer that should always be connected.
virtual void start()=0
Transition to the started state, synchronously.
virtual void onClosed(std::shared_ptr< Slot > const &slot)=0
Called when the slot is closed.
virtual void addFallbackStrings(std::string const &name, std::vector< std::string > const &strings)=0
Add a set of strings as fallback ip::Endpoint sources.
Result
Possible results from activating a slot.
std::vector< Endpoint > Endpoints
A set of Endpoint used for connecting.
PeerFinder configuration settings.