rippled
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Private Attributes | List of all members
ripple::Overlay Class Referenceabstract

Manages the set of connected peers. More...

Inheritance diagram for ripple::Overlay:
Inheritance graph
[legend]
Collaboration diagram for ripple::Overlay:
Collaboration graph
[legend]

Classes

struct  Setup
 

Public Types

enum  Promote { Promote::automatic, Promote::never, Promote::always }
 
using PeerSequence = std::vector< std::shared_ptr< Peer > >
 

Public Member Functions

virtual ~Overlay ()=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 remote_address)=0
 Conditionally accept an incoming HTTP request. More...
 
virtual void connect (beast::IP::Endpoint const &address)=0
 Establish a peer connection to the specified endpoint. More...
 
virtual int limit ()=0
 Returns the maximum number of peers we are configured to allow. More...
 
virtual std::size_t size () const =0
 Returns the number of active peers. More...
 
virtual Json::Value json ()=0
 Return diagnostics on the status of all peers. More...
 
virtual PeerSequence getActivePeers () const =0
 Returns a sequence representing the current list of peers. More...
 
virtual void checkTracking (std::uint32_t index)=0
 Calls the checkTracking function on each peer. More...
 
virtual std::shared_ptr< PeerfindPeerByShortID (Peer::id_t const &id) const =0
 Returns the peer with the matching short id, or null. More...
 
virtual std::shared_ptr< PeerfindPeerByPublicKey (PublicKey const &pubKey)=0
 Returns the peer with the matching public key, or null. More...
 
virtual void broadcast (protocol::TMProposeSet &m)=0
 Broadcast a proposal. More...
 
virtual void broadcast (protocol::TMValidation &m)=0
 Broadcast a validation. More...
 
virtual std::set< Peer::id_trelay (protocol::TMProposeSet &m, uint256 const &uid, PublicKey const &validator)=0
 Relay a proposal. More...
 
virtual std::set< Peer::id_trelay (protocol::TMValidation &m, uint256 const &uid, PublicKey const &validator)=0
 Relay a validation. More...
 
virtual void relay (uint256 const &hash, protocol::TMTransaction &m, std::set< Peer::id_t > const &toSkip)=0
 Relay a transaction. More...
 
template<class Function >
void foreach (Function f) const
 Visit every active peer. More...
 
virtual void incJqTransOverflow ()=0
 Increment and retrieve counter for transaction job queue overflows. More...
 
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. More...
 
virtual std::uint64_t getPeerDisconnect () const =0
 
virtual void incPeerDisconnectCharges ()=0
 
virtual std::uint64_t getPeerDisconnectCharges () const =0
 
virtual Json::Value crawlShards (bool includePublicKey, std::uint32_t hops)=0
 Returns information reported to the crawl shard RPC command. More...
 
virtual std::optional< std::uint32_tnetworkID () const =0
 Returns the ID of the network this server is configured for, if any. More...
 
virtual Json::Value txMetrics () const =0
 Returns tx reduce-relay metrics. More...
 
std::string const & name () const
 Returns the name of this source. More...
 
void add (Source &source)
 Add a child source. More...
 
template<class Derived >
Derived * add (Derived *child)
 Add a child source by pointer. More...
 
void remove (Source &child)
 Remove a child source from this Source. More...
 
void removeAll ()
 Remove all child sources from this Source. More...
 
void write_one (PropertyStream &stream)
 Write only this Source to the stream. More...
 
void write (PropertyStream &stream)
 write this source and all its children recursively to the stream. More...
 
void write (PropertyStream &stream, std::string const &path)
 Parse the path and write the corresponding Source and optional children. More...
 
std::pair< Source *, bool > find (std::string path)
 Parse the dot-delimited Source path and return the result. More...
 
Sourcefind_one_deep (std::string const &name)
 
PropertyStream::Source * find_path (std::string path)
 
PropertyStream::Source * find_one (std::string const &name)
 
virtual void onWrite (Map &)
 Subclass override. More...
 

Static Public Member Functions

static bool peel_leading_slash (std::string *path)
 
static bool peel_trailing_slashstar (std::string *path)
 
static std::string peel_name (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

const std::string m_name
 
std::recursive_mutex lock_
 
Item item_
 
Sourceparent_
 
List< Item > children_
 

Detailed Description

Manages the set of connected peers.

Definition at line 51 of file Overlay.h.

Member Typedef Documentation

◆ socket_type

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

Definition at line 54 of file Overlay.h.

◆ stream_type

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

Definition at line 55 of file Overlay.h.

◆ PeerSequence

Definition at line 79 of file Overlay.h.

Member Enumeration Documentation

◆ Promote

Enumerator
automatic 
never 
always 

Definition at line 65 of file Overlay.h.

Constructor & Destructor Documentation

◆ Overlay()

ripple::Overlay::Overlay ( )
protected

Definition at line 60 of file Overlay.h.

◆ ~Overlay()

virtual ripple::Overlay::~Overlay ( )
virtualdefault

Member Function Documentation

◆ start()

virtual void ripple::Overlay::start ( )
virtual

Reimplemented in ripple::OverlayImpl.

Definition at line 84 of file Overlay.h.

◆ stop()

virtual void ripple::Overlay::stop ( )
virtual

Reimplemented in ripple::OverlayImpl.

Definition at line 89 of file Overlay.h.

◆ onHandoff()

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

Conditionally accept an incoming HTTP request.

Implemented in ripple::OverlayImpl.

◆ connect()

virtual void ripple::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 ripple::OverlayImpl.

◆ limit()

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

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

Implemented in ripple::OverlayImpl.

◆ size()

virtual std::size_t ripple::Overlay::size ( ) const
pure 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 ripple::OverlayImpl.

◆ json()

virtual Json::Value ripple::Overlay::json ( )
pure virtual

Return diagnostics on the status of all peers.

Implemented in ripple::OverlayImpl.

◆ getActivePeers()

virtual PeerSequence ripple::Overlay::getActivePeers ( ) const
pure virtual

Returns a sequence representing the current list of peers.

The snapshot is made at the time of the call.

Implemented in ripple::OverlayImpl.

◆ checkTracking()

virtual void ripple::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 ripple::OverlayImpl.

◆ findPeerByShortID()

virtual std::shared_ptr<Peer> ripple::Overlay::findPeerByShortID ( Peer::id_t const &  id) const
pure virtual

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

Implemented in ripple::OverlayImpl.

◆ findPeerByPublicKey()

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

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

Implemented in ripple::OverlayImpl.

◆ broadcast() [1/2]

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

Broadcast a proposal.

Implemented in ripple::OverlayImpl.

◆ broadcast() [2/2]

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

Broadcast a validation.

Implemented in ripple::OverlayImpl.

◆ relay() [1/3]

virtual std::set<Peer::id_t> ripple::Overlay::relay ( protocol::TMProposeSet &  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 ripple::OverlayImpl.

◆ relay() [2/3]

virtual std::set<Peer::id_t> ripple::Overlay::relay ( protocol::TMValidation &  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 ripple::OverlayImpl.

◆ relay() [3/3]

virtual void ripple::Overlay::relay ( uint256 const &  hash,
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 ripple::OverlayImpl.

◆ foreach()

template<class Function >
void ripple::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 198 of file Overlay.h.

◆ incJqTransOverflow()

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

Increment and retrieve counter for transaction job queue overflows.

Implemented in ripple::OverlayImpl.

◆ getJqTransOverflow()

virtual std::uint64_t ripple::Overlay::getJqTransOverflow ( ) const
pure virtual

Implemented in ripple::OverlayImpl.

◆ incPeerDisconnect()

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

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

Implemented in ripple::OverlayImpl.

◆ getPeerDisconnect()

virtual std::uint64_t ripple::Overlay::getPeerDisconnect ( ) const
pure virtual

Implemented in ripple::OverlayImpl.

◆ incPeerDisconnectCharges()

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

Implemented in ripple::OverlayImpl.

◆ getPeerDisconnectCharges()

virtual std::uint64_t ripple::Overlay::getPeerDisconnectCharges ( ) const
pure virtual

Implemented in ripple::OverlayImpl.

◆ crawlShards()

virtual Json::Value ripple::Overlay::crawlShards ( bool  includePublicKey,
std::uint32_t  hops 
)
pure virtual

Returns information reported to the crawl shard RPC command.

Parameters
includePublicKeyinclude peer public keys in the result.
hopsthe maximum jumps the crawler will attempt. The number of hops achieved is not guaranteed.

Implemented in ripple::OverlayImpl.

◆ networkID()

virtual std::optional<std::uint32_t> ripple::Overlay::networkID ( ) const
pure 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 ripple::OverlayImpl.

◆ txMetrics()

virtual Json::Value ripple::Overlay::txMetrics ( ) const
pure virtual

Returns tx reduce-relay metrics.

Returns
json value of tx reduce-relay metrics

Implemented in ripple::OverlayImpl.

◆ name()

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

Returns the name of this source.

Definition at line 190 of file beast_PropertyStream.cpp.

◆ add() [1/2]

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

Add a child source.

Definition at line 196 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 360 of file PropertyStream.h.

◆ remove()

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

Remove a child source from this Source.

Definition at line 208 of file beast_PropertyStream.cpp.

◆ removeAll()

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

Remove all child sources from this Source.

Definition at line 220 of file beast_PropertyStream.cpp.

◆ write_one()

void beast::PropertyStream::Source::write_one ( PropertyStream stream)
inherited

Write only this Source to the stream.

Definition at line 233 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 240 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 252 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 discendent "parent.grandchild." starts at the parent and prints down to grandchild "parent.grandchild.*" starts at parent, print through grandchild children

Definition at line 266 of file beast_PropertyStream.cpp.

◆ find_one_deep()

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

Definition at line 333 of file beast_PropertyStream.cpp.

◆ find_path()

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

Definition at line 350 of file beast_PropertyStream.cpp.

◆ find_one()

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

Definition at line 368 of file beast_PropertyStream.cpp.

◆ peel_leading_slash()

bool beast::PropertyStream::Source::peel_leading_slash ( std::string path)
staticinherited

Definition at line 286 of file beast_PropertyStream.cpp.

◆ peel_trailing_slashstar()

bool beast::PropertyStream::Source::peel_trailing_slashstar ( std::string path)
staticinherited

Definition at line 297 of file beast_PropertyStream.cpp.

◆ peel_name()

std::string beast::PropertyStream::Source::peel_name ( std::string path)
staticinherited

Definition at line 313 of file beast_PropertyStream.cpp.

◆ onWrite()

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

Subclass override.

The default version does nothing.

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

Definition at line 380 of file beast_PropertyStream.cpp.

Member Data Documentation

◆ m_name

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

Definition at line 333 of file PropertyStream.h.

◆ lock_

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

Definition at line 334 of file PropertyStream.h.

◆ item_

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

Definition at line 335 of file PropertyStream.h.

◆ parent_

Source* beast::PropertyStream::Source::parent_
privateinherited

Definition at line 336 of file PropertyStream.h.

◆ children_

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

Definition at line 337 of file PropertyStream.h.