rippled
Loading...
Searching...
No Matches
PeerfinderManager.h
1#pragma once
2
3#include <xrpld/core/Config.h>
4#include <xrpld/peerfinder/Slot.h>
5
6#include <xrpl/beast/clock/abstract_clock.h>
7#include <xrpl/beast/utility/PropertyStream.h>
8
9#include <boost/asio/ip/tcp.hpp>
10
11#include <string_view>
12
13namespace xrpl {
14namespace PeerFinder {
15
17
20
21//------------------------------------------------------------------------------
22
24struct Config
25{
31
37
43
45 bool peerPrivate = true;
46
49
52
55
58
61
62 //--------------------------------------------------------------------------
63
65 Config();
66
69 calcOutPeers() const;
70
72 void
74
76 void
78
86 static Config
87 makeConfig(xrpl::Config const& config, std::uint16_t port, bool validationPublicKey, int ipLimit);
88
89 friend bool
90 operator==(Config const& lhs, Config const& rhs);
91};
92
93//------------------------------------------------------------------------------
94
105
106inline bool
107operator<(Endpoint const& lhs, Endpoint const& rhs)
108{
109 return lhs.address < rhs.address;
110}
111
114
115//------------------------------------------------------------------------------
116
119
134inline std::string_view
135to_string(Result result) noexcept
136{
137 switch (result)
138 {
139 case Result::inboundDisabled:
140 return "inbound disabled";
141 case Result::duplicatePeer:
142 return "peer already connected";
143 case Result::ipLimitExceeded:
144 return "ip limit exceeded";
145 case Result::full:
146 return "slots full";
147 case Result::success:
148 return "success";
149 }
150
151 return "unknown";
152}
153
156{
157protected:
158 Manager() noexcept;
159
160public:
166 virtual ~Manager() = default;
167
173 virtual void
175
177 virtual void
178 start() = 0;
179
181 virtual void
182 stop() = 0;
183
185 virtual Config
186 config() = 0;
187
193 virtual void
195
199 virtual void
201
205 /* VFALCO NOTE Unimplemented
206 virtual void addFallbackURL (std::string const& name,
207 std::string const& url) = 0;
208 */
209
210 //--------------------------------------------------------------------------
211
217 new_inbound_slot(beast::IP::Endpoint const& local_endpoint, beast::IP::Endpoint const& remote_endpoint) = 0;
218
224 new_outbound_slot(beast::IP::Endpoint const& remote_endpoint) = 0;
225
227 virtual void
228 on_endpoints(std::shared_ptr<Slot> const& slot, Endpoints const& endpoints) = 0;
229
234 virtual void
236
238 virtual void
240
242 virtual void
244 boost::asio::ip::tcp::endpoint const& remote_address,
246
247 //--------------------------------------------------------------------------
248
256 virtual bool
257 onConnected(std::shared_ptr<Slot> const& slot, beast::IP::Endpoint const& local_endpoint) = 0;
258
260 virtual Result
261 activate(std::shared_ptr<Slot> const& slot, PublicKey const& key, bool reserved) = 0;
262
266
270
273
277 virtual void
279};
280
281} // namespace PeerFinder
282} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:18
Subclasses can be called to write to a stream and have children.
std::string const & name() const
Returns the name of this source.
Maintains a set of IP addresses used for getting into the network.
virtual void start()=0
Transition to the started state, synchronously.
virtual std::vector< beast::IP::Endpoint > autoconnect()=0
Return a set of addresses we should connect to.
virtual void addFallbackStrings(std::string const &name, std::vector< std::string > const &strings)=0
Add a set of strings as fallback IP::Endpoint sources.
virtual std::vector< std::pair< std::shared_ptr< Slot >, std::vector< Endpoint > > > buildEndpointsForPeers()=0
virtual std::pair< std::shared_ptr< Slot >, Result > new_outbound_slot(beast::IP::Endpoint const &remote_endpoint)=0
Create a new outbound slot with the specified remote endpoint.
virtual void addFixedPeer(std::string const &name, std::vector< beast::IP::Endpoint > const &addresses)=0
Add a peer that should always be connected.
virtual void onRedirects(boost::asio::ip::tcp::endpoint const &remote_address, std::vector< boost::asio::ip::tcp::endpoint > const &eps)=0
Called when we received redirect IPs from a busy peer.
virtual Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved)=0
Request an active slot type.
virtual void on_closed(std::shared_ptr< Slot > const &slot)=0
Called when the slot is closed.
virtual ~Manager()=default
Destroy the object.
virtual void stop()=0
Transition to the stopped state, synchronously.
virtual std::pair< std::shared_ptr< Slot >, Result > new_inbound_slot(beast::IP::Endpoint const &local_endpoint, beast::IP::Endpoint const &remote_endpoint)=0
Add a URL as a fallback location to obtain IP::Endpoint sources.
virtual Config config()=0
Returns the configuration for the manager.
virtual void once_per_second()=0
Perform periodic activity.
virtual void setConfig(Config const &config)=0
Set the configuration for the manager.
virtual void on_endpoints(std::shared_ptr< Slot > const &slot, Endpoints const &endpoints)=0
Called when mtENDPOINTS is received.
virtual bool onConnected(std::shared_ptr< Slot > const &slot, beast::IP::Endpoint const &local_endpoint)=0
Called when an outbound connection attempt succeeds.
virtual std::vector< Endpoint > redirect(std::shared_ptr< Slot > const &slot)=0
Returns a set of endpoints suitable for redirection.
virtual void on_failure(std::shared_ptr< Slot > const &slot)=0
Called when an outbound connection is deemed to have failed.
A public key.
Definition PublicKey.h:42
std::string_view to_string(Result result) noexcept
Converts a Result enum value to its string representation.
Result
Possible results from activating a slot.
bool operator<(Endpoint const &lhs, Endpoint const &rhs)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
PeerFinder configuration settings.
std::size_t maxPeers
The largest number of public peer slots to allow.
int ipLimit
Limit how many incoming connections we allow per IP.
std::size_t outPeers
The number of automatic outbound connections to maintain.
void onWrite(beast::PropertyStream::Map &map)
Write the configuration into a property stream.
Config()
Create a configuration with default values.
void applyTuning()
Adjusts the values so they follow the business rules.
bool wantIncoming
true if we want to accept incoming connections.
bool autoConnect
true if we want to establish connections automatically
std::string features
The set of features we advertise.
std::size_t inPeers
The number of automatic inbound connections to maintain.
static Config makeConfig(xrpl::Config const &config, std::uint16_t port, bool validationPublicKey, int ipLimit)
Make PeerFinder::Config from configuration parameters.
std::uint16_t listeningPort
The listening port number.
std::size_t calcOutPeers() const
Returns a suitable value for outPeers according to the rules.
friend bool operator==(Config const &lhs, Config const &rhs)
bool peerPrivate
true if we want our IP address kept private.
Describes a connectable peer address along with some metadata.