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>
33#include <xrpl/basics/Resolver.h>
34#include <xrpl/basics/UnorderedContainers.h>
35#include <xrpl/basics/chrono.h>
36#include <xrpl/beast/utility/instrumentation.h>
37#include <xrpl/resource/ResourceManager.h>
38#include <xrpl/server/Handoff.h>
39#include <boost/asio/basic_waitable_timer.hpp>
40#include <boost/asio/ip/tcp.hpp>
41#include <boost/asio/ssl/context.hpp>
42#include <boost/asio/strand.hpp>
43#include <boost/container/flat_map.hpp>
84 boost::asio::basic_waitable_timer<clock_type>
timer_;
106 boost::container::flat_map<Child*, std::weak_ptr<Child>>
list_;
143 boost::asio::io_service& io_service,
188 size()
const override;
221 broadcast(protocol::TMProposeSet& m)
override;
224 broadcast(protocol::TMValidation& m)
override;
228 protocol::TMProposeSet& m,
234 protocol::TMValidation& m,
273 template <
class UnaryFunc>
291 if (
auto p = w.lock())
305 template <
class Body>
311 return response.result() ==
312 boost::beast::http::status::switching_protocols;
315 template <
class Fields>
317 is_upgrade(boost::beast::http::header<true, Fields>
const& req)
319 if (req.version() < 11)
321 if (req.method() != boost::beast::http::verb::get)
323 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
329 template <
class Fields>
331 is_upgrade(boost::beast::http::header<false, Fields>
const& req)
333 if (req.version() < 11)
335 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
403 protocol::MessageType type);
412 protocol::MessageType type);
429 template <
typename... Args>
433 if (!
strand_.running_in_this_thread())
436 std::bind(&OverlayImpl::addTxMetrics<Args...>,
this, args...));
577 template <
class Handler>
579 Handler
const& handler,
583 collector->make_gauge(
"Overlay",
"Peer_Disconnects"))
585 ,
hook(collector->make_hook(handler))
605 "ripple::OverlayImpl::collect_metrics : counts size do match");
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.
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 reportTraffic(TrafficCount::category cat, bool isInbound, int bytes)
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.
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.
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.
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::vector< TrafficGauges > trafficGauges
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector, std::vector< 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
TrafficGauges(char const *name, beast::insight::Collector::ptr const &collector)
beast::insight::Gauge bytesOut
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.