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/peerfinder/PeerfinderManager.h>
34 #include <ripple/resource/ResourceManager.h>
35 #include <ripple/rpc/ServerHandler.h>
36 #include <ripple/server/Handoff.h>
37 #include <boost/asio/basic_waitable_timer.hpp>
38 #include <boost/asio/ip/tcp.hpp>
39 #include <boost/asio/ssl/context.hpp>
40 #include <boost/asio/strand.hpp>
41 #include <boost/container/flat_map.hpp>
42 #include <boost/optional.hpp>
83 boost::asio::basic_waitable_timer<clock_type>
timer_;
99 boost::optional<boost::asio::io_service::work>
work_;
104 boost::container::flat_map<Child*, std::weak_ptr<Child>>
list_;
148 boost::asio::io_service& io_service,
195 size()
const override;
212 broadcast(protocol::TMProposeSet& m)
override;
215 broadcast(protocol::TMValidation& m)
override;
219 protocol::TMProposeSet& m,
225 protocol::TMValidation& m,
258 template <
class UnaryFunc>
276 if (
auto p = w.lock())
290 template <
class Body>
296 return response.result() ==
297 boost::beast::http::status::switching_protocols;
300 template <
class Fields>
302 is_upgrade(boost::beast::http::header<true, Fields>
const& req)
304 if (req.version() < 11)
306 if (req.method() != boost::beast::http::verb::get)
308 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
314 template <
class Fields>
316 is_upgrade(boost::beast::http::header<false, Fields>
const& req)
318 if (req.version() < 11)
320 if (!boost::beast::http::token_list{req[
"Connection"]}.exists(
368 boost::optional<std::uint32_t>
398 protocol::MessageType type);
407 protocol::MessageType type);
568 template <
class Handler>
570 Handler
const& handler,
574 collector->make_gauge(
"Overlay",
"Peer_Disconnects"))
576 ,
hook(collector->make_hook(handler))
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_
boost::optional< boost::asio::io_service::work > work_
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
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
void updateSlotAndSquelch(uint256 const &key, PublicKey const &validator, std::set< Peer::id_t > &&peers, protocol::MessageType type)
Updates message count for validator/peer.
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.
void onStart() override
Override called during start.
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.
void onChildrenStopped() override
Override called when all children have stopped.
std::condition_variable_any cond_
PeerFinder::Manager & peerFinder()
Integers of any length that is a multiple of 32-bits.
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
void onManifests(std::shared_ptr< protocol::TMManifests > const &m, std::shared_ptr< PeerImp > const &from)
Provides an interface for starting and stopping.
std::shared_ptr< Message > manifestMessage_
Resource::Manager & resourceManager()
boost::asio::ip::tcp::socket socket_type
boost::optional< std::uint32_t > networkID_
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_
ServerHandler & serverHandler()
Json::Value getUnlInfo()
Returns information about the local server's UNL.
std::unique_ptr< PeerFinder::Manager > m_peerFinder
A generic endpoint for log messages.
ServerHandler & serverHandler_
void onPrepare() override
Override called during preparation.
Child(OverlayImpl &overlay)
beast::insight::Gauge bytesIn
PeerSequence getActivePeers() const override
Returns a sequence representing the current list of peers.
beast::insight::Gauge messagesIn
OverlayImpl(Application &app, Setup const &setup, Stoppable &parent, ServerHandler &serverHandler, Resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_service &io_service, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
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.
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.
boost::optional< std::uint32_t > networkID() const override
Returns the ID of the network this server is configured for, if any.
std::shared_ptr< Message > getManifestsMessage()
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_
void lastLink(std::uint32_t id)
Called when the last link from a peer chain is received.
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
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.
Slots is a container for validator's Slot and handles Slot update when a message is received from a v...
void incPeerDisconnect() override
Increment and retrieve counters for total peer disconnects, and disconnects we initiate for excessive...
std::weak_ptr< Timer > timer_
std::atomic< std::chrono::seconds > csLast_
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)
Json::Value crawlShards(bool pubKey, std::uint32_t hops) override
Returns information reported to the crawl shard RPC command.
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector, std::vector< TrafficGauges > &&trafficGauges_)
std::atomic< uint64_t > peerDisconnects_
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
squelch::Slots< UptimeClock > slots_
void onWrite(beast::PropertyStream::Map &stream) override
Subclass override.
Holds unparsed configuration information.
void for_each(UnaryFunc &&f) const
void onStop() override
Override called when the stop notification is issued.
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