20 #ifndef RIPPLE_OVERLAY_PEERIMP_H_INCLUDED
21 #define RIPPLE_OVERLAY_PEERIMP_H_INCLUDED
23 #include <ripple/app/consensus/RCLCxPeerPos.h>
24 #include <ripple/basics/Log.h>
25 #include <ripple/basics/RangeSet.h>
26 #include <ripple/beast/utility/WrappedSink.h>
27 #include <ripple/overlay/Squelch.h>
28 #include <ripple/overlay/impl/OverlayImpl.h>
29 #include <ripple/overlay/impl/ProtocolMessage.h>
30 #include <ripple/overlay/impl/ProtocolVersion.h>
31 #include <ripple/peerfinder/PeerfinderManager.h>
32 #include <ripple/protocol/Protocol.h>
33 #include <ripple/protocol/STTx.h>
34 #include <ripple/protocol/STValidation.h>
35 #include <ripple/resource/Fees.h>
37 #include <boost/circular_buffer.hpp>
38 #include <boost/endian/conversion.hpp>
39 #include <boost/optional.hpp>
40 #include <boost/thread/shared_mutex.hpp>
46 struct ValidatorBlobInfo;
71 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
83 boost::asio::strand<boost::asio::executor>
strand_;
116 boost::optional<std::chrono::milliseconds>
latency_;
231 template <
class Buffers>
235 Buffers
const& buffers,
340 boost::optional<std::size_t>
390 getScore(
bool haveItem)
const override;
399 boost::optional<RangeSet<std::uint32_t>>
403 boost::optional<hash_map<PublicKey, ShardInfo>>
433 onTimer(boost::system::error_code
const& ec);
576 template <
class Buffers>
580 Buffers
const& buffers,
591 , sink_(app_.journal(
"Peer"), makePrefix(id))
592 , p_sink_(app_.journal(
"Protocol"), makePrefix(id))
594 , p_journal_(p_sink_)
595 , stream_ptr_(
std::move(stream_ptr))
596 , socket_(stream_ptr_->next_layer().socket())
597 , stream_(*stream_ptr_)
598 , strand_(socket_.get_executor())
600 , remote_address_(slot->remote_endpoint())
604 , tracking_(Tracking::unknown)
605 , trackingTime_(clock_type::now())
606 , publicKey_(publicKey)
607 , lastPingTime_(clock_type::now())
608 , creationTime_(clock_type::now())
609 , squelch_(app_.journal(
"Squelch"))
612 , slot_(std::move(slot))
613 , response_(std::move(response))
614 , headers_(response_)
615 , compressionEnabled_(
620 app_.config().COMPRESSION)
626 app_.config().VP_REDUCE_RELAY_ENABLE))
628 read_buffer_.commit(boost::asio::buffer_copy(
629 read_buffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
630 JLOG(journal_.debug()) <<
"compression enabled "
631 << (compressionEnabled_ == Compressed::On)
632 <<
" vp reduce-relay enabled "
633 << vpReduceRelayEnabled_ <<
" on " << remote_address_
637 template <
class FwdIt,
class>
641 protocol::TMEndpoints tm;
643 while (first != last)
645 auto& tme2(*tm.add_endpoints_v2());
646 tme2.set_endpoint(first->address.to_string());
647 tme2.set_hops(first->hops);
652 send(std::make_shared<Message>(tm, protocol::mtENDPOINTS));
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 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_
boost::optional< std::size_t > publisherListSequence(PublicKey const &pubKey) const override
http_request_type request_
boost::optional< RangeSet< std::uint32_t > > getShardIndexes() const
Return a range set of known shard indexes from this peer.
std::uint32_t id_t
Uniquely identifies a peer.
int getScore(bool haveItem) const override
boost::circular_buffer< uint256 > recentTxSets_
void checkValidation(std::shared_ptr< STValidation > const &val, std::shared_ptr< protocol::TMValidation > const &packet)
void checkPropose(Job &job, std::shared_ptr< protocol::TMProposeSet > const &packet, RCLCxPeerPos peerPos)
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
void getLedger(std::shared_ptr< protocol::TMGetLedger > const &packet)
beast::IP::Endpoint endpoint
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)
boost::asio::ip::tcp::socket socket_type
uint256 previousLedgerHash_
static constexpr char FEATURE_VPRR[]
std::uint64_t rollingAvgBytes_
clock_type::time_point intervalStart_
const PublicKey publicKey_
boost::beast::multi_buffer read_buffer_
boost::system::error_code error_code
const beast::IP::Endpoint remote_address_
std::optional< std::uint32_t > networkID() const
Maintains squelching of relaying messages from validators.
std::uint64_t totalBytes_
void addLedger(uint256 const &hash, std::lock_guard< std::mutex > const &lockedRecentLock)
hash_map< PublicKey, ShardInfo > shardInfo_
uint256 closedLedgerHash_
boost::optional< std::uint32_t > lastPingSeq_
void onMessageEnd(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m)
PublicKey const & getNodePublic() const override
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[]
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_
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_
boost::optional< std::chrono::milliseconds > latency_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
boost::asio::ip::tcp::endpoint endpoint_type
reduce_relay::Squelch< UptimeClock > squelch_
bool hasShard(std::uint32_t shardIndex) const override
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
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_
boost::icl::interval_set< T, std::less, ClosedInterval< T > > RangeSet
A set of closed intervals over the domain T.
boost::shared_mutex mutex_
void checkTransaction(int flags, bool checkSignature, std::shared_ptr< STTx const > const &stx)
boost::beast::tcp_stream middle_type
boost::optional< hash_map< PublicKey, ShardInfo > > getPeerShardInfo() const
Return any known shard info from this peer and its sub peers.
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 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.
RangeSet< std::uint32_t > shardIndexes
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)