xrpld
Loading...
Searching...
No Matches
xrpl::test::CapturePeer Class Reference

A real PeerImp that captures the messages it would have sent. More...

#include <CapturePeer.h>

Inheritance diagram for xrpl::test::CapturePeer:
Collaboration diagram for xrpl::test::CapturePeer:

Public Types

using MiddleType = boost::beast::tcp_stream
using StreamType = boost::beast::ssl_stream<MiddleType>
using SocketType = boost::asio::ip::tcp::socket
enum class  Tracking { Diverged , Unknown , Converged }
 Whether the peer's view of the ledger converges or diverges from ours. More...
using Ptr = std::shared_ptr<Peer>
using ID = std::uint32_t
 Uniquely identifies a peer.

Public Member Functions

 CapturePeer (Application &app, Peer::ID id, std::shared_ptr< peer_finder::Slot > const &slot, HttpRequestType request, PublicKey const &publicKey, ProtocolVersion protocol, resource::Consumer consumer, std::unique_ptr< StreamType > streamPtr, OverlayImpl &overlay)
 Takes PeerImp's two rvalue-reference parameters by value instead, so a derived double can inherit this constructor without a never-moved-from warning.
 ~CapturePeer () override=default
void run () override
 Does nothing, so the peer stays registered.
void send (std::shared_ptr< Message > const &m) override
 Captures the message instead of writing it, so replies are observable.
std::vector< std::shared_ptr< Message > > const & sent () const
std::shared_ptr< Message > lastSent () const
resource::Charge feeCharge () const
 Reads the accumulated charge without draining it through charge().
beast::Journal const & pJournal () const
std::shared_ptr< peer_finder::Slot > const & slot ()
void stop () override
void sendTxQueue () override
 Send aggregated transactions' hashes.
void addTxQueue (UInt256 const &hash) override
 Add transaction's hash to the transactions' hashes queue.
void removeTxQueue (UInt256 const &hash) override
 Remove transaction's hash from the transactions' hashes queue.
template<class FwdIt>
requires ( std::is_same_v< // typename std::iterator_traits<FwdIt>::value_type, peer_finder::Endpoint>)
void sendEndpoints (FwdIt first, FwdIt last)
 Send a set of PeerFinder endpoints as a protocol message.
beast::ip::Endpoint getRemoteAddress () const override
void charge (resource::Charge const &fee, std::string const &context) override
 Adjust this peer's load balance based on the type of load imposed.
Peer::ID id () const override
bool crawl () const
 Returns true if this connection will publicly share its IP address.
bool cluster () const override
 Returns true if this connection is a member of the cluster.
void checkTracking (std::uint32_t validationSeq)
 Check if the peer is tracking.
void checkTracking (std::uint32_t seq1, std::uint32_t seq2)
PublicKey const & getNodePublic () const override
std::string getVersion () const
 Return the version of xrpld that the peer is running, if reported.
ClockType::duration uptime () const
json::Value json () override
bool supportsFeature (ProtocolFeature f) const override
std::optional< std::size_t > publisherListSequence (PublicKey const &pubKey) const override
void setPublisherListSequence (PublicKey const &pubKey, std::size_t const seq) override
UInt256 getClosedLedgerHash () const override
bool hasLedger (UInt256 const &hash, std::uint32_t seq) const override
void ledgerRange (std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
bool hasTxSet (UInt256 const &hash) const override
void cycleStatus () override
bool hasRange (std::uint32_t uMin, std::uint32_t uMax) override
int getScore (bool haveItem) const override
bool isHighLatency () const override
void fail (std::string const &reason)
bool compressionEnabled () const override
std::size_t maxManifestsMessageSize () const
 Largest TMManifests message this node accepts, in bytes.
bool txReduceRelayEnabled () const override
void onMessageUnknown (std::uint16_t type)
void onMessageBegin (std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m, std::size_t size, std::size_t uncompressedSize, bool isCompressed)
void onMessageEnd (std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m)
void onMessage (std::shared_ptr< protocol::TMManifests > const &m)
void onMessage (std::shared_ptr< protocol::TMPing > const &m)
void onMessage (std::shared_ptr< protocol::TMCluster > const &m)
void onMessage (std::shared_ptr< protocol::TMEndpoints > const &m)
void onMessage (std::shared_ptr< protocol::TMTransaction > const &m)
void onMessage (std::shared_ptr< protocol::TMGetLedger > const &m)
void onMessage (std::shared_ptr< protocol::TMLedgerData > const &m)
void onMessage (std::shared_ptr< protocol::TMProposeSet > const &m)
void onMessage (std::shared_ptr< protocol::TMStatusChange > const &m)
void onMessage (std::shared_ptr< protocol::TMHaveTransactionSet > const &m)
void onMessage (std::shared_ptr< protocol::TMValidatorListCollection > const &m)
void onMessage (std::shared_ptr< protocol::TMValidation > const &m)
void onMessage (std::shared_ptr< protocol::TMGetObjectByHash > const &m)
void onMessage (std::shared_ptr< protocol::TMHaveTransactions > const &m)
void onMessage (std::shared_ptr< protocol::TMTransactions > const &m)
void onMessage (std::shared_ptr< protocol::TMSquelch > const &m)
void onMessage (std::shared_ptr< protocol::TMProofPathRequest > const &m)
void onMessage (std::shared_ptr< protocol::TMProofPathResponse > const &m)
void onMessage (std::shared_ptr< protocol::TMReplayDeltaRequest > const &m)
void onMessage (std::shared_ptr< protocol::TMReplayDeltaResponse > const &m)
T shared_from_this (T... args)
T weak_from_this (T... args)

Protected Member Functions

void processLedgerRequest (std::shared_ptr< protocol::TMGetLedger > const &m, std::vector< SHAMapNodeID > nodeIDs)
void processGetObjectByHash (std::shared_ptr< protocol::TMGetObjectByHash > const &m)
 Process a generic-query TMGetObjectByHash message.
resource::Charge currentFeeCharge () const
 Read-only accessor for the accumulated peer-message charge.

Static Protected Member Functions

static resource::Charge computeGetObjectByHashFee (int const requested, int const found)
 Compute the per-message resource charge for a TMGetObjectByHash request based on how much work was actually performed.

Private Types

using ClockType = std::chrono::steady_clock
using ErrorCode = boost::system::error_code
using AddressType = boost::asio::ip::address
using EndpointType = boost::asio::ip::tcp::endpoint
using WaitableTimer = boost::asio::basic_waitable_timer<std::chrono::steady_clock>
using Compressed = compression::Compressed

Private Member Functions

void fail (std::string const &name, ErrorCode ec)
void close ()
void gracefulClose ()
void setTimer ()
void cancelTimer () noexcept
void onTimer (boost::system::error_code const &ec)
void onShutdown (ErrorCode ec)
void doAccept ()
std::string name () const
std::string domain () const
void doProtocolStart ()
void onReadMessage (ErrorCode ec, std::size_t bytesTransferred)
void onWriteMessage (ErrorCode ec, std::size_t bytesTransferred)
void handleTransaction (std::shared_ptr< protocol::TMTransaction > const &m, bool eraseTxQueue, bool batch)
 Called from onMessage(TMTransaction(s)).
void handleHaveTransactions (std::shared_ptr< protocol::TMHaveTransactions > const &m)
 Handle protocol message with hashes of transactions that have not been relayed by an upstream node down to its peers - request transactions, which have not been relayed to this peer.
std::string const & fingerprint () const override
std::string const & prefix () const
void addLedger (UInt256 const &hash, std::scoped_lock< std::mutex > const &lockedRecentLock)
void doFetchPack (std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
void onValidatorListMessage (std::string const &messageType, std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs)
void doTransactions (std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
 Process peer's request to send missing transactions.
void checkTransaction (HashRouterFlags flags, bool checkSignature, std::shared_ptr< STTx const > const &stx, bool batch)
void checkPropose (bool isTrusted, std::shared_ptr< protocol::TMProposeSet > const &packet, RCLCxPeerPos peerPos)
void checkValidation (std::shared_ptr< STValidation > const &val, UInt256 const &key, std::shared_ptr< protocol::TMValidation > const &packet)
void sendLedgerBase (std::shared_ptr< Ledger const > const &ledger, protocol::TMLedgerData &ledgerData)
std::shared_ptr< Ledger const > getLedger (std::shared_ptr< protocol::TMGetLedger > const &m)
std::shared_ptr< SHAMap const > getTxSet (std::shared_ptr< protocol::TMGetLedger > const &m) const

Static Private Member Functions

static std::string makePrefix (std::string const &fingerprint)

Private Attributes

std::vector< std::shared_ptr< Message > > sent_
Application & app_
ID const id_
std::string fingerprint_
std::string prefix_
beast::WrappedSink sink_
beast::WrappedSink pSink_
beast::Journal const journal_
beast::Journal const pJournal_
std::unique_ptr< StreamType > streamPtr_
SocketType & socket_
StreamType & stream_
boost::asio::strand< boost::asio::executor > strand_
WaitableTimer timer_
beast::ip::Endpoint const remoteAddress_
OverlayImpl & overlay_
bool const inbound_
ProtocolVersion protocol_
std::atomic< Tracking > tracking_
ClockType::time_point trackingTime_
bool detaching_ = false
PublicKey const publicKey_
std::string name_
std::shared_mutex nameMutex_
LedgerIndex minLedger_ = 0
LedgerIndex maxLedger_ = 0
UInt256 closedLedgerHash_
UInt256 previousLedgerHash_
boost::circular_buffer< UInt256 > recentLedgers_ {128}
boost::circular_buffer< UInt256 > recentTxSets_ {128}
std::optional< std::chrono::milliseconds > latency_
std::optional< std::uint32_t > lastPingSeq_
ClockType::time_point lastPingTime_
ClockType::time_point const creationTime_
reduce_relay::Squelch< UptimeClock > squelch_
std::mutex recentLock_
protocol::TMStatusChange lastStatus_
resource::Consumer usage_
ChargeWithContext fee_
std::atomic< bool > chargeDisconnectFired_ {false}
std::shared_ptr< peer_finder::Slot > const slot_
boost::beast::multi_buffer readBuffer_
HttpRequestType request_
HttpResponseType response_
boost::beast::http::fields const & headers_
std::queue< std::shared_ptr< Message > > sendQueue_
bool gracefulClose_ = false
int largeSendq_ = 0
std::unique_ptr< LoadEvent > loadEvent_
HashMap< PublicKey, std::size_t > publisherListSequences_
Compressed compressionEnabled_ = Compressed::Off
HashSet< UInt256 > txQueue_
bool txReduceRelayEnabled_ = false
bool ledgerReplayEnabled_ = false
LedgerReplayMsgHandler ledgerReplayMsgHandler_
struct { 
   Metrics   sent 
   Metrics   recv 
} metrics_

Detailed Description

A real PeerImp that captures the messages it would have sent.

Only send and run are overridden, so onMessage runs production code. Derive from this to reach a protected PeerImp member.

Definition at line 46 of file CapturePeer.h.

Member Typedef Documentation

◆ MiddleType

using xrpl::test::CapturePeer::MiddleType = boost::beast::tcp_stream

Definition at line 49 of file CapturePeer.h.

◆ StreamType

using xrpl::test::CapturePeer::StreamType = boost::beast::ssl_stream<MiddleType>

Definition at line 50 of file CapturePeer.h.

◆ SocketType

using xrpl::test::CapturePeer::SocketType = boost::asio::ip::tcp::socket

Definition at line 51 of file CapturePeer.h.

◆ ClockType

Definition at line 75 of file PeerImp.h.

◆ ErrorCode

using xrpl::PeerImp::ErrorCode = boost::system::error_code
privateinherited

Definition at line 76 of file PeerImp.h.

◆ AddressType

using xrpl::PeerImp::AddressType = boost::asio::ip::address
privateinherited

Definition at line 80 of file PeerImp.h.

◆ EndpointType

using xrpl::PeerImp::EndpointType = boost::asio::ip::tcp::endpoint
privateinherited

Definition at line 81 of file PeerImp.h.

◆ WaitableTimer

using xrpl::PeerImp::WaitableTimer = boost::asio::basic_waitable_timer<std::chrono::steady_clock>
privateinherited

Definition at line 82 of file PeerImp.h.

◆ Compressed

Definition at line 83 of file PeerImp.h.

◆ Ptr

using xrpl::Peer::Ptr = std::shared_ptr<Peer>
inherited

Definition at line 33 of file xrpld/overlay/Peer.h.

◆ ID

using xrpl::Peer::ID = std::uint32_t
inherited

Uniquely identifies a peer.

This can be stored in tables to find the peer later. Callers can discover if the peer is no longer connected and make adjustments as needed.

Definition at line 41 of file xrpld/overlay/Peer.h.

Member Enumeration Documentation

◆ Tracking

enum class xrpl::PeerImp::Tracking
stronginherited

Whether the peer's view of the ledger converges or diverges from ours.

Enumerator
Diverged 
Unknown 
Converged 

Definition at line 72 of file PeerImp.h.

Constructor & Destructor Documentation

◆ CapturePeer()

xrpl::test::CapturePeer::CapturePeer ( Application & app,
Peer::ID id,
std::shared_ptr< peer_finder::Slot > const & slot,
HttpRequestType request,
PublicKey const & publicKey,
ProtocolVersion protocol,
resource::Consumer consumer,
std::unique_ptr< StreamType > streamPtr,
OverlayImpl & overlay )

Takes PeerImp's two rvalue-reference parameters by value instead, so a derived double can inherit this constructor without a never-moved-from warning.

Parameters
appThe application owning the peer.
idThe connection id, unique among the overlay's peers.
slotThe peer finder slot; must be seated.
requestThe handshake request.
publicKeyThe peer's node public key.
protocolThe negotiated protocol version.
consumerThe resource manager endpoint for the peer.
streamPtrThe connection's ssl stream.
overlayThe overlay to register with.

Definition at line 68 of file CapturePeer.h.

◆ ~CapturePeer()

xrpl::test::CapturePeer::~CapturePeer ( )
overridedefault

Member Function Documentation

◆ run()

void xrpl::test::CapturePeer::run ( )
overridevirtual

Does nothing, so the peer stays registered.

The real run() reaches PeerImp::doAccept, which fails on an unconnected socket and detaches.

Reimplemented from xrpl::PeerImp.

Definition at line 98 of file CapturePeer.h.

◆ send()

void xrpl::test::CapturePeer::send ( std::shared_ptr< Message > const & m)
overridevirtual

Captures the message instead of writing it, so replies are observable.

Implements xrpl::Peer.

Definition at line 106 of file CapturePeer.h.

◆ sent()

std::vector< std::shared_ptr< Message > > const & xrpl::test::CapturePeer::sent ( ) const
Returns
Every message sent to this peer, in order.

Definition at line 115 of file CapturePeer.h.

◆ lastSent()

std::shared_ptr< Message > xrpl::test::CapturePeer::lastSent ( ) const
Returns
The most recent message sent, or null if there was none.

Definition at line 124 of file CapturePeer.h.

◆ feeCharge()

resource::Charge xrpl::test::CapturePeer::feeCharge ( ) const

Reads the accumulated charge without draining it through charge().

Returns
The charge accumulated on the peer so far.

Definition at line 135 of file CapturePeer.h.

◆ pJournal()

beast::Journal const & xrpl::PeerImp::pJournal ( ) const
inherited

Definition at line 290 of file PeerImp.h.

◆ slot()

std::shared_ptr< peer_finder::Slot > const & xrpl::PeerImp::slot ( )
inherited

Definition at line 296 of file PeerImp.h.

◆ stop()

void xrpl::PeerImp::stop ( )
overridevirtualinherited

Implements xrpl::OverlayImpl::Child.

Definition at line 264 of file PeerImp.cpp.

◆ sendTxQueue()

void xrpl::PeerImp::sendTxQueue ( )
overridevirtualinherited

Send aggregated transactions' hashes.

Implements xrpl::Peer.

Definition at line 338 of file PeerImp.cpp.

◆ addTxQueue()

void xrpl::PeerImp::addTxQueue ( UInt256 const & hash)
overridevirtualinherited

Add transaction's hash to the transactions' hashes queue.

Parameters
hashtransaction's hash

Implements xrpl::Peer.

Reimplemented in xrpl::test::tx_reduce_relay_test::TxReducePeer.

Definition at line 354 of file PeerImp.cpp.

◆ removeTxQueue()

void xrpl::PeerImp::removeTxQueue ( UInt256 const & hash)
overridevirtualinherited

Remove transaction's hash from the transactions' hashes queue.

Parameters
hashtransaction's hash

Implements xrpl::Peer.

Definition at line 369 of file PeerImp.cpp.

◆ sendEndpoints()

template<class FwdIt>
requires ( std::is_same_v< // typename std::iterator_traits<FwdIt>::value_type, peer_finder::Endpoint>)
void xrpl::PeerImp::sendEndpoints ( FwdIt first,
FwdIt last )
inherited

Send a set of PeerFinder endpoints as a protocol message.

Definition at line 827 of file PeerImp.h.

◆ getRemoteAddress()

beast::ip::Endpoint xrpl::PeerImp::getRemoteAddress ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 348 of file PeerImp.h.

◆ charge()

void xrpl::PeerImp::charge ( resource::Charge const & fee,
std::string const & context )
overridevirtualinherited

Adjust this peer's load balance based on the type of load imposed.

Implements xrpl::Peer.

Definition at line 378 of file PeerImp.cpp.

◆ id()

Peer::ID xrpl::PeerImp::id ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 361 of file PeerImp.h.

◆ crawl()

bool xrpl::PeerImp::crawl ( ) const
inherited

Returns true if this connection will publicly share its IP address.

Definition at line 404 of file PeerImp.cpp.

◆ cluster()

bool xrpl::PeerImp::cluster ( ) const
overridevirtualinherited

Returns true if this connection is a member of the cluster.

Implements xrpl::Peer.

Definition at line 413 of file PeerImp.cpp.

◆ checkTracking() [1/2]

void xrpl::PeerImp::checkTracking ( std::uint32_t validationSeq)
inherited

Check if the peer is tracking.

Parameters
validationSeqThe ledger sequence of a recently-validated ledger

Definition at line 2177 of file PeerImp.cpp.

◆ checkTracking() [2/2]

void xrpl::PeerImp::checkTracking ( std::uint32_t seq1,
std::uint32_t seq2 )
inherited

Definition at line 2196 of file PeerImp.cpp.

◆ getNodePublic()

PublicKey const & xrpl::PeerImp::getNodePublic ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 386 of file PeerImp.h.

◆ getVersion()

std::string xrpl::PeerImp::getVersion ( ) const
inherited

Return the version of xrpld that the peer is running, if reported.

Definition at line 419 of file PeerImp.cpp.

◆ uptime()

ClockType::duration xrpl::PeerImp::uptime ( ) const
inherited

Definition at line 399 of file PeerImp.h.

◆ json()

json::Value xrpl::PeerImp::json ( )
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 427 of file PeerImp.cpp.

◆ supportsFeature()

bool xrpl::PeerImp::supportsFeature ( ProtocolFeature f) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 541 of file PeerImp.cpp.

◆ publisherListSequence()

std::optional< std::size_t > xrpl::PeerImp::publisherListSequence ( PublicKey const & pubKey) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 411 of file PeerImp.h.

◆ setPublisherListSequence()

void xrpl::PeerImp::setPublisherListSequence ( PublicKey const & pubKey,
std::size_t const seq )
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 422 of file PeerImp.h.

◆ getClosedLedgerHash()

UInt256 xrpl::PeerImp::getClosedLedgerHash ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 434 of file PeerImp.h.

◆ hasLedger()

bool xrpl::PeerImp::hasLedger ( UInt256 const & hash,
std::uint32_t seq ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 556 of file PeerImp.cpp.

◆ ledgerRange()

void xrpl::PeerImp::ledgerRange ( std::uint32_t & minSeq,
std::uint32_t & maxSeq ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 570 of file PeerImp.cpp.

◆ hasTxSet()

bool xrpl::PeerImp::hasTxSet ( UInt256 const & hash) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 579 of file PeerImp.cpp.

◆ cycleStatus()

void xrpl::PeerImp::cycleStatus ( )
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 586 of file PeerImp.cpp.

◆ hasRange()

bool xrpl::PeerImp::hasRange ( std::uint32_t uMin,
std::uint32_t uMax )
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 596 of file PeerImp.cpp.

◆ getScore()

int xrpl::PeerImp::getScore ( bool haveItem) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 3699 of file PeerImp.cpp.

◆ isHighLatency()

bool xrpl::PeerImp::isHighLatency ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 3741 of file PeerImp.cpp.

◆ fail() [1/2]

void xrpl::PeerImp::fail ( std::string const & reason)
inherited

Definition at line 622 of file PeerImp.cpp.

◆ fail() [2/2]

void xrpl::PeerImp::fail ( std::string const & name,
ErrorCode ec )
privateinherited

Definition at line 635 of file PeerImp.cpp.

◆ compressionEnabled()

bool xrpl::PeerImp::compressionEnabled ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 466 of file PeerImp.h.

◆ maxManifestsMessageSize()

std::size_t xrpl::PeerImp::maxManifestsMessageSize ( ) const
nodiscardinherited

Largest TMManifests message this node accepts, in bytes.

Read by invokeProtocolMessage to drop oversized messages before parsing. Not part of the Peer interface: the message handler is a template parameter, so only PeerImp needs to provide this.

Definition at line 479 of file PeerImp.h.

◆ txReduceRelayEnabled()

bool xrpl::PeerImp::txReduceRelayEnabled ( ) const
overridevirtualinherited

Implements xrpl::Peer.

Definition at line 487 of file PeerImp.h.

◆ close()

void xrpl::PeerImp::close ( )
privateinherited

Definition at line 605 of file PeerImp.cpp.

◆ gracefulClose()

void xrpl::PeerImp::gracefulClose ( )
privateinherited

Definition at line 647 of file PeerImp.cpp.

◆ setTimer()

void xrpl::PeerImp::setTimer ( )
privateinherited

Definition at line 662 of file PeerImp.cpp.

◆ cancelTimer()

void xrpl::PeerImp::cancelTimer ( )
privatenoexceptinherited

Definition at line 679 of file PeerImp.cpp.

◆ makePrefix()

std::string xrpl::PeerImp::makePrefix ( std::string const & fingerprint)
staticprivateinherited

Definition at line 694 of file PeerImp.cpp.

◆ onTimer()

void xrpl::PeerImp::onTimer ( boost::system::error_code const & ec)
privateinherited

Definition at line 702 of file PeerImp.cpp.

◆ onShutdown()

void xrpl::PeerImp::onShutdown ( ErrorCode ec)
privateinherited

Definition at line 762 of file PeerImp.cpp.

◆ doAccept()

void xrpl::PeerImp::doAccept ( )
privateinherited

Definition at line 788 of file PeerImp.cpp.

◆ name()

std::string xrpl::PeerImp::name ( ) const
privateinherited

Definition at line 862 of file PeerImp.cpp.

◆ domain()

std::string xrpl::PeerImp::domain ( ) const
privateinherited

Definition at line 869 of file PeerImp.cpp.

◆ doProtocolStart()

void xrpl::PeerImp::doProtocolStart ( )
privateinherited

Definition at line 879 of file PeerImp.cpp.

◆ onReadMessage()

void xrpl::PeerImp::onReadMessage ( ErrorCode ec,
std::size_t bytesTransferred )
privateinherited

Definition at line 917 of file PeerImp.cpp.

◆ onWriteMessage()

void xrpl::PeerImp::onWriteMessage ( ErrorCode ec,
std::size_t bytesTransferred )
privateinherited

Definition at line 989 of file PeerImp.cpp.

◆ handleTransaction()

void xrpl::PeerImp::handleTransaction ( std::shared_ptr< protocol::TMTransaction > const & m,
bool eraseTxQueue,
bool batch )
privateinherited

Called from onMessage(TMTransaction(s)).

Parameters
mTransaction protocol message
eraseTxQueueis true when called from onMessage(TMTransaction) and is false when called from onMessage(TMTransactions). If true then the transaction hash is erased from txQueue_. Don't need to erase from the queue when called from onMessage(TMTransactions) because this message is a response to the missing transactions request and the queue would not have any of these transactions.
batchis false when called from onMessage(TMTransaction) and is true when called from onMessage(TMTransactions). If true, then the transaction is part of a batch, and should not be charged an extra fee.

Definition at line 1293 of file PeerImp.cpp.

◆ handleHaveTransactions()

void xrpl::PeerImp::handleHaveTransactions ( std::shared_ptr< protocol::TMHaveTransactions > const & m)
privateinherited

Handle protocol message with hashes of transactions that have not been relayed by an upstream node down to its peers - request transactions, which have not been relayed to this peer.

Parameters
mprotocol message with transactions' hashes

Definition at line 2811 of file PeerImp.cpp.

◆ fingerprint()

std::string const & xrpl::PeerImp::fingerprint ( ) const
overrideprivatevirtualinherited

Implements xrpl::Peer.

Definition at line 573 of file PeerImp.h.

◆ prefix()

std::string const & xrpl::PeerImp::prefix ( ) const
privateinherited

Definition at line 579 of file PeerImp.h.

◆ onMessageUnknown()

void xrpl::PeerImp::onMessageUnknown ( std::uint16_t type)
inherited

Definition at line 1041 of file PeerImp.cpp.

◆ onMessageBegin()

void xrpl::PeerImp::onMessageBegin ( std::uint16_t type,
std::shared_ptr<::google::protobuf::Message > const & m,
std::size_t size,
std::size_t uncompressedSize,
bool isCompressed )
inherited

Definition at line 1047 of file PeerImp.cpp.

◆ onMessageEnd()

void xrpl::PeerImp::onMessageEnd ( std::uint16_t type,
std::shared_ptr<::google::protobuf::Message > const & m )
inherited

Definition at line 1088 of file PeerImp.cpp.

◆ onMessage() [1/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMManifests > const & m)
inherited

Definition at line 1095 of file PeerImp.cpp.

◆ onMessage() [2/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMPing > const & m)
inherited

Definition at line 1117 of file PeerImp.cpp.

◆ onMessage() [3/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMCluster > const & m)
inherited

Definition at line 1161 of file PeerImp.cpp.

◆ onMessage() [4/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMEndpoints > const & m)
inherited

Definition at line 1230 of file PeerImp.cpp.

◆ onMessage() [5/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMTransaction > const & m)
inherited

Definition at line 1287 of file PeerImp.cpp.

◆ onMessage() [6/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMGetLedger > const & m)
inherited

Definition at line 1427 of file PeerImp.cpp.

◆ onMessage() [7/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMLedgerData > const & m)
inherited

Definition at line 1697 of file PeerImp.cpp.

◆ onMessage() [8/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMProposeSet > const & m)
inherited

Definition at line 1899 of file PeerImp.cpp.

◆ onMessage() [9/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMStatusChange > const & m)
inherited

Definition at line 2004 of file PeerImp.cpp.

◆ onMessage() [10/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMHaveTransactionSet > const & m)
inherited

Definition at line 2217 of file PeerImp.cpp.

◆ onMessage() [11/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMValidatorListCollection > const & m)
inherited

Definition at line 2438 of file PeerImp.cpp.

◆ onMessage() [12/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMValidation > const & m)
inherited

Definition at line 2463 of file PeerImp.cpp.

◆ onMessage() [13/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMGetObjectByHash > const & m)
inherited

Definition at line 2579 of file PeerImp.cpp.

◆ onMessage() [14/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMHaveTransactions > const & m)
inherited

Definition at line 2794 of file PeerImp.cpp.

◆ onMessage() [15/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMTransactions > const & m)
inherited

Definition at line 2857 of file PeerImp.cpp.

◆ onMessage() [16/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMSquelch > const & m)
inherited

Definition at line 2888 of file PeerImp.cpp.

◆ onMessage() [17/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMProofPathRequest > const & m)
inherited

Definition at line 1583 of file PeerImp.cpp.

◆ onMessage() [18/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMProofPathResponse > const & m)
inherited

Definition at line 1618 of file PeerImp.cpp.

◆ onMessage() [19/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMReplayDeltaRequest > const & m)
inherited

Definition at line 1640 of file PeerImp.cpp.

◆ onMessage() [20/20]

void xrpl::PeerImp::onMessage ( std::shared_ptr< protocol::TMReplayDeltaResponse > const & m)
inherited

Definition at line 1675 of file PeerImp.cpp.

◆ addLedger()

void xrpl::PeerImp::addLedger ( UInt256 const & hash,
std::scoped_lock< std::mutex > const & lockedRecentLock )
privateinherited

Definition at line 2931 of file PeerImp.cpp.

◆ doFetchPack()

void xrpl::PeerImp::doFetchPack ( std::shared_ptr< protocol::TMGetObjectByHash > const & packet)
privateinherited

Definition at line 2944 of file PeerImp.cpp.

◆ onValidatorListMessage()

void xrpl::PeerImp::onValidatorListMessage ( std::string const & messageType,
std::string const & manifest,
std::uint32_t version,
std::vector< ValidatorBlobInfo > const & blobs )
privateinherited

Definition at line 2242 of file PeerImp.cpp.

◆ doTransactions()

void xrpl::PeerImp::doTransactions ( std::shared_ptr< protocol::TMGetObjectByHash > const & packet)
privateinherited

Process peer's request to send missing transactions.

The request is sent in response to TMHaveTransactions.

Parameters
packetprotocol message containing missing transactions' hashes.

Definition at line 2977 of file PeerImp.cpp.

◆ checkTransaction()

void xrpl::PeerImp::checkTransaction ( HashRouterFlags flags,
bool checkSignature,
std::shared_ptr< STTx const > const & stx,
bool batch )
privateinherited

Definition at line 3029 of file PeerImp.cpp.

◆ checkPropose()

void xrpl::PeerImp::checkPropose ( bool isTrusted,
std::shared_ptr< protocol::TMProposeSet > const & packet,
RCLCxPeerPos peerPos )
privateinherited

Definition at line 3174 of file PeerImp.cpp.

◆ checkValidation()

void xrpl::PeerImp::checkValidation ( std::shared_ptr< STValidation > const & val,
UInt256 const & key,
std::shared_ptr< protocol::TMValidation > const & packet )
privateinherited

Definition at line 3222 of file PeerImp.cpp.

◆ sendLedgerBase()

void xrpl::PeerImp::sendLedgerBase ( std::shared_ptr< Ledger const > const & ledger,
protocol::TMLedgerData & ledgerData )
privateinherited

Definition at line 3313 of file PeerImp.cpp.

◆ getLedger()

std::shared_ptr< Ledger const > xrpl::PeerImp::getLedger ( std::shared_ptr< protocol::TMGetLedger > const & m)
privateinherited

Definition at line 3350 of file PeerImp.cpp.

◆ getTxSet()

std::shared_ptr< SHAMap const > xrpl::PeerImp::getTxSet ( std::shared_ptr< protocol::TMGetLedger > const & m) const
privateinherited

Definition at line 3434 of file PeerImp.cpp.

◆ processLedgerRequest()

void xrpl::PeerImp::processLedgerRequest ( std::shared_ptr< protocol::TMGetLedger > const & m,
std::vector< SHAMapNodeID > nodeIDs )
protectedinherited

Definition at line 3466 of file PeerImp.cpp.

◆ processGetObjectByHash()

void xrpl::PeerImp::processGetObjectByHash ( std::shared_ptr< protocol::TMGetObjectByHash > const & m)
protectedinherited

Process a generic-query TMGetObjectByHash message.

Dispatched from onMessage(TMGetObjectByHash) to the JobQueue (JtLedgerReq) so synchronous NodeStore lookups do not block the peer's I/O strand. Caps iteration at tuning::kHardMaxReplyNodes regardless of hit/miss outcome and applies differential pricing via computeGetObjectByHashFee() after the fetch loop completes.

Parameters
mThe protocol message containing requested object hashes.

Definition at line 2731 of file PeerImp.cpp.

◆ computeGetObjectByHashFee()

resource::Charge xrpl::PeerImp::computeGetObjectByHashFee ( int const requested,
int const found )
staticprotectedinherited

Compute the per-message resource charge for a TMGetObjectByHash request based on how much work was actually performed.

The charge has three components on top of the base resource::kFeeModerateBurdenPeer:

  • per-hit lookup cost (cheap; usually served from cache)
  • per-miss lookup cost (expensive node store seeks)
  • request-size band surcharge (escalates abusive batch sizes)

The first tuning::kFreeObjectsPerRequest objects are free so that legitimate InboundLedger::getNeededHashes() traffic (at most 8 objects) is unaffected.

Parameters
requestedNumber of objects requested by the message. This value is used for request-size pricing and may exceed tuning::kHardMaxReplyNodes when this helper is called directly, even though processing caps the iterations to tuning::kHardMaxReplyNodes.
foundNumber of objects successfully returned in the reply.
Returns
A resource::Charge whose cost reflects the work performed.

Definition at line 3673 of file PeerImp.cpp.

◆ currentFeeCharge()

resource::Charge xrpl::PeerImp::currentFeeCharge ( ) const
protectedinherited

Read-only accessor for the accumulated peer-message charge.

Exposed at protected scope so test subclasses can verify the oversized-request rejection path (Layer 1) without invoking the full JobQueue handler. Production callers should never read this back — the value is consumed by charge()/disconnect() internally.

Returns
The current resource::Charge accumulated on fee_.

Definition at line 756 of file PeerImp.h.

Member Data Documentation

◆ sent_

std::vector<std::shared_ptr<Message> > xrpl::test::CapturePeer::sent_
private

Definition at line 141 of file CapturePeer.h.

◆ app_

Application& xrpl::PeerImp::app_
privateinherited

Definition at line 85 of file PeerImp.h.

◆ id_

ID const xrpl::PeerImp::id_
privateinherited

Definition at line 86 of file PeerImp.h.

◆ fingerprint_

std::string xrpl::PeerImp::fingerprint_
privateinherited

Definition at line 87 of file PeerImp.h.

◆ prefix_

std::string xrpl::PeerImp::prefix_
privateinherited

Definition at line 88 of file PeerImp.h.

◆ sink_

beast::WrappedSink xrpl::PeerImp::sink_
privateinherited

Definition at line 89 of file PeerImp.h.

◆ pSink_

beast::WrappedSink xrpl::PeerImp::pSink_
privateinherited

Definition at line 90 of file PeerImp.h.

◆ journal_

beast::Journal const xrpl::PeerImp::journal_
privateinherited

Definition at line 91 of file PeerImp.h.

◆ pJournal_

beast::Journal const xrpl::PeerImp::pJournal_
privateinherited

Definition at line 92 of file PeerImp.h.

◆ streamPtr_

std::unique_ptr<StreamType> xrpl::PeerImp::streamPtr_
privateinherited

Definition at line 93 of file PeerImp.h.

◆ socket_

SocketType& xrpl::PeerImp::socket_
privateinherited

Definition at line 94 of file PeerImp.h.

◆ stream_

StreamType& xrpl::PeerImp::stream_
privateinherited

Definition at line 95 of file PeerImp.h.

◆ strand_

boost::asio::strand<boost::asio::executor> xrpl::PeerImp::strand_
privateinherited

Definition at line 96 of file PeerImp.h.

◆ timer_

WaitableTimer xrpl::PeerImp::timer_
privateinherited

Definition at line 97 of file PeerImp.h.

◆ remoteAddress_

beast::ip::Endpoint const xrpl::PeerImp::remoteAddress_
privateinherited

Definition at line 101 of file PeerImp.h.

◆ overlay_

OverlayImpl& xrpl::PeerImp::overlay_
privateinherited

Definition at line 105 of file PeerImp.h.

◆ inbound_

bool const xrpl::PeerImp::inbound_
privateinherited

Definition at line 106 of file PeerImp.h.

◆ protocol_

ProtocolVersion xrpl::PeerImp::protocol_
privateinherited

Definition at line 109 of file PeerImp.h.

◆ tracking_

std::atomic<Tracking> xrpl::PeerImp::tracking_
privateinherited

Definition at line 111 of file PeerImp.h.

◆ trackingTime_

ClockType::time_point xrpl::PeerImp::trackingTime_
privateinherited

Definition at line 112 of file PeerImp.h.

◆ detaching_

bool xrpl::PeerImp::detaching_ = false
privateinherited

Definition at line 113 of file PeerImp.h.

◆ publicKey_

PublicKey const xrpl::PeerImp::publicKey_
privateinherited

Definition at line 115 of file PeerImp.h.

◆ name_

std::string xrpl::PeerImp::name_
privateinherited

Definition at line 116 of file PeerImp.h.

◆ nameMutex_

std::shared_mutex xrpl::PeerImp::nameMutex_
mutableprivateinherited

Definition at line 117 of file PeerImp.h.

◆ minLedger_

LedgerIndex xrpl::PeerImp::minLedger_ = 0
privateinherited

Definition at line 121 of file PeerImp.h.

◆ maxLedger_

LedgerIndex xrpl::PeerImp::maxLedger_ = 0
privateinherited

Definition at line 122 of file PeerImp.h.

◆ closedLedgerHash_

UInt256 xrpl::PeerImp::closedLedgerHash_
privateinherited

Definition at line 123 of file PeerImp.h.

◆ previousLedgerHash_

UInt256 xrpl::PeerImp::previousLedgerHash_
privateinherited

Definition at line 124 of file PeerImp.h.

◆ recentLedgers_

boost::circular_buffer<UInt256> xrpl::PeerImp::recentLedgers_ {128}
privateinherited

Definition at line 126 of file PeerImp.h.

◆ recentTxSets_

boost::circular_buffer<UInt256> xrpl::PeerImp::recentTxSets_ {128}
privateinherited

Definition at line 127 of file PeerImp.h.

◆ latency_

std::optional<std::chrono::milliseconds> xrpl::PeerImp::latency_
privateinherited

Definition at line 129 of file PeerImp.h.

◆ lastPingSeq_

std::optional<std::uint32_t> xrpl::PeerImp::lastPingSeq_
privateinherited

Definition at line 130 of file PeerImp.h.

◆ lastPingTime_

ClockType::time_point xrpl::PeerImp::lastPingTime_
privateinherited

Definition at line 131 of file PeerImp.h.

◆ creationTime_

ClockType::time_point const xrpl::PeerImp::creationTime_
privateinherited

Definition at line 132 of file PeerImp.h.

◆ squelch_

reduce_relay::Squelch<UptimeClock> xrpl::PeerImp::squelch_
privateinherited

Definition at line 134 of file PeerImp.h.

◆ recentLock_

std::mutex xrpl::PeerImp::recentLock_
mutableprivateinherited

Definition at line 181 of file PeerImp.h.

◆ lastStatus_

protocol::TMStatusChange xrpl::PeerImp::lastStatus_
privateinherited

Definition at line 182 of file PeerImp.h.

◆ usage_

resource::Consumer xrpl::PeerImp::usage_
privateinherited

Definition at line 183 of file PeerImp.h.

◆ fee_

ChargeWithContext xrpl::PeerImp::fee_
privateinherited

Definition at line 184 of file PeerImp.h.

◆ chargeDisconnectFired_

std::atomic<bool> xrpl::PeerImp::chargeDisconnectFired_ {false}
privateinherited

Definition at line 190 of file PeerImp.h.

◆ slot_

std::shared_ptr<peer_finder::Slot> const xrpl::PeerImp::slot_
privateinherited

Definition at line 191 of file PeerImp.h.

◆ readBuffer_

boost::beast::multi_buffer xrpl::PeerImp::readBuffer_
privateinherited

Definition at line 192 of file PeerImp.h.

◆ request_

HttpRequestType xrpl::PeerImp::request_
privateinherited

Definition at line 193 of file PeerImp.h.

◆ response_

HttpResponseType xrpl::PeerImp::response_
privateinherited

Definition at line 194 of file PeerImp.h.

◆ headers_

boost::beast::http::fields const& xrpl::PeerImp::headers_
privateinherited

Definition at line 195 of file PeerImp.h.

◆ sendQueue_

std::queue<std::shared_ptr<Message> > xrpl::PeerImp::sendQueue_
privateinherited

Definition at line 196 of file PeerImp.h.

◆ gracefulClose_

bool xrpl::PeerImp::gracefulClose_ = false
privateinherited

Definition at line 197 of file PeerImp.h.

◆ largeSendq_

int xrpl::PeerImp::largeSendq_ = 0
privateinherited

Definition at line 198 of file PeerImp.h.

◆ loadEvent_

std::unique_ptr<LoadEvent> xrpl::PeerImp::loadEvent_
privateinherited

Definition at line 199 of file PeerImp.h.

◆ publisherListSequences_

HashMap<PublicKey, std::size_t> xrpl::PeerImp::publisherListSequences_
privateinherited

Definition at line 202 of file PeerImp.h.

◆ compressionEnabled_

Compressed xrpl::PeerImp::compressionEnabled_ = Compressed::Off
privateinherited

Definition at line 204 of file PeerImp.h.

◆ txQueue_

HashSet<UInt256> xrpl::PeerImp::txQueue_
privateinherited

Definition at line 209 of file PeerImp.h.

◆ txReduceRelayEnabled_

bool xrpl::PeerImp::txReduceRelayEnabled_ = false
privateinherited

Definition at line 211 of file PeerImp.h.

◆ ledgerReplayEnabled_

bool xrpl::PeerImp::ledgerReplayEnabled_ = false
privateinherited

Definition at line 213 of file PeerImp.h.

◆ ledgerReplayMsgHandler_

LedgerReplayMsgHandler xrpl::PeerImp::ledgerReplayMsgHandler_
privateinherited

Definition at line 214 of file PeerImp.h.

◆ sent

Metrics xrpl::PeerImp::sent
inherited

Definition at line 247 of file PeerImp.h.

◆ recv

Metrics xrpl::PeerImp::recv
inherited

Definition at line 248 of file PeerImp.h.

◆ [struct]

struct { ... } xrpl::PeerImp::metrics_