20 #ifndef RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
21 #define RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
23 #include <ripple/app/main/Application.h>
24 #include <ripple/basics/Resolver.h>
25 #include <ripple/basics/UnorderedContainers.h>
26 #include <ripple/basics/chrono.h>
27 #include <ripple/core/Job.h>
28 #include <ripple/overlay/Message.h>
29 #include <ripple/overlay/Overlay.h>
30 #include <ripple/overlay/Slot.h>
31 #include <ripple/overlay/impl/Handshake.h>
32 #include <ripple/overlay/impl/TrafficCount.h>
33 #include <ripple/overlay/impl/TxMetrics.h>
34 #include <ripple/peerfinder/PeerfinderManager.h>
35 #include <ripple/resource/ResourceManager.h>
36 #include <ripple/rpc/ServerHandler.h>
37 #include <ripple/server/Handoff.h>
38 #include <boost/asio/basic_waitable_timer.hpp>
39 #include <boost/asio/ip/tcp.hpp>
40 #include <boost/asio/ssl/context.hpp>
41 #include <boost/asio/strand.hpp>
42 #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_;
149 boost::asio::io_service& io_service,
194 size()
const override;
227 broadcast(protocol::TMProposeSet& m)
override;
230 broadcast(protocol::TMValidation& m)
override;
234 protocol::TMProposeSet& m,
240 protocol::TMValidation& m,
247 protocol::TMTransaction& m,
279 template <
class UnaryFunc>
297 if (
auto p = w.lock())
311 template <
class Body>
317 return response.result() ==
318 boost::beast::http::status::switching_protocols;
321 template <
class Fields>
323 is_upgrade(boost::beast::http::header<true, Fields>
const& req)
325 if (req.version() < 11)
327 if (req.method() != boost::beast::http::verb::get)
329 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
335 template <
class Fields>
337 is_upgrade(boost::beast::http::header<false, Fields>
const& req)
339 if (req.version() < 11)
341 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
419 protocol::MessageType type);
428 protocol::MessageType type);
445 template <
typename... Args>
449 if (!
strand_.running_in_this_thread())
452 std::bind(&OverlayImpl::addTxMetrics<Args...>,
this, args...));
593 template <
class Handler>
595 Handler
const& handler,
599 collector->make_gauge(
"Overlay",
"Peer_Disconnects"))
601 ,
hook(collector->make_hook(handler))
OverlayImpl(Application &app, Setup const &setup, ServerHandler &serverHandler, Resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_service &io_service, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
std::string const & name() const
Returns the name of this source.
beast::insight::Hook hook
Json::Value getServerCounts()
Returns information about the local server's performance counters.
const beast::Journal journal_
boost::asio::ip::address address_type
auto const & getCounts() const
An up-to-date copy of all the counters.
boost::asio::basic_waitable_timer< clock_type > timer_
std::optional< std::uint32_t > networkID
std::atomic< uint64_t > peerDisconnectsCharges_
static bool is_upgrade(boost::beast::http::header< true, Fields > const &req)
hash_map< Peer::id_t, std::weak_ptr< PeerImp > > ids_
std::uint64_t getJqTransOverflow() const override
void updateSlotAndSquelch(uint256 const &key, PublicKey const &validator, std::set< Peer::id_t > &&peers, protocol::MessageType type)
Updates message count for validator/peer.
void endOfPeerChain(std::uint32_t id)
Called when the reply from the last peer in a peer chain is received.
std::set< std::uint32_t > csIDs_
std::recursive_mutex mutex_
std::uint64_t getPeerDisconnect() const override
void on_timer(error_code ec)
std::atomic< Peer::id_t > next_id_
std::vector< std::shared_ptr< Peer > > PeerSequence
static std::string makePrefix(std::uint32_t id)
Handoff onHandoff(std::unique_ptr< stream_type > &&bundle, http_request_type &&request, endpoint_type remote_endpoint) override
Conditionally accept an incoming HTTP request.
void incPeerDisconnectCharges() override
std::condition_variable csCV_
boost::asio::io_service::strand strand_
Json::Value getServerInfo()
Returns information about the local server.
TrafficGauges(char const *name, beast::insight::Collector::ptr const &collector)
void broadcast(protocol::TMProposeSet &m) override
Broadcast a proposal.
void connect(beast::IP::Endpoint const &remote_endpoint) override
Establish a peer connection to the specified endpoint.
Json::Value json() override
Return diagnostics on the status of all peers.
Setup const & setup() const
static bool is_upgrade(boost::beast::http::header< false, Fields > const &req)
void incJqTransOverflow() override
Increment and retrieve counter for transaction job queue overflows.
bool processValidatorList(http_request_type const &req, Handoff &handoff)
Handles validator list requests.
beast::insight::Gauge peerDisconnects
bool processHealth(http_request_type const &req, Handoff &handoff)
Handles health requests.
std::condition_variable_any cond_
void sendTxQueue()
Send once a second transactions' hashes aggregated by peers.
PeerFinder::Manager & peerFinder()
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 checkTracking(std::uint32_t) override
Calls the checkTracking function on each peer.
OverlayImpl & operator=(OverlayImpl const &)=delete
Json::Value json() const
Get json representation of the metrics.
void onManifests(std::shared_ptr< protocol::TMManifests > const &m, std::shared_ptr< PeerImp > const &from)
std::shared_ptr< Message > manifestMessage_
Resource::Manager & resourceManager()
boost::asio::ip::tcp::socket socket_type
std::uint64_t getPeerDisconnectCharges() const override
Json::Value getOverlayInfo()
Returns information about peers on the overlay network.
std::vector< TrafficGauges > trafficGauges
boost::asio::io_service & io_service_
reduce_relay::Slots< UptimeClock > slots_
Run transaction reduce-relay feature related metrics.
Json::Value getUnlInfo()
Returns information about the local server's UNL.
Slots is a container for validator's Slot and handles Slot update when a message is received from a v...
std::unique_ptr< PeerFinder::Manager > m_peerFinder
A generic endpoint for log messages.
ServerHandler & serverHandler_
Child(OverlayImpl &overlay)
Json::Value txMetrics() const override
Returns tx reduce-relay metrics.
beast::insight::Gauge bytesIn
PeerSequence getActivePeers() const override
Returns a sequence representing the current list of peers.
beast::insight::Gauge messagesIn
void deleteIdlePeers()
Check if peers stopped relaying messages and if slots stopped receiving messages from the validator.
A metric for measuring an integral value.
bool processRequest(http_request_type const &req, Handoff &handoff)
Handles non-peer protocol requests.
std::optional< std::uint32_t > manifestListSeq_
Tracks load and resource consumption.
std::optional< std::uint32_t > networkID() const override
Returns the ID of the network this server is configured for, if any.
void deletePeer(Peer::id_t id)
Called when the peer is deleted.
Resource::Manager & m_resourceManager
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::set< Peer::id_t > relay(protocol::TMProposeSet &m, uint256 const &uid, PublicKey const &validator) override
Relay a proposal.
void addMetrics(protocol::MessageType type, std::uint32_t val)
Add protocol message metrics.
std::shared_ptr< Message > getManifestsMessage()
Json::Value crawlShards(bool includePublicKey, std::uint32_t relays) override
Returns information reported to the crawl shard RPC command.
void remove(std::shared_ptr< PeerFinder::Slot > const &slot)
Manages the set of connected peers.
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...
void onPeerDeactivate(Peer::id_t id)
boost::container::flat_map< Child *, std::weak_ptr< Child > > list_
std::optional< boost::asio::io_service::work > work_
Timer(OverlayImpl &overlay)
void squelch(PublicKey const &validator, Peer::id_t const id, std::uint32_t squelchDuration) const override
Squelch handler.
Used to indicate the result of a server connection handoff.
std::shared_ptr< Peer > findPeerByPublicKey(PublicKey const &pubKey) override
Returns the peer with the matching public key, or null.
static bool isPeerUpgrade(boost::beast::http::response< Body > const &response)
beast::insight::Gauge bytesOut
metrics::TxMetrics txMetrics_
std::shared_ptr< Writer > makeRedirectResponse(std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type const &request, address_type remote_address)
A version-independent IP address and port combination.
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::weak_ptr< Timer > timer_
std::atomic< uint64_t > jqTransOverflow_
std::shared_ptr< Peer > findPeerByShortID(Peer::id_t const &id) const override
Returns the peer with the matching short id, or null.
void reportTraffic(TrafficCount::category cat, bool isInbound, int bytes)
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector, std::vector< TrafficGauges > &&trafficGauges_)
std::atomic< uint64_t > peerDisconnects_
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
std::shared_ptr< Writer > makeErrorResponse(std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type const &request, address_type remote_address, std::string msg)
hash_map< std::shared_ptr< PeerFinder::Slot >, std::weak_ptr< PeerImp > > m_peers
beast::insight::Gauge messagesOut
static bool isPeerUpgrade(http_request_type const &request)
void add_active(std::shared_ptr< PeerImp > const &peer)
A reference to a handler for performing polled collection.
boost::system::error_code error_code
void onWrite(beast::PropertyStream::Map &stream) override
Subclass override.
Holds unparsed configuration information.
void for_each(UnaryFunc &&f) const
Maintains a set of IP addresses used for getting into the network.
void unsquelch(PublicKey const &validator, Peer::id_t id) const override
Unsquelch handler.
int limit() override
Returns the maximum number of peers we are configured to allow.
bool processCrawl(http_request_type const &req, Handoff &handoff)
Handles crawl requests.
boost::asio::ip::tcp::endpoint endpoint_type