20#ifndef RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
21#define RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
23#include <xrpld/app/main/Application.h>
24#include <xrpld/core/Job.h>
25#include <xrpld/overlay/Message.h>
26#include <xrpld/overlay/Overlay.h>
27#include <xrpld/overlay/Slot.h>
28#include <xrpld/overlay/detail/Handshake.h>
29#include <xrpld/overlay/detail/TrafficCount.h>
30#include <xrpld/overlay/detail/TxMetrics.h>
31#include <xrpld/peerfinder/PeerfinderManager.h>
32#include <xrpld/rpc/ServerHandler.h>
34#include <xrpl/basics/Resolver.h>
35#include <xrpl/basics/UnorderedContainers.h>
36#include <xrpl/basics/chrono.h>
37#include <xrpl/beast/utility/instrumentation.h>
38#include <xrpl/resource/ResourceManager.h>
39#include <xrpl/server/Handoff.h>
41#include <boost/asio/basic_waitable_timer.hpp>
42#include <boost/asio/ip/tcp.hpp>
43#include <boost/asio/ssl/context.hpp>
44#include <boost/asio/strand.hpp>
45#include <boost/container/flat_map.hpp>
87 boost::asio::basic_waitable_timer<clock_type>
timer_;
109 boost::container::flat_map<Child*, std::weak_ptr<Child>>
list_;
146 boost::asio::io_service& io_service,
191 size()
const override;
224 broadcast(protocol::TMProposeSet& m)
override;
227 broadcast(protocol::TMValidation& m)
override;
231 protocol::TMProposeSet& m,
237 protocol::TMValidation& m,
276 template <
class UnaryFunc>
294 if (
auto p = w.lock())
308 template <
class Body>
314 return response.result() ==
315 boost::beast::http::status::switching_protocols;
318 template <
class Fields>
320 is_upgrade(boost::beast::http::header<true, Fields>
const& req)
322 if (req.version() < 11)
324 if (req.method() != boost::beast::http::verb::get)
326 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
332 template <
class Fields>
334 is_upgrade(boost::beast::http::header<false, Fields>
const& req)
336 if (req.version() < 11)
338 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
409 protocol::MessageType type);
418 protocol::MessageType type);
435 template <
typename... Args>
439 if (!
strand_.running_in_this_thread())
442 std::bind(&OverlayImpl::addTxMetrics<Args...>,
this, args...));
585 template <
class Handler>
587 Handler
const& handler,
592 collector->make_gauge(
"Overlay",
"Peer_Disconnects"))
594 ,
hook(collector->make_hook(handler))
614 "ripple::OverlayImpl::collect_metrics : counts size do match");
616 for (
auto const& [key, value] : counts)
622 auto& gauge = it->second;
625 gauge.name == value.name,
626 "ripple::OverlayImpl::collect_metrics : gauge and counter "
629 gauge.bytesIn = value.bytesIn;
630 gauge.bytesOut = value.bytesOut;
631 gauge.messagesIn = value.messagesIn;
632 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.
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
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...
boost::asio::io_service & io_service_
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...
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)
std::optional< boost::asio::io_service::work > work_
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)
boost::asio::io_service::strand strand_
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...
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
static disabled_t const disabled
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.