1#ifndef XRPL_PEERFINDER_MANAGER_H_INCLUDED
2#define XRPL_PEERFINDER_MANAGER_H_INCLUDED
4#include <xrpld/core/Config.h>
5#include <xrpld/peerfinder/Slot.h>
7#include <xrpl/beast/clock/abstract_clock.h>
8#include <xrpl/beast/utility/PropertyStream.h>
10#include <boost/asio/ip/tcp.hpp>
91 bool validationPublicKey,
150 case Result::inboundDisabled:
151 return "inbound disabled";
152 case Result::duplicatePeer:
153 return "peer already connected";
154 case Result::ipLimitExceeded:
155 return "ip limit exceeded";
158 case Result::success:
263 boost::asio::ip::tcp::endpoint
const& remote_address,
A version-independent IP address and port combination.
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.
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.
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.
beast::IP::Endpoint address