1#include <xrpl/peerfinder/PeerfinderManager.h>
3#include <xrpl/beast/insight/Collector.h>
4#include <xrpl/beast/insight/Gauge.h>
5#include <xrpl/beast/insight/Hook.h>
6#include <xrpl/beast/net/IPEndpoint.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/beast/utility/PropertyStream.h>
9#include <xrpl/peerfinder/Config.h>
10#include <xrpl/peerfinder/Slot.h>
11#include <xrpl/peerfinder/Types.h>
12#include <xrpl/peerfinder/detail/Checker.h>
13#include <xrpl/peerfinder/detail/Logic.h>
14#include <xrpl/peerfinder/detail/SlotImp.h>
15#include <xrpl/peerfinder/detail/SourceStrings.h>
16#include <xrpl/peerfinder/detail/Store.h>
17#include <xrpl/peerfinder/make_Manager.h>
18#include <xrpl/protocol/PublicKey.h>
20#include <boost/asio/executor_work_guard.hpp>
21#include <boost/asio/io_context.hpp>
22#include <boost/asio/ip/tcp.hpp>
50 boost::asio::io_context& ioContext,
125 return logic_.newInboundSlot(localEndpoint, remoteEndpoint);
131 return logic_.newOutboundSlot(remoteEndpoint);
138 logic_.onEndpoints(impl, endpoints);
157 boost::asio::ip::tcp::endpoint
const& remoteAddress,
170 return logic_.onConnected(impl, localEndpoint);
177 return logic_.activate(impl, key, reserved);
184 return logic_.redirect(impl);
190 return logic_.autoconnect();
202 return logic_.buildEndpointsForPeers();
226 template <
class Handler>
228 :
hook(collector->makeHook(handler))
246 stats_.activeInboundPeers =
logic_.counts().inboundActive();
247 stats_.activeOutboundPeers =
logic_.counts().outActive();
259 boost::asio::io_context& ioContext,
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.
A version-independent IP address and port combination.
Tests remote listening sockets to make sure they are connectable.
The Logic for maintaining the list of Slot addresses.
ManagerImp(boost::asio::io_context &ioContext, clock_type &clock, beast::Journal journal, Store &store, 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< Endpoint > redirect(std::shared_ptr< Slot > const &slot) override
Returns a set of endpoints suitable for redirection.
void addFallbackURL(std::string const &name, std::string const &url)
void addFixedPeer(std::string_view name, std::vector< beast::ip::Endpoint > const &addresses) override
Add a peer that should always be connected.
Logic< decltype(checker_)> logic_
void onEndpoints(std::shared_ptr< Slot > const &slot, Endpoints const &endpoints) override
Called when mtENDPOINTS is received.
void onFailure(std::shared_ptr< Slot > const &slot) override
Called when an outbound connection is deemed to have failed.
void onClosed(std::shared_ptr< Slot > const &slot) override
Called when the slot is closed.
void setConfig(Config const &config) override
Set the configuration for the manager.
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::pair< std::shared_ptr< Slot >, Result > newOutboundSlot(beast::ip::Endpoint const &remoteEndpoint) override
Create a new outbound slot with the specified remote endpoint.
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
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
void oncePerSecond() override
Perform periodic activity.
void start() override
Transition to the started state, synchronously.
std::vector< beast::ip::Endpoint > autoconnect() override
Return a set of addresses we should connect to.
Config config() override
Returns the configuration for the manager.
void stop() override
Transition to the stopped state, synchronously.
void onWrite(beast::PropertyStream::Map &map) override
Subclass override.
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.
Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved) override
Request an active slot type.
Checker< boost::asio::ip::tcp > checker_
std::shared_ptr< SlotImp > ptr
static std::shared_ptr< Source > make(std::string const &name, Strings const &strings)
Abstract persistence for PeerFinder data.
std::unique_ptr< Manager > makeManager(boost::asio::io_context &ioContext, clock_type &clock, beast::Journal journal, Store &store, beast::insight::Collector::ptr const &collector)
Create a new Manager.
Result
Possible results from activating a slot.
std::vector< Endpoint > Endpoints
A set of Endpoint used for connecting.
beast::AbstractClock< std::chrono::steady_clock > clock_type
T dynamic_pointer_cast(T... args)
PeerFinder configuration settings.
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector)
beast::insight::Hook hook
beast::insight::Gauge activeOutboundPeers
beast::insight::Gauge activeInboundPeers