1#ifndef XRPL_OVERLAY_PEERIMP_H_INCLUDED
2#define XRPL_OVERLAY_PEERIMP_H_INCLUDED
4#include <xrpld/app/consensus/RCLCxPeerPos.h>
5#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
6#include <xrpld/app/misc/HashRouter.h>
7#include <xrpld/overlay/Squelch.h>
8#include <xrpld/overlay/detail/OverlayImpl.h>
9#include <xrpld/overlay/detail/ProtocolVersion.h>
10#include <xrpld/peerfinder/PeerfinderManager.h>
12#include <xrpl/basics/Log.h>
13#include <xrpl/basics/UnorderedContainers.h>
14#include <xrpl/beast/utility/WrappedSink.h>
15#include <xrpl/protocol/Protocol.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/STValidation.h>
18#include <xrpl/resource/Fees.h>
20#include <boost/circular_buffer.hpp>
21#include <boost/endian/conversion.hpp>
22#include <boost/thread/shared_mutex.hpp>
31struct ValidatorBlobInfo;
113 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
127 boost::asio::strand<boost::asio::executor>
strand_;
205 "ripple::PeerImp::ChargeWithContext::update : fee increases");
310 template <
class Buffers>
314 Buffers
const& buffers,
482 getScore(
bool haveItem)
const override;
673 std::shared_ptr<
protocol::TMHaveTransactions> const& m);
801 protocol::TMLedgerData& ledgerData);
815template <
class Buffers>
819 Buffers
const& buffers,
832 , prefix_(makePrefix(fingerprint_))
833 , sink_(app_.journal(
"Peer"), prefix_)
834 , p_sink_(app_.journal(
"Protocol"), prefix_)
836 , p_journal_(p_sink_)
837 , stream_ptr_(
std::move(stream_ptr))
838 , socket_(stream_ptr_->next_layer().socket())
839 , stream_(*stream_ptr_)
840 , strand_(
boost::asio::make_strand(socket_.get_executor()))
842 , remote_address_(slot->remote_endpoint())
848 , publicKey_(publicKey)
851 , squelch_(app_.journal(
"Squelch"))
853 , fee_{Resource::feeTrivialPeer}
854 , slot_(
std::move(slot))
855 , response_(
std::move(response))
856 , headers_(response_)
857 , compressionEnabled_(
862 app_.config().COMPRESSION)
868 app_.config().TX_REDUCE_RELAY_ENABLE))
872 app_.config().LEDGER_REPLAY))
873 , ledgerReplayMsgHandler_(app, app.getLedgerReplayer())
876 read_buffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
879 <<
" vp reduce-relay base squelch enabled "
888template <
class FwdIt,
class>
892 protocol::TMEndpoints tm;
894 while (first != last)
896 auto& tme2(*tm.add_endpoints_v2());
897 tme2.set_endpoint(first->address.to_string());
898 tme2.set_hops(first->hops);
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_
This class manages established peer-to-peer connections, handles message exchange,...
std::string const & prefix() const
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()
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)
std::string const & fingerprint() const override
boost::asio::ip::tcp::endpoint endpoint_type
beast::Journal const journal_
boost::asio::ip::address address_type
void tryAsyncShutdown()
Attempts to perform a graceful SSL shutdown if conditions are met.
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 shutdown()
Initiates the peer disconnection sequence.
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)
void close()
Forcibly closes the underlying socket connection.
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
void fail(std::string const &name, error_code ec)
Handles a failure associated with a specific error code.
clock_type::time_point trackingTime_
void cancelTimer() noexcept
Cancels any pending wait on the peer activity timer.
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.
struct ripple::PeerImp::@22 metrics_
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 onTimer(error_code const &ec)
Handles the expiration of the peer activity timer.
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.
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 setTimer(std::chrono::seconds interval)
Sets and starts the peer timer.
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.
static std::string makePrefix(std::string const &fingerprint)
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)
Handles the completion of the asynchronous SSL shutdown.
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
std::atomic< Tracking > tracking_
Represents a peer connection in the overlay.
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
std::string getFingerprint(beast::IP::Endpoint const &address, std::optional< PublicKey > const &publicKey=std::nullopt, std::optional< std::string > const &id=std::nullopt)
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[]
std::string to_string(base_uint< Bits, Tag > const &a)
static constexpr char FEATURE_VPRR[]
Describes a connectible peer address along with some metadata.
void update(Resource::Charge f, std::string const &add)