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>
69 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
81 boost::asio::strand<boost::asio::executor>
strand_;
114 boost::optional<std::chrono::milliseconds>
latency_;
224 template <
class Buffers>
228 Buffers
const& buffers,
333 boost::optional<std::size_t>
383 getScore(
bool haveItem)
const override;
392 boost::optional<RangeSet<std::uint32_t>>
396 boost::optional<hash_map<PublicKey, ShardInfo>>
426 onTimer(boost::system::error_code
const& ec);
553 template <
class Buffers>
557 Buffers
const& buffers,
568 , sink_(app_.journal(
"Peer"), makePrefix(id))
569 , p_sink_(app_.journal(
"Protocol"), makePrefix(id))
571 , p_journal_(p_sink_)
572 , stream_ptr_(
std::move(stream_ptr))
573 , socket_(stream_ptr_->next_layer().socket())
574 , stream_(*stream_ptr_)
575 , strand_(socket_.get_executor())
577 , remote_address_(slot->remote_endpoint())
580 , protocol_(protocol)
581 , tracking_(Tracking::unknown)
582 , trackingTime_(clock_type::now())
583 , publicKey_(publicKey)
584 , lastPingTime_(clock_type::now())
585 , creationTime_(clock_type::now())
588 , slot_(std::move(slot))
589 , response_(std::move(response))
590 , headers_(response_)
591 , compressionEnabled_(
592 headers_[
"X-Offer-Compression"] ==
"lz4" && app_.config().COMPRESSION
596 read_buffer_.commit(boost::asio::buffer_copy(
597 read_buffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
600 template <
class FwdIt,
class>
604 protocol::TMEndpoints tm;
606 while (first != last)
608 auto& tme2(*tm.add_endpoints_v2());
609 tme2.set_endpoint(first->address.to_string());
610 tme2.set_hops(first->hops);
615 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_
void onMessageBegin(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m, std::size_t size)
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.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
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)
squelch::Squelch< UptimeClock > squelch_
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_
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
std::uint64_t totalBytes_
void addLedger(uint256 const &hash, std::lock_guard< std::mutex > const &lockedRecentLock)
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_type
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.
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_
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_
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)
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
Maintains squelching of relaying messages from validators.
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
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::ssl_stream< middle_type > stream_type
std::atomic< Tracking > tracking_
boost::shared_mutex nameMutex_
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 onReadMessage(error_code ec, std::size_t bytes_transferred)