1#include <xrpld/peerfinder/PeerfinderManager.h>
3#include <xrpld/peerfinder/Slot.h>
4#include <xrpld/peerfinder/detail/Checker.h>
5#include <xrpld/peerfinder/detail/Logic.h>
6#include <xrpld/peerfinder/detail/SlotImp.h>
7#include <xrpld/peerfinder/detail/SourceStrings.h>
8#include <xrpld/peerfinder/detail/StoreSqdb.h>
10#include <xrpl/beast/insight/Collector.h>
11#include <xrpl/beast/insight/Gauge.h>
12#include <xrpl/beast/insight/Hook.h>
13#include <xrpl/beast/net/IPEndpoint.h>
14#include <xrpl/beast/utility/Journal.h>
15#include <xrpl/beast/utility/PropertyStream.h>
16#include <xrpl/config/BasicConfig.h>
17#include <xrpl/protocol/PublicKey.h>
19#include <boost/asio/executor_work_guard.hpp>
20#include <boost/asio/io_context.hpp>
21#include <boost/asio/ip/tcp.hpp>
51 boost::asio::io_context& ioContext,
127 return logic_.newInboundSlot(localEndpoint, remoteEndpoint);
133 return logic_.newOutboundSlot(remoteEndpoint);
140 logic_.onEndpoints(impl, endpoints);
159 boost::asio::ip::tcp::endpoint
const& remoteAddress,
172 return logic_.onConnected(impl, localEndpoint);
179 return logic_.activate(impl, key, reserved);
186 return logic_.redirect(impl);
192 return logic_.autoconnect();
204 return logic_.buildEndpointsForPeers();
229 template <
class Handler>
231 :
hook(collector->makeHook(handler))
249 stats_.activeInboundPeers =
logic_.counts().inboundActive();
250 stats_.activeOutboundPeers =
logic_.counts().outActive();
262 boost::asio::io_context& ioContext,
A version-independent IP address and port combination.
A generic endpoint for log messages.
std::string const & name() const
Returns the name of this source.
std::shared_ptr< Collector > ptr
A metric for measuring an integral value.
A reference to a handler for performing polled collection.
Holds unparsed configuration information.
Tests remote listening sockets to make sure they are connectable.
The Logic for maintaining the list of Slot addresses.
void addFixedPeer(std::string_view name, std::vector< beast::IP::Endpoint > const &addresses) override
Add a peer that should always be connected.
void setConfig(Config const &config) override
Set the configuration for the manager.
void start() override
Transition to the started state, synchronously.
Config config() override
Returns the configuration for the manager.
void onRedirects(boost::asio::ip::tcp::endpoint const &remoteAddress, std::vector< boost::asio::ip::tcp::endpoint > const &eps) override
Called when we received redirect IPs from a busy peer.
std::pair< std::shared_ptr< Slot >, Result > newOutboundSlot(beast::IP::Endpoint const &remoteEndpoint) override
Create a new outbound slot with the specified remote endpoint.
std::vector< Endpoint > redirect(std::shared_ptr< Slot > const &slot) override
Returns a set of endpoints suitable for redirection.
void onFailure(std::shared_ptr< Slot > const &slot) override
Called when an outbound connection is deemed to have failed.
Logic< decltype(checker_)> logic_
void addFallbackURL(std::string const &name, std::string const &url)
void onWrite(beast::PropertyStream::Map &map) override
Subclass override.
Checker< boost::asio::ip::tcp > checker_
void stop() override
Transition to the stopped state, synchronously.
void onClosed(std::shared_ptr< Slot > const &slot) override
Called when the slot is closed.
void oncePerSecond() override
Perform periodic activity.
void onEndpoints(std::shared_ptr< Slot > const &slot, Endpoints const &endpoints) override
Called when mtENDPOINTS is received.
ManagerImp(boost::asio::io_context &ioContext, clock_type &clock, beast::Journal journal, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
void addFallbackStrings(std::string const &name, std::vector< std::string > const &strings) override
Add a set of strings as fallback IP::Endpoint sources.
std::vector< beast::IP::Endpoint > autoconnect() override
Return a set of addresses we should connect to.
Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved) override
Request an active slot type.
std::pair< std::shared_ptr< Slot >, Result > newInboundSlot(beast::IP::Endpoint const &localEndpoint, beast::IP::Endpoint const &remoteEndpoint) override
Add a URL as a fallback location to obtain IP::Endpoint sources.
std::vector< std::pair< std::shared_ptr< Slot >, std::vector< Endpoint > > > buildEndpointsForPeers() override
bool onConnected(std::shared_ptr< Slot > const &slot, beast::IP::Endpoint const &localEndpoint) override
Called when an outbound connection attempt succeeds.
boost::asio::io_context & io_context_
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
BasicConfig const & config_
std::shared_ptr< SlotImp > ptr
static std::shared_ptr< Source > make(std::string const &name, Strings const &strings)
Database persistence for PeerFinder using SQLite.
std::unique_ptr< Manager > makeManager(boost::asio::io_context &ioContext, clock_type &clock, beast::Journal journal, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
Create a new Manager.
std::vector< Endpoint > Endpoints
A set of Endpoint used for connecting.
Result
Possible results from activating a slot.
beast::AbstractClock< std::chrono::steady_clock > clock_type
T dynamic_pointer_cast(T... args)
PeerFinder configuration settings.
beast::insight::Gauge activeOutboundPeers
beast::insight::Hook hook
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector)
beast::insight::Gauge activeInboundPeers