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