20#ifndef RIPPLE_OVERLAY_PEERIMP_H_INCLUDED
21#define RIPPLE_OVERLAY_PEERIMP_H_INCLUDED
23#include <xrpld/app/consensus/RCLCxPeerPos.h>
24#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
25#include <xrpld/app/misc/HashRouter.h>
26#include <xrpld/overlay/Squelch.h>
27#include <xrpld/overlay/detail/OverlayImpl.h>
28#include <xrpld/overlay/detail/ProtocolVersion.h>
29#include <xrpld/peerfinder/PeerfinderManager.h>
31#include <xrpl/basics/Log.h>
32#include <xrpl/basics/UnorderedContainers.h>
33#include <xrpl/beast/utility/WrappedSink.h>
34#include <xrpl/protocol/Protocol.h>
35#include <xrpl/protocol/STTx.h>
36#include <xrpl/protocol/STValidation.h>
37#include <xrpl/resource/Fees.h>
39#include <boost/circular_buffer.hpp>
40#include <boost/endian/conversion.hpp>
41#include <boost/thread/shared_mutex.hpp>
49struct ValidatorBlobInfo;
69 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
81 boost::asio::strand<boost::asio::executor>
strand_;
158 "ripple::PeerImp::ChargeWithContext::update : fee increases");
251 template <
class Buffers>
255 Buffers
const& buffers,
423 getScore(
bool haveItem)
const override;
464 onTimer(boost::system::error_code
const& ec);
636 protocol::TMLedgerData& ledgerData);
650template <
class Buffers>
654 Buffers
const& buffers,
665 , sink_(app_.journal(
"Peer"), makePrefix(id))
666 , p_sink_(app_.journal(
"Protocol"), makePrefix(id))
668 , p_journal_(p_sink_)
669 , stream_ptr_(
std::move(stream_ptr))
670 , socket_(stream_ptr_->next_layer().socket())
671 , stream_(*stream_ptr_)
672 , strand_(socket_.get_executor())
674 , remote_address_(slot->remote_endpoint())
680 , publicKey_(publicKey)
683 , squelch_(app_.journal(
"Squelch"))
685 , fee_{Resource::feeTrivialPeer}
686 , slot_(
std::move(slot))
687 , response_(
std::move(response))
688 , headers_(response_)
689 , compressionEnabled_(
694 app_.config().COMPRESSION)
700 app_.config().TX_REDUCE_RELAY_ENABLE))
704 app_.config().LEDGER_REPLAY))
705 , ledgerReplayMsgHandler_(app, app.getLedgerReplayer())
708 read_buffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
711 <<
" vp reduce-relay base squelch enabled "
720template <
class FwdIt,
class>
724 protocol::TMEndpoints tm;
726 while (first != last)
728 auto& tme2(*tm.add_endpoints_v2());
729 tme2.set_endpoint(first->address.to_string());
730 tme2.set_hops(first->hops);
735 send(std::make_shared<Message>(tm, protocol::mtENDPOINTS));
A version-independent IP address and port combination.
A generic endpoint for log messages.
Wraps a Journal::Sink to prefix its output with a string.
virtual Config & config()=0
bool VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE
boost::circular_buffer< std::uint64_t > rollingAvg_
std::uint64_t accumBytes_
Metrics & operator=(Metrics const &)=delete
Metrics(Metrics &&)=delete
std::uint64_t total_bytes() const
std::uint64_t totalBytes_
Metrics & operator=(Metrics &&)=delete
std::uint64_t average_bytes() const
void add_message(std::uint64_t bytes)
Metrics(Metrics const &)=delete
std::uint64_t rollingAvgBytes_
clock_type::time_point intervalStart_
std::queue< std::shared_ptr< Message > > send_queue_
boost::beast::ssl_stream< middle_type > stream_type
PeerImp & operator=(PeerImp const &)=delete
std::unique_ptr< LoadEvent > load_event_
boost::beast::http::fields const & headers_
void onValidatorListMessage(std::string const &messageType, std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs)
void onMessageEnd(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m)
bool hasLedger(uint256 const &hash, std::uint32_t seq) const override
clock_type::duration uptime() const
void removeTxQueue(uint256 const &hash) override
Remove transaction's hash from the transactions' hashes queue.
protocol::TMStatusChange last_status_
boost::circular_buffer< uint256 > recentTxSets_
std::unique_ptr< stream_type > stream_ptr_
void onMessage(std::shared_ptr< protocol::TMManifests > const &m)
Tracking
Whether the peer's view of the ledger converges or diverges from ours.
Compressed compressionEnabled_
std::optional< std::size_t > publisherListSequence(PublicKey const &pubKey) const override
uint256 closedLedgerHash_
std::string domain() const
std::optional< std::uint32_t > lastPingSeq_
std::shared_ptr< PeerFinder::Slot > const & slot()
void onTimer(boost::system::error_code const &ec)
http_response_type response_
void sendEndpoints(FwdIt first, FwdIt last)
Send a set of PeerFinder endpoints as a protocol message.
void sendLedgerBase(std::shared_ptr< Ledger const > const &ledger, protocol::TMLedgerData &ledgerData)
void doFetchPack(std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
boost::asio::ip::tcp::endpoint endpoint_type
beast::Journal const journal_
boost::asio::ip::address address_type
struct ripple::PeerImp::@21 metrics_
beast::Journal const p_journal_
PeerImp(PeerImp const &)=delete
void processLedgerRequest(std::shared_ptr< protocol::TMGetLedger > const &m)
std::shared_ptr< SHAMap const > getTxSet(std::shared_ptr< protocol::TMGetLedger > const &m) const
void checkTransaction(HashRouterFlags flags, bool checkSignature, std::shared_ptr< STTx const > const &stx, bool batch)
bool hasRange(std::uint32_t uMin, std::uint32_t uMax) override
bool hasTxSet(uint256 const &hash) const override
clock_type::time_point lastPingTime_
void onMessageUnknown(std::uint16_t type)
std::shared_ptr< PeerFinder::Slot > const slot_
std::shared_mutex nameMutex_
boost::circular_buffer< uint256 > recentLedgers_
std::optional< std::chrono::milliseconds > latency_
void handleTransaction(std::shared_ptr< protocol::TMTransaction > const &m, bool eraseTxQueue, bool batch)
Called from onMessage(TMTransaction(s)).
beast::IP::Endpoint const remote_address_
boost::asio::ip::tcp::socket socket_type
Json::Value json() override
PublicKey const publicKey_
void addLedger(uint256 const &hash, std::lock_guard< std::mutex > const &lockedRecentLock)
hash_set< uint256 > txQueue_
std::shared_ptr< Ledger const > getLedger(std::shared_ptr< protocol::TMGetLedger > const &m)
void onMessageBegin(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m, std::size_t size, std::size_t uncompressed_size, bool isCompressed)
bool txReduceRelayEnabled_
beast::IP::Endpoint getRemoteAddress() const override
clock_type::time_point trackingTime_
ProtocolVersion protocol_
clock_type::time_point const creationTime_
reduce_relay::Squelch< UptimeClock > squelch_
hash_map< PublicKey, std::size_t > publisherListSequences_
std::string getVersion() const
Return the version of rippled that the peer is running, if reported.
uint256 previousLedgerHash_
void charge(Resource::Charge const &fee, std::string const &context) override
Adjust this peer's load balance based on the type of load imposed.
boost::beast::tcp_stream middle_type
int getScore(bool haveItem) const override
void send(std::shared_ptr< Message > const &m) override
void doTransactions(std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
Process peer's request to send missing transactions.
static std::string makePrefix(id_t id)
boost::system::error_code error_code
void onReadMessage(error_code ec, std::size_t bytes_transferred)
bool ledgerReplayEnabled_
beast::WrappedSink p_sink_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > waitable_timer
PublicKey const & getNodePublic() const override
bool crawl() const
Returns true if this connection will publicly share its IP address.
beast::Journal const & pjournal() const
void sendTxQueue() override
Send aggregated transactions' hashes.
bool compressionEnabled() const override
bool txReduceRelayEnabled() const override
bool supportsFeature(ProtocolFeature f) const override
uint256 const & getClosedLedgerHash() const override
void onWriteMessage(error_code ec, std::size_t bytes_transferred)
http_request_type request_
Peer::id_t id() const override
LedgerReplayMsgHandler ledgerReplayMsgHandler_
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 do...
void addTxQueue(uint256 const &hash) override
Add transaction's hash to the transactions' hashes queue.
bool cluster() const override
Returns true if this connection is a member of the cluster.
void checkPropose(bool isTrusted, std::shared_ptr< protocol::TMProposeSet > const &packet, RCLCxPeerPos peerPos)
bool isHighLatency() const override
void checkTracking(std::uint32_t validationSeq)
Check if the peer is tracking.
void onShutdown(error_code ec)
boost::asio::strand< boost::asio::executor > strand_
void cycleStatus() override
boost::beast::multi_buffer read_buffer_
Resource::Consumer usage_
void checkValidation(std::shared_ptr< STValidation > const &val, uint256 const &key, std::shared_ptr< protocol::TMValidation > const &packet)
void setPublisherListSequence(PublicKey const &pubKey, std::size_t const seq) override
void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
void fail(std::string const &reason)
std::atomic< Tracking > tracking_
Represents a peer connection in the overlay.
std::uint32_t id_t
Uniquely identifies a peer.
A peer's signed, proposed position for use in RCLConsensus.
An endpoint that consumes resources.
Maintains squelching of relaying messages from validators.
Charge const feeTrivialPeer
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_type
static constexpr char FEATURE_COMPR[]
static constexpr char FEATURE_LEDGER_REPLAY[]
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
bool peerFeatureEnabled(headers const &request, std::string const &feature, std::string value, bool config)
Check if a feature should be enabled for a peer.
static constexpr char FEATURE_TXRR[]
static constexpr char FEATURE_VPRR[]
Describes a connectible peer address along with some metadata.
void update(Resource::Charge f, std::string const &add)