xrpld
Loading...
Searching...
No Matches
xrpl::Overlay Class Referenceabstract

Manages the set of connected peers. More...

#include <Overlay.h>

Inheritance diagram for xrpl::Overlay:
Collaboration diagram for xrpl::Overlay:

Classes

struct  Setup

Public Types

enum class  Promote { Automatic , Never , Always }
using PeerSequence = std::vector<std::shared_ptr<Peer>>

Public Member Functions

 ~Overlay () override=default
virtual void start ()
virtual void stop ()
virtual Handoff onHandoff (std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint remoteAddress)=0
 Conditionally accept an incoming HTTP request.
virtual void connect (beast::IP::Endpoint const &address)=0
 Establish a peer connection to the specified endpoint.
virtual int limit ()=0
 Returns the maximum number of peers we are configured to allow.
virtual std::size_t size () const =0
 Returns the number of active peers.
virtual json::Value json ()=0
 Return diagnostics on the status of all peers.
virtual PeerSequence getActivePeers () const =0
 Returns a sequence representing the current list of peers.
virtual void checkTracking (std::uint32_t index)=0
 Calls the checkTracking function on each peer.
virtual std::shared_ptr< PeerfindPeerByShortID (Peer::id_t const &id) const =0
 Returns the peer with the matching short id, or null.
virtual std::shared_ptr< PeerfindPeerByPublicKey (PublicKey const &pubKey)=0
 Returns the peer with the matching public key, or null.
virtual void broadcast (protocol::TMProposeSet const &m)=0
 Broadcast a proposal.
virtual void broadcast (protocol::TMValidation const &m)=0
 Broadcast a validation.
virtual std::set< Peer::id_trelay (protocol::TMProposeSet const &m, uint256 const &uid, PublicKey const &validator)=0
 Relay a proposal.
virtual std::set< Peer::id_trelay (protocol::TMValidation const &m, uint256 const &uid, PublicKey const &validator)=0
 Relay a validation.
virtual void relay (uint256 const &hash, std::optional< std::reference_wrapper< protocol::TMTransaction > > m, std::set< Peer::id_t > const &toSkip)=0
 Relay a transaction.
template<class Function>
void foreach (Function f) const
 Visit every active peer.
virtual void incJqTransOverflow ()=0
 Increment and retrieve counter for transaction job queue overflows.
virtual std::uint64_t getJqTransOverflow () const =0
virtual void incPeerDisconnect ()=0
 Increment and retrieve counters for total peer disconnects, and disconnects we initiate for excessive resource consumption.
virtual std::uint64_t getPeerDisconnect () const =0
virtual void incPeerDisconnectCharges ()=0
virtual std::uint64_t getPeerDisconnectCharges () const =0
virtual std::optional< std::uint32_tnetworkID () const =0
 Returns the ID of the network this server is configured for, if any.
virtual json::Value txMetrics () const =0
 Returns tx reduce-relay metrics.
std::string const & name () const
 Returns the name of this source.
void add (Source &source)
 Add a child source.
template<class Derived>
Derived * add (Derived *child)
 Add a child source by pointer.
void remove (Source &child)
 Remove a child source from this Source.
void removeAll ()
 Remove all child sources from this Source.
void writeOne (PropertyStream &stream)
 Write only this Source to the stream.
void write (PropertyStream &stream)
 write this source and all its children recursively to the stream.
void write (PropertyStream &stream, std::string const &path)
 Parse the path and write the corresponding Source and optional children.
std::pair< Source *, bool > find (std::string path)
 Parse the dot-delimited Source path and return the result.
SourcefindOneDeep (std::string const &name)
PropertyStream::Source * findPath (std::string path)
PropertyStream::Source * findOne (std::string const &name)
virtual void onWrite (Map &)
 Subclass override.

Static Public Member Functions

static bool peelLeadingSlash (std::string *path)
static bool peelTrailingSlashstar (std::string *path)
static std::string peelName (std::string *path)

Protected Types

using socket_type = boost::beast::tcp_stream
using stream_type = boost::beast::ssl_stream<socket_type>

Protected Member Functions

 Overlay ()

Private Attributes

std::string const name_
std::recursive_mutex lock_
Item item_
Sourceparent_ {nullptr}
List< Item > children_

Detailed Description

Manages the set of connected peers.

Definition at line 24 of file Overlay.h.

Member Typedef Documentation

◆ socket_type

using xrpl::Overlay::socket_type = boost::beast::tcp_stream
protected

Definition at line 27 of file Overlay.h.

◆ stream_type

using xrpl::Overlay::stream_type = boost::beast::ssl_stream<socket_type>
protected

Definition at line 28 of file Overlay.h.

◆ PeerSequence

Member Enumeration Documentation

◆ Promote

enum class xrpl::Overlay::Promote
strong
Enumerator
Automatic 
Never 
Always 

Definition at line 38 of file Overlay.h.

Constructor & Destructor Documentation

◆ Overlay()

xrpl::Overlay::Overlay ( )
protected

Definition at line 33 of file Overlay.h.

◆ ~Overlay()

xrpl::Overlay::~Overlay ( )
overridedefault

Member Function Documentation

◆ start()

virtual void xrpl::Overlay::start ( )
virtual

Reimplemented in xrpl::OverlayImpl.

Definition at line 58 of file Overlay.h.

◆ stop()

virtual void xrpl::Overlay::stop ( )
virtual

Reimplemented in xrpl::OverlayImpl.

Definition at line 63 of file Overlay.h.

◆ onHandoff()

virtual Handoff xrpl::Overlay::onHandoff ( std::unique_ptr< stream_type > && bundle,
http_request_type && request,
boost::asio::ip::tcp::endpoint remoteAddress )
pure virtual

Conditionally accept an incoming HTTP request.

Implemented in xrpl::OverlayImpl.

◆ connect()

virtual void xrpl::Overlay::connect ( beast::IP::Endpoint const & address)
pure virtual

Establish a peer connection to the specified endpoint.

The call returns immediately, the connection attempt is performed asynchronously.

Implemented in xrpl::OverlayImpl.

◆ limit()

virtual int xrpl::Overlay::limit ( )
pure virtual

Returns the maximum number of peers we are configured to allow.

Implemented in xrpl::OverlayImpl.

◆ size()

virtual std::size_t xrpl::Overlay::size ( ) const
nodiscardpure virtual

Returns the number of active peers.

Active peers are only those peers that have completed the handshake and are using the peer protocol.

Implemented in xrpl::OverlayImpl.

◆ json()

virtual json::Value xrpl::Overlay::json ( )
pure virtual

Return diagnostics on the status of all peers.

Implemented in xrpl::OverlayImpl.

◆ getActivePeers()

virtual PeerSequence xrpl::Overlay::getActivePeers ( ) const
nodiscardpure virtual

Returns a sequence representing the current list of peers.

The snapshot is made at the time of the call.

Implemented in xrpl::OverlayImpl.

◆ checkTracking()

virtual void xrpl::Overlay::checkTracking ( std::uint32_t index)
pure virtual

Calls the checkTracking function on each peer.

Parameters
indexthe value to pass to the peer's checkTracking function

Implemented in xrpl::OverlayImpl.

◆ findPeerByShortID()

virtual std::shared_ptr< Peer > xrpl::Overlay::findPeerByShortID ( Peer::id_t const & id) const
nodiscardpure virtual

Returns the peer with the matching short id, or null.

Implemented in xrpl::OverlayImpl.

◆ findPeerByPublicKey()

virtual std::shared_ptr< Peer > xrpl::Overlay::findPeerByPublicKey ( PublicKey const & pubKey)
pure virtual

Returns the peer with the matching public key, or null.

Implemented in xrpl::OverlayImpl.

◆ broadcast() [1/2]

virtual void xrpl::Overlay::broadcast ( protocol::TMProposeSet const & m)
pure virtual

Broadcast a proposal.

Implemented in xrpl::OverlayImpl.

◆ broadcast() [2/2]

virtual void xrpl::Overlay::broadcast ( protocol::TMValidation const & m)
pure virtual

Broadcast a validation.

Implemented in xrpl::OverlayImpl.

◆ relay() [1/3]

virtual std::set< Peer::id_t > xrpl::Overlay::relay ( protocol::TMProposeSet const & m,
uint256 const & uid,
PublicKey const & validator )
pure virtual

Relay a proposal.

Parameters
mthe serialized proposal
uidthe id used to identify this proposal
validatorThe pubkey of the validator that issued this proposal
Returns
the set of peers which have already sent us this proposal

Implemented in xrpl::OverlayImpl.

◆ relay() [2/3]

virtual std::set< Peer::id_t > xrpl::Overlay::relay ( protocol::TMValidation const & m,
uint256 const & uid,
PublicKey const & validator )
pure virtual

Relay a validation.

Parameters
mthe serialized validation
uidthe id used to identify this validation
validatorThe pubkey of the validator that issued this validation
Returns
the set of peers which have already sent us this validation

Implemented in xrpl::OverlayImpl.

◆ relay() [3/3]

virtual void xrpl::Overlay::relay ( uint256 const & hash,
std::optional< std::reference_wrapper< protocol::TMTransaction > > m,
std::set< Peer::id_t > const & toSkip )
pure virtual

Relay a transaction.

If the tx reduce-relay feature is enabled then randomly select peers to relay to and queue transaction's hash for the rest of the peers.

Parameters
hashtransaction's hash
mtransaction's protocol message to relay
toSkippeers which have already seen this transaction

Implemented in xrpl::OverlayImpl.

◆ foreach()

template<class Function>
void xrpl::Overlay::foreach ( Function f) const

Visit every active peer.

The visitor must be invocable as: Function(std::shared_ptr<Peer> const& peer);

Parameters
fthe invocable to call with every peer

Definition at line 166 of file Overlay.h.

◆ incJqTransOverflow()

virtual void xrpl::Overlay::incJqTransOverflow ( )
pure virtual

Increment and retrieve counter for transaction job queue overflows.

Implemented in xrpl::OverlayImpl.

◆ getJqTransOverflow()

virtual std::uint64_t xrpl::Overlay::getJqTransOverflow ( ) const
nodiscardpure virtual

Implemented in xrpl::OverlayImpl.

◆ incPeerDisconnect()

virtual void xrpl::Overlay::incPeerDisconnect ( )
pure virtual

Increment and retrieve counters for total peer disconnects, and disconnects we initiate for excessive resource consumption.

Implemented in xrpl::OverlayImpl.

◆ getPeerDisconnect()

virtual std::uint64_t xrpl::Overlay::getPeerDisconnect ( ) const
nodiscardpure virtual

Implemented in xrpl::OverlayImpl.

◆ incPeerDisconnectCharges()

virtual void xrpl::Overlay::incPeerDisconnectCharges ( )
pure virtual

Implemented in xrpl::OverlayImpl.

◆ getPeerDisconnectCharges()

virtual std::uint64_t xrpl::Overlay::getPeerDisconnectCharges ( ) const
nodiscardpure virtual

Implemented in xrpl::OverlayImpl.

◆ networkID()

virtual std::optional< std::uint32_t > xrpl::Overlay::networkID ( ) const
nodiscardpure virtual

Returns the ID of the network this server is configured for, if any.

The ID is just a numerical identifier, with the IDs 0, 1 and 2 used to identify the mainnet, the testnet and the devnet respectively.

Returns
The numerical identifier configured by the administrator of the server. An unseated optional, otherwise.

Implemented in xrpl::OverlayImpl.

◆ txMetrics()

virtual json::Value xrpl::Overlay::txMetrics ( ) const
nodiscardpure virtual

Returns tx reduce-relay metrics.

Returns
json value of tx reduce-relay metrics

Implemented in xrpl::OverlayImpl.

◆ name()

std::string const & beast::PropertyStream::Source::name ( ) const
nodiscardinherited

Returns the name of this source.

Definition at line 168 of file beast_PropertyStream.cpp.

◆ add() [1/2]

void beast::PropertyStream::Source::add ( Source & source)
inherited

Add a child source.

Definition at line 174 of file beast_PropertyStream.cpp.

◆ add() [2/2]

template<class Derived>
Derived * beast::PropertyStream::Source::add ( Derived * child)
inherited

Add a child source by pointer.

The source pointer is returned so it can be used in ctor-initializers.

Definition at line 338 of file PropertyStream.h.

◆ remove()

void beast::PropertyStream::Source::remove ( Source & child)
inherited

Remove a child source from this Source.

Definition at line 185 of file beast_PropertyStream.cpp.

◆ removeAll()

void beast::PropertyStream::Source::removeAll ( )
inherited

Remove all child sources from this Source.

Definition at line 196 of file beast_PropertyStream.cpp.

◆ writeOne()

void beast::PropertyStream::Source::writeOne ( PropertyStream & stream)
inherited

Write only this Source to the stream.

Definition at line 209 of file beast_PropertyStream.cpp.

◆ write() [1/2]

void beast::PropertyStream::Source::write ( PropertyStream & stream)
inherited

write this source and all its children recursively to the stream.

Definition at line 216 of file beast_PropertyStream.cpp.

◆ write() [2/2]

void beast::PropertyStream::Source::write ( PropertyStream & stream,
std::string const & path )
inherited

Parse the path and write the corresponding Source and optional children.

If the source is found, it is written. If the wildcard character '*' exists as the last character in the path, then all the children are written recursively.

Definition at line 228 of file beast_PropertyStream.cpp.

◆ find()

std::pair< PropertyStream::Source *, bool > beast::PropertyStream::Source::find ( std::string path)
inherited

Parse the dot-delimited Source path and return the result.

The first value will be a pointer to the Source object corresponding to the given path. If no Source object exists, then the first value will be nullptr and the second value will be undefined. The second value is a boolean indicating whether or not the path string specifies the wildcard character '*' as the last character.

print statement examples "parent.child" prints child and all of its children "parent.child." start at the parent and print down to child "parent.grandchild" prints nothing- grandchild not direct descendent "parent.grandchild." starts at the parent and prints down to grandchild "parent.grandchild.*" starts at parent, print through grandchild children

Definition at line 246 of file beast_PropertyStream.cpp.

◆ findOneDeep()

PropertyStream::Source * beast::PropertyStream::Source::findOneDeep ( std::string const & name)
inherited

Definition at line 317 of file beast_PropertyStream.cpp.

◆ findPath()

PropertyStream::Source * beast::PropertyStream::Source::findPath ( std::string path)
inherited

Definition at line 334 of file beast_PropertyStream.cpp.

◆ findOne()

PropertyStream::Source * beast::PropertyStream::Source::findOne ( std::string const & name)
inherited

Definition at line 352 of file beast_PropertyStream.cpp.

◆ peelLeadingSlash()

bool beast::PropertyStream::Source::peelLeadingSlash ( std::string * path)
staticinherited

Definition at line 266 of file beast_PropertyStream.cpp.

◆ peelTrailingSlashstar()

bool beast::PropertyStream::Source::peelTrailingSlashstar ( std::string * path)
staticinherited

Definition at line 277 of file beast_PropertyStream.cpp.

◆ peelName()

std::string beast::PropertyStream::Source::peelName ( std::string * path)
staticinherited

Definition at line 293 of file beast_PropertyStream.cpp.

◆ onWrite()

void beast::PropertyStream::Source::onWrite ( Map & )
virtualinherited

Subclass override.

The default version does nothing.

Reimplemented in xrpl::ApplicationImp, xrpl::LedgerCleanerImp, xrpl::OverlayImpl, xrpl::PeerFinder::ManagerImp, and xrpl::Resource::ManagerImp.

Definition at line 364 of file beast_PropertyStream.cpp.

Member Data Documentation

◆ name_

std::string const beast::PropertyStream::Source::name_
privateinherited

Definition at line 311 of file PropertyStream.h.

◆ lock_

std::recursive_mutex beast::PropertyStream::Source::lock_
privateinherited

Definition at line 312 of file PropertyStream.h.

◆ item_

Item beast::PropertyStream::Source::item_
privateinherited

Definition at line 313 of file PropertyStream.h.

◆ parent_

Source* beast::PropertyStream::Source::parent_ {nullptr}
privateinherited

Definition at line 314 of file PropertyStream.h.

◆ children_

List<Item> beast::PropertyStream::Source::children_
privateinherited

Definition at line 315 of file PropertyStream.h.