1#ifndef XRPL_OVERLAY_OVERLAYIMPL_H_INCLUDED
2#define XRPL_OVERLAY_OVERLAYIMPL_H_INCLUDED
4#include <xrpld/app/main/Application.h>
5#include <xrpld/core/Job.h>
6#include <xrpld/overlay/Message.h>
7#include <xrpld/overlay/Overlay.h>
8#include <xrpld/overlay/Slot.h>
9#include <xrpld/overlay/detail/Handshake.h>
10#include <xrpld/overlay/detail/TrafficCount.h>
11#include <xrpld/overlay/detail/TxMetrics.h>
12#include <xrpld/peerfinder/PeerfinderManager.h>
13#include <xrpld/rpc/ServerHandler.h>
15#include <xrpl/basics/Resolver.h>
16#include <xrpl/basics/UnorderedContainers.h>
17#include <xrpl/basics/chrono.h>
18#include <xrpl/beast/utility/instrumentation.h>
19#include <xrpl/resource/ResourceManager.h>
20#include <xrpl/server/Handoff.h>
22#include <boost/algorithm/string/predicate.hpp>
23#include <boost/asio/basic_waitable_timer.hpp>
24#include <boost/asio/ip/tcp.hpp>
25#include <boost/asio/ssl/context.hpp>
26#include <boost/asio/strand.hpp>
27#include <boost/container/flat_map.hpp>
69 boost::asio::basic_waitable_timer<clock_type>
timer_;
87 boost::asio::io_context::executor_type>>
89 boost::asio::strand<boost::asio::io_context::executor_type>
strand_;
93 boost::container::flat_map<Child*, std::weak_ptr<Child>>
list_;
130 boost::asio::io_context& io_context,
175 size()
const override;
208 broadcast(protocol::TMProposeSet& m)
override;
211 broadcast(protocol::TMValidation& m)
override;
215 protocol::TMProposeSet& m,
221 protocol::TMValidation& m,
260 template <
class UnaryFunc>
278 if (
auto p = w.lock())
292 template <
class Body>
298 return response.result() ==
299 boost::beast::http::status::switching_protocols;
302 template <
class Fields>
304 is_upgrade(boost::beast::http::header<true, Fields>
const& req)
306 if (req.version() < 11)
308 if (req.method() != boost::beast::http::verb::get)
310 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
316 template <
class Fields>
318 is_upgrade(boost::beast::http::header<false, Fields>
const& req)
320 if (req.version() < 11)
322 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
393 protocol::MessageType type);
402 protocol::MessageType type);
419 template <
typename... Args>
423 if (!
strand_.running_in_this_thread())
426 std::bind(&OverlayImpl::addTxMetrics<Args...>,
this, args...));
569 template <
class Handler>
571 Handler
const& handler,
576 collector->make_gauge(
"Overlay",
"Peer_Disconnects"))
578 ,
hook(collector->make_hook(handler))
598 "ripple::OverlayImpl::collect_metrics : counts size do match");
600 for (
auto const& [key, value] : counts)
606 auto& gauge = it->second;
609 gauge.name == value.name,
610 "ripple::OverlayImpl::collect_metrics : gauge and counter "
613 gauge.bytesIn = value.bytesIn;
614 gauge.bytesOut = value.bytesOut;
615 gauge.messagesIn = value.messagesIn;
616 gauge.messagesOut = value.messagesOut;
A version-independent IP address and port combination.
A generic endpoint for log messages.
A metric for measuring an integral value.
A reference to a handler for performing polled collection.
Holds unparsed configuration information.
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
boost::system::error_code error_code
Json::Value getUnlInfo()
Returns information about the local server's UNL.
static std::string makePrefix(std::uint32_t id)
PeerFinder::Manager & peerFinder()
boost::asio::ip::tcp::endpoint endpoint_type
std::atomic< uint64_t > peerDisconnects_
bool processHealth(http_request_type const &req, Handoff &handoff)
Handles health requests.
boost::asio::ip::address address_type
boost::asio::io_context & io_context_
static bool is_upgrade(boost::beast::http::header< true, Fields > const &req)
std::condition_variable_any cond_
void onWrite(beast::PropertyStream::Map &stream) override
Subclass override.
Json::Value txMetrics() const override
Returns tx reduce-relay metrics.
void deleteIdlePeers()
Check if peers stopped relaying messages and if slots stopped receiving messages from the validator.
void activate(std::shared_ptr< PeerImp > const &peer)
Called when a peer has connected successfully This is called after the peer handshake has been comple...
PeerSequence getActivePeers() const override
Returns a sequence representing the current list of peers.
hash_map< std::shared_ptr< PeerFinder::Slot >, std::weak_ptr< PeerImp > > m_peers
void add_active(std::shared_ptr< PeerImp > const &peer)
std::shared_ptr< Peer > findPeerByPublicKey(PublicKey const &pubKey) override
Returns the peer with the matching public key, or null.
Resource::Manager & m_resourceManager
std::shared_ptr< Message > manifestMessage_
std::optional< std::uint32_t > manifestListSeq_
OverlayImpl & operator=(OverlayImpl const &)=delete
void squelch(PublicKey const &validator, Peer::id_t const id, std::uint32_t squelchDuration) const override
Squelch handler.
std::shared_ptr< Writer > makeErrorResponse(std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type const &request, address_type remote_address, std::string msg)
reduce_relay::Slots< UptimeClock > slots_
void deletePeer(Peer::id_t id)
Called when the peer is deleted.
std::shared_ptr< Peer > findPeerByShortID(Peer::id_t const &id) const override
Returns the peer with the matching short id, or null.
std::atomic< Peer::id_t > next_id_
void incPeerDisconnect() override
Increment and retrieve counters for total peer disconnects, and disconnects we initiate for excessive...
void addTxMetrics(Args... args)
Add tx reduce-relay metrics.
std::optional< std::uint32_t > networkID() const override
Returns the ID of the network this server is configured for, if any.
std::weak_ptr< Timer > timer_
std::atomic< uint64_t > jqTransOverflow_
metrics::TxMetrics txMetrics_
void broadcast(protocol::TMProposeSet &m) override
Broadcast a proposal.
void onPeerDeactivate(Peer::id_t id)
bool processRequest(http_request_type const &req, Handoff &handoff)
Handles non-peer protocol requests.
std::recursive_mutex mutex_
std::uint64_t getPeerDisconnectCharges() const override
boost::asio::ip::tcp::socket socket_type
void remove(std::shared_ptr< PeerFinder::Slot > const &slot)
void sendTxQueue()
Send once a second transactions' hashes aggregated by peers.
void reportOutboundTraffic(TrafficCount::category cat, int bytes)
std::set< Peer::id_t > relay(protocol::TMProposeSet &m, uint256 const &uid, PublicKey const &validator) override
Relay a proposal.
std::size_t size() const override
The number of active peers on the network Active peers are only those peers that have completed the h...
boost::asio::strand< boost::asio::io_context::executor_type > strand_
void unsquelch(PublicKey const &validator, Peer::id_t id) const override
Unsquelch handler.
std::shared_ptr< Writer > makeRedirectResponse(std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type const &request, address_type remote_address)
void for_each(UnaryFunc &&f) const
static bool isPeerUpgrade(boost::beast::http::response< Body > const &response)
OverlayImpl(OverlayImpl const &)=delete
Json::Value getOverlayInfo()
Returns information about peers on the overlay network.
Resource::Manager & resourceManager()
static bool isPeerUpgrade(http_request_type const &request)
Json::Value getServerCounts()
Returns information about the local server's performance counters.
void reportInboundTraffic(TrafficCount::category cat, int bytes)
void onManifests(std::shared_ptr< protocol::TMManifests > const &m, std::shared_ptr< PeerImp > const &from)
std::unique_ptr< PeerFinder::Manager > m_peerFinder
std::uint64_t getJqTransOverflow() const override
void connect(beast::IP::Endpoint const &remote_endpoint) override
Establish a peer connection to the specified endpoint.
Handoff onHandoff(std::unique_ptr< stream_type > &&bundle, http_request_type &&request, endpoint_type remote_endpoint) override
Conditionally accept an incoming HTTP request.
Setup const & setup() const
std::atomic< uint64_t > peerDisconnectsCharges_
std::shared_ptr< Message > getManifestsMessage()
hash_map< Peer::id_t, std::weak_ptr< PeerImp > > ids_
Json::Value getServerInfo()
Returns information about the local server.
bool processValidatorList(http_request_type const &req, Handoff &handoff)
Handles validator list requests.
Json::Value json() override
Return diagnostics on the status of all peers.
void checkTracking(std::uint32_t) override
Calls the checkTracking function on each peer.
void incPeerDisconnectCharges() override
ServerHandler & serverHandler_
bool processCrawl(http_request_type const &req, Handoff &handoff)
Handles crawl requests.
static bool is_upgrade(boost::beast::http::header< false, Fields > const &req)
int limit() override
Returns the maximum number of peers we are configured to allow.
void updateSlotAndSquelch(uint256 const &key, PublicKey const &validator, std::set< Peer::id_t > &&peers, protocol::MessageType type)
Updates message count for validator/peer.
void incJqTransOverflow() override
Increment and retrieve counter for transaction job queue overflows.
beast::Journal const journal_
boost::container::flat_map< Child *, std::weak_ptr< Child > > list_
std::uint64_t getPeerDisconnect() const override
Manages the set of connected peers.
std::vector< std::shared_ptr< Peer > > PeerSequence
Maintains a set of IP addresses used for getting into the network.
Tracks load and resource consumption.
TrafficCount is used to count ingress and egress wire bytes and number of messages.
auto const & getCounts() const
An up-to-date copy of all the counters.
Slots is a container for validator's Slot and handles Slot update when a message is received from a v...
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Used to indicate the result of a server connection handoff.
beast::insight::Gauge peerDisconnects
std::unordered_map< TrafficCount::category, TrafficGauges > trafficGauges
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector, std::unordered_map< TrafficCount::category, TrafficGauges > &&trafficGauges_)
beast::insight::Hook hook
void on_timer(error_code ec)
boost::asio::basic_waitable_timer< clock_type > timer_
beast::insight::Gauge messagesIn
beast::insight::Gauge bytesIn
beast::insight::Gauge messagesOut
beast::insight::Gauge bytesOut
TrafficGauges(std::string const &name, beast::insight::Collector::ptr const &collector)
std::optional< std::uint32_t > networkID
Run transaction reduce-relay feature related metrics.
void addMetrics(protocol::MessageType type, std::uint32_t val)
Add protocol message metrics.
Json::Value json() const
Get json representation of the metrics.