xrpld
Loading...
Searching...
No Matches
PeerImp.h
1#pragma once
2
3#include <xrpld/app/consensus/RCLCxPeerPos.h>
4#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/overlay/Compression.h>
7#include <xrpld/overlay/Message.h>
8#include <xrpld/overlay/Peer.h>
9#include <xrpld/overlay/Squelch.h>
10#include <xrpld/overlay/detail/OverlayImpl.h>
11#include <xrpld/overlay/detail/ProtocolVersion.h>
12
13#include <xrpl/basics/Log.h>
14#include <xrpl/basics/Number.h>
15#include <xrpl/basics/UnorderedContainers.h>
16#include <xrpl/basics/UptimeClock.h>
17#include <xrpl/basics/base_uint.h>
18#include <xrpl/beast/net/IPEndpoint.h>
19#include <xrpl/beast/utility/Journal.h>
20#include <xrpl/beast/utility/WrappedSink.h>
21#include <xrpl/beast/utility/instrumentation.h>
22#include <xrpl/core/HashRouter.h>
23#include <xrpl/core/LoadEvent.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/peerfinder/Slot.h>
26#include <xrpl/peerfinder/Types.h>
27#include <xrpl/protocol/Protocol.h>
28#include <xrpl/protocol/PublicKey.h>
29#include <xrpl/protocol/STTx.h>
30#include <xrpl/protocol/STValidation.h>
31#include <xrpl/resource/Charge.h>
32#include <xrpl/resource/Consumer.h>
33#include <xrpl/resource/Fees.h>
34#include <xrpl/server/Handoff.h>
35#include <xrpl/server/Manifest.h>
36#include <xrpl/shamap/SHAMapNodeID.h>
37
38#include <boost/circular_buffer.hpp>
39#include <boost/endian/conversion.hpp>
40#include <boost/thread/shared_mutex.hpp>
41
42#include <google/protobuf/message.h>
43
44#include <xrpl.pb.h>
45
46#include <atomic>
47#include <chrono>
48#include <cstddef>
49#include <cstdint>
50#include <iterator>
51#include <memory>
52#include <mutex>
53#include <optional>
54#include <queue>
55#include <shared_mutex>
56#include <string>
57#include <type_traits>
58#include <utility>
59#include <vector>
60
61namespace xrpl {
62
64class SHAMap;
65
66class PeerImp : public Peer, public std::enable_shared_from_this<PeerImp>, public OverlayImpl::Child
67{
68public:
73
74private:
76 using ErrorCode = boost::system::error_code;
77 using SocketType = boost::asio::ip::tcp::socket;
78 using MiddleType = boost::beast::tcp_stream;
79 using StreamType = boost::beast::ssl_stream<MiddleType>;
80 using AddressType = boost::asio::ip::address;
81 using EndpointType = boost::asio::ip::tcp::endpoint;
82 using WaitableTimer = boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
84
86 ID const id_;
96 boost::asio::strand<boost::asio::executor> strand_;
98
99 // Updated at each stage of the connection process to reflect
100 // the current conditions as closely as possible.
102
103 // These are up here to prevent warnings about order of initializations
104 //
106 bool const inbound_;
107
108 // Protocol version to use for this link
110
112 ClockType::time_point trackingTime_;
113 bool detaching_ = false;
114 // Node public key of peer.
118
119 // The indices of the smallest and largest ledgers this peer has available
120 //
125
126 boost::circular_buffer<UInt256> recentLedgers_{128};
127 boost::circular_buffer<UInt256> recentTxSets_{128};
128
131 ClockType::time_point lastPingTime_;
132 ClockType::time_point const creationTime_;
133
135
136 // Notes on thread locking:
137 //
138 // During an audit it was noted that some member variables that looked
139 // like they need thread protection were not receiving it. And, indeed,
140 // that was correct. But the multi-phase initialization of PeerImp
141 // makes such an audit difficult. A further audit suggests that the
142 // locking is now protecting variables that don't need it. We're
143 // leaving that locking in place (for now) as a form of future proofing.
144 //
145 // Here are the variables that appear to need locking currently:
146 //
147 // o closedLedgerHash_
148 // o previousLedgerHash_
149 // o minLedger_
150 // o maxLedger_
151 // o recentLedgers_
152 // o recentTxSets_
153 // o trackingTime_
154 // o latency_
155 //
156 // The following variables are being protected preemptively:
157 //
158 // o name_
159 // o lastStatus_
160 //
161 // June 2019
162
164 {
166 std::string context{}; // NOLINT(readability-redundant-member-init)
167
168 void
170 {
171 XRPL_ASSERT(f >= fee, "xrpl::PeerImp::ChargeWithContext::update : fee increases");
172 fee = f;
173 if (!context.empty())
174 {
175 context += " ";
176 }
177 context += add;
178 }
179 };
180
182 protocol::TMStatusChange lastStatus_;
185
186 // One-shot guard so concurrent JobQueue workers cannot double-count
187 // the per-connection peer-disconnect-by-charge metric (and cannot
188 // post duplicate fail() calls) when several queued requests cross
189 // kDropThreshold before the first fail() lands on the strand.
192 boost::beast::multi_buffer readBuffer_;
195 boost::beast::http::fields const& headers_;
197 bool gracefulClose_ = false;
198 int largeSendq_ = 0;
200 // The highest sequence of each PublisherList that has
201 // been sent to or received from this peer.
203
205
206 // Queue of transactions' hashes that have not been
207 // relayed. The hashes are sent once a second to a peer
208 // and the peer requests missing transactions from the node.
210 // true if tx reduce-relay feature is enabled on the peer.
212
215
216 friend class OverlayImpl;
217
219 {
220 public:
221 Metrics() = default;
222 Metrics(Metrics const&) = delete;
223 Metrics&
224 operator=(Metrics const&) = delete;
225 Metrics(Metrics&&) = delete;
226 Metrics&
227 operator=(Metrics&&) = delete;
228
229 void
232 averageBytes() const;
234 totalBytes() const;
235
236 private:
238 boost::circular_buffer<std::uint64_t> rollingAvg_{30, 0ull};
239 ClockType::time_point intervalStart_{ClockType::now()};
243 };
244
245 struct
246 {
250
251public:
252 PeerImp(PeerImp const&) = delete;
253 PeerImp&
254 operator=(PeerImp const&) = delete;
255
259 PeerImp(
260 Application& app,
261 ID id,
263 HttpRequestType&& request,
264 PublicKey const& publicKey,
266 resource::Consumer consumer,
267 std::unique_ptr<StreamType>&& streamPtr,
268 OverlayImpl& overlay);
269
273 // VFALCO legacyPublicKey should be implied by the Slot
274 template <class Buffers>
275 PeerImp(
276 Application& app,
277 std::unique_ptr<StreamType>&& streamPtr,
278 Buffers const& buffers,
280 HttpResponseType&& response,
281 resource::Consumer usage,
282 PublicKey const& publicKey,
284 ID id,
285 OverlayImpl& overlay);
286
287 ~PeerImp() override;
288
289 beast::Journal const&
290 pJournal() const
291 {
292 return pJournal_;
293 }
294
297 {
298 return slot_;
299 }
300
301 // Work-around for calling shared_from_this in constructors
302 virtual void
303 run();
304
305 // Called when Overlay gets a stop request.
306 void
307 stop() override;
308
309 //
310 // Network
311 //
312
313 void
314 send(std::shared_ptr<Message> const& m) override;
315
319 void
320 sendTxQueue() override;
321
326 void
327 addTxQueue(UInt256 const& hash) override;
328
333 void
334 removeTxQueue(UInt256 const& hash) override;
335
339 template <class FwdIt>
340 void
341 sendEndpoints(FwdIt first, FwdIt last)
342 requires(
346
348 getRemoteAddress() const override
349 {
350 return remoteAddress_;
351 }
352
353 void
354 charge(resource::Charge const& fee, std::string const& context) override;
355
356 //
357 // Identity
358 //
359
361 id() const override
362 {
363 return id_;
364 }
365
369 bool
370 crawl() const;
371
372 bool
373 cluster() const override;
374
379 void
380 checkTracking(std::uint32_t validationSeq);
381
382 void
384
385 PublicKey const&
386 getNodePublic() const override
387 {
388 return publicKey_;
389 }
390
395 getVersion() const;
396
397 // Return the connection elapsed time.
398 ClockType::duration
399 uptime() const
400 {
401 return ClockType::now() - creationTime_;
402 }
403
405 json() override;
406
407 bool
408 supportsFeature(ProtocolFeature f) const override;
409
411 publisherListSequence(PublicKey const& pubKey) const override
412 {
414
415 auto iter = publisherListSequences_.find(pubKey);
416 if (iter != publisherListSequences_.end())
417 return iter->second;
418 return {};
419 }
420
421 void
422 setPublisherListSequence(PublicKey const& pubKey, std::size_t const seq) override
423 {
425
426 publisherListSequences_[pubKey] = seq;
427 }
428
429 //
430 // Ledger
431 //
432
433 UInt256
434 getClosedLedgerHash() const override
435 {
437 return closedLedgerHash_;
438 }
439
440 bool
441 hasLedger(UInt256 const& hash, std::uint32_t seq) const override;
442
443 void
444 ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override;
445
446 bool
447 hasTxSet(UInt256 const& hash) const override;
448
449 void
450 cycleStatus() override;
451
452 bool
453 hasRange(std::uint32_t uMin, std::uint32_t uMax) override;
454
455 // Called to determine our priority for querying
456 int
457 getScore(bool haveItem) const override;
458
459 bool
460 isHighLatency() const override;
461
462 void
463 fail(std::string const& reason);
464
465 bool
466 compressionEnabled() const override
467 {
468 return compressionEnabled_ == Compressed::On;
469 }
470
478 [[nodiscard]] std::size_t
480 {
482 trustedManifestCount(app_.config().maxTrustedCount),
483 untrustedManifestCount(app_.config().maxUntrustedCount));
484 }
485
486 bool
487 txReduceRelayEnabled() const override
488 {
490 }
491
492private:
493 void
494 close();
495
496 void
497 fail(std::string const& name, ErrorCode ec);
498
499 void
501
502 void
503 setTimer();
504
505 void
506 cancelTimer() noexcept;
507
508 static std::string
509 makePrefix(std::string const& fingerprint);
510
511 // Called when the timer wait completes
512 void
513 onTimer(boost::system::error_code const& ec);
514
515 // Called when SSL shutdown completes
516 void
518
519 void
520 doAccept();
521
522 std::string
523 name() const;
524
525 std::string
526 domain() const;
527
528 //
529 // protocol message loop
530 //
531
532 // Starts the protocol message loop
533 void
535
536 // Called when protocol message bytes are received
537 void
538 onReadMessage(ErrorCode ec, std::size_t bytesTransferred);
539
540 // Called when protocol messages bytes are sent
541 void
542 onWriteMessage(ErrorCode ec, std::size_t bytesTransferred);
543
557 void
559 std::shared_ptr<protocol::TMTransaction> const& m,
560 bool eraseTxQueue,
561 bool batch);
562
569 void
570 handleHaveTransactions(std::shared_ptr<protocol::TMHaveTransactions> const& m);
571
572 std::string const&
573 fingerprint() const override
574 {
575 return fingerprint_;
576 }
577
578 std::string const&
579 prefix() const
580 {
581 return prefix_;
582 }
583
584public:
585 //--------------------------------------------------------------------------
586 //
587 // ProtocolStream
588 //
589 //--------------------------------------------------------------------------
590
591 void
593
594 void
596 std::uint16_t type,
598 std::size_t size,
599 std::size_t uncompressedSize,
600 bool isCompressed);
601
602 void
604
605 void
607 void
609 void
611 void
613 void
615 void
617 void
619 void
621 void
623 void
625 void
627 void
629 void
631 void
633 void
635 void
637 void
639 void
641 void
643 void
645
646private:
647 //--------------------------------------------------------------------------
648 // lockedRecentLock is passed as a reminder to callers that recentLock_
649 // must be locked.
650 void
651 addLedger(UInt256 const& hash, std::scoped_lock<std::mutex> const& lockedRecentLock);
652
653 void
655
656 void
658 std::string const& messageType,
659 std::string const& manifest,
660 std::uint32_t version,
661 std::vector<ValidatorBlobInfo> const& blobs);
662
668 void
670
671 void
673 HashRouterFlags flags,
674 bool checkSignature,
676 bool batch);
677
678 void
680 bool isTrusted,
682 RCLCxPeerPos peerPos);
683
684 void
687 UInt256 const& key,
689
690 void
691 sendLedgerBase(std::shared_ptr<Ledger const> const& ledger, protocol::TMLedgerData& ledgerData);
692
695
698
699protected:
700 void
704
716 void
718
742 static resource::Charge
743 computeGetObjectByHashFee(int const requested, int const found);
744
757 {
758 return fee_.fee;
759 }
760};
761
762//------------------------------------------------------------------------------
763
764template <class Buffers>
766 Application& app,
767 std::unique_ptr<StreamType>&& streamPtr,
768 Buffers const& buffers,
770 HttpResponseType&& response,
771 resource::Consumer usage,
772 PublicKey const& publicKey,
774 ID id,
775 OverlayImpl& overlay)
776 : Child(overlay)
777 , app_(app)
778 , id_(id)
779 , fingerprint_(getFingerprint(slot->remoteEndpoint(), publicKey, to_string(id_)))
781 , sink_(app_.getJournal("Peer"), prefix_)
782 , pSink_(app_.getJournal("Protocol"), prefix_)
783 , journal_(sink_)
785 , streamPtr_(std::move(streamPtr))
786 , socket_(streamPtr_->next_layer().socket())
788 , strand_(boost::asio::make_strand(socket_.get_executor()))
789 , timer_(WaitableTimer{socket_.get_executor()})
790 , remoteAddress_(slot->remoteEndpoint())
791 , overlay_(overlay)
792 , inbound_(false)
793 , protocol_(std::move(protocol))
795 , trackingTime_(ClockType::now())
796 , publicKey_(publicKey)
797 , lastPingTime_(ClockType::now())
798 , creationTime_(ClockType::now())
799 , squelch_(app_.getJournal("Squelch"))
800 , usage_(usage)
801 , fee_{.fee = resource::kFeeTrivialPeer}
802 , slot_(std::move(slot))
803 , response_(std::move(response))
807 ? Compressed::On
808 : Compressed::Off)
810 peerFeatureEnabled(headers_, kFeatureTxrr, app_.config().txReduceRelayEnable))
812 peerFeatureEnabled(headers_, kFeatureLedgerReplay, app_.config().ledgerReplay))
813 , ledgerReplayMsgHandler_(app, app.getLedgerReplayer())
814{
815 readBuffer_.commit(
816 boost::asio::buffer_copy(readBuffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
817 JLOG(journal_.info())
818 << "compression enabled " << (compressionEnabled_ == Compressed::On)
819 << " vp reduce-relay base squelch enabled "
820 << peerFeatureEnabled(headers_, kFeatureVprr, app_.config().vpReduceRelayBaseSquelchEnable)
821 << " tx reduce-relay enabled " << txReduceRelayEnabled_ << " on " << remoteAddress_ << " "
822 << id_;
823}
824
825template <class FwdIt>
826void
827PeerImp::sendEndpoints(FwdIt first, FwdIt last)
828 requires(
830{
831 protocol::TMEndpoints tm;
832
833 while (first != last)
834 {
835 auto& tme2(*tm.add_endpoints_v2());
836 tme2.set_endpoint(first->address.toString());
837 tme2.set_hops(first->hops);
838 first++;
839 }
840 tm.set_version(2);
841
842 send(std::make_shared<Message>(tm, protocol::mtENDPOINTS));
843}
844
845} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Wraps a Journal::Sink to prefix its output with a string.
Definition WrappedSink.h:19
A version-independent IP address and port combination.
Definition IPEndpoint.h:24
Represents a JSON value.
Definition json_value.h:117
Child(OverlayImpl &overlay)
std::shared_mutex mutex_
Definition PeerImp.h:237
std::uint64_t rollingAvgBytes_
Definition PeerImp.h:242
boost::circular_buffer< std::uint64_t > rollingAvg_
Definition PeerImp.h:238
Metrics(Metrics const &)=delete
void addMessage(std::uint64_t bytes)
Definition PeerImp.cpp:3748
Metrics & operator=(Metrics const &)=delete
Metrics & operator=(Metrics &&)=delete
std::uint64_t averageBytes() const
Definition PeerImp.cpp:3772
ClockType::time_point intervalStart_
Definition PeerImp.h:239
Metrics(Metrics &&)=delete
std::uint64_t totalBytes() const
Definition PeerImp.cpp:3779
std::uint64_t accumBytes_
Definition PeerImp.h:241
std::uint64_t totalBytes_
Definition PeerImp.h:240
void checkTracking(std::uint32_t validationSeq)
Check if the peer is tracking.
Definition PeerImp.cpp:2177
void onTimer(boost::system::error_code const &ec)
Definition PeerImp.cpp:702
std::optional< std::chrono::milliseconds > latency_
Definition PeerImp.h:129
std::string getVersion() const
Return the version of xrpld that the peer is running, if reported.
Definition PeerImp.cpp:419
std::size_t maxManifestsMessageSize() const
Largest TMManifests message this node accepts, in bytes.
Definition PeerImp.h:479
void onMessage(std::shared_ptr< protocol::TMManifests > const &m)
Definition PeerImp.cpp:1095
ProtocolVersion protocol_
Definition PeerImp.h:109
bool txReduceRelayEnabled_
Definition PeerImp.h:211
void checkTransaction(HashRouterFlags flags, bool checkSignature, std::shared_ptr< STTx const > const &stx, bool batch)
Definition PeerImp.cpp:3029
void setTimer()
Definition PeerImp.cpp:662
void handleTransaction(std::shared_ptr< protocol::TMTransaction > const &m, bool eraseTxQueue, bool batch)
Called from onMessage(TMTransaction(s)).
Definition PeerImp.cpp:1293
bool hasTxSet(UInt256 const &hash) const override
Definition PeerImp.cpp:579
beast::WrappedSink sink_
Definition PeerImp.h:89
void addLedger(UInt256 const &hash, std::scoped_lock< std::mutex > const &lockedRecentLock)
Definition PeerImp.cpp:2931
std::string name() const
Definition PeerImp.cpp:862
bool txReduceRelayEnabled() const override
Definition PeerImp.h:487
SocketType & socket_
Definition PeerImp.h:94
compression::Compressed Compressed
Definition PeerImp.h:83
boost::beast::http::fields const & headers_
Definition PeerImp.h:195
Compressed compressionEnabled_
Definition PeerImp.h:204
ClockType::duration uptime() const
Definition PeerImp.h:399
StreamType & stream_
Definition PeerImp.h:95
ClockType::time_point const creationTime_
Definition PeerImp.h:132
boost::beast::ssl_stream< MiddleType > StreamType
Definition PeerImp.h:79
PeerImp & operator=(PeerImp const &)=delete
boost::circular_buffer< UInt256 > recentTxSets_
Definition PeerImp.h:127
LedgerIndex minLedger_
Definition PeerImp.h:121
std::string prefix_
Definition PeerImp.h:88
WaitableTimer timer_
Definition PeerImp.h:97
std::shared_ptr< peer_finder::Slot > const slot_
Definition PeerImp.h:191
void onWriteMessage(ErrorCode ec, std::size_t bytesTransferred)
Definition PeerImp.cpp:989
boost::beast::multi_buffer readBuffer_
Definition PeerImp.h:192
void onShutdown(ErrorCode ec)
Definition PeerImp.cpp:762
boost::circular_buffer< UInt256 > recentLedgers_
Definition PeerImp.h:126
Metrics sent
Definition PeerImp.h:247
std::string const & fingerprint() const override
Definition PeerImp.h:573
void checkValidation(std::shared_ptr< STValidation > const &val, UInt256 const &key, std::shared_ptr< protocol::TMValidation > const &packet)
Definition PeerImp.cpp:3222
bool ledgerReplayEnabled_
Definition PeerImp.h:213
boost::asio::ip::tcp::socket SocketType
Definition PeerImp.h:77
void sendTxQueue() override
Send aggregated transactions' hashes.
Definition PeerImp.cpp:338
struct xrpl::PeerImp::@337373043150231020277011015352151251117171316327 metrics_
beast::ip::Endpoint const remoteAddress_
Definition PeerImp.h:101
reduce_relay::Squelch< UptimeClock > squelch_
Definition PeerImp.h:134
PeerImp(PeerImp const &)=delete
void cycleStatus() override
Definition PeerImp.cpp:586
bool gracefulClose_
Definition PeerImp.h:197
std::shared_mutex nameMutex_
Definition PeerImp.h:117
std::string domain() const
Definition PeerImp.cpp:869
std::atomic< Tracking > tracking_
Definition PeerImp.h:111
std::optional< std::size_t > publisherListSequence(PublicKey const &pubKey) const override
Definition PeerImp.h:411
void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
Definition PeerImp.cpp:570
HashMap< PublicKey, std::size_t > publisherListSequences_
Definition PeerImp.h:202
void addTxQueue(UInt256 const &hash) override
Add transaction's hash to the transactions' hashes queue.
Definition PeerImp.cpp:354
void onReadMessage(ErrorCode ec, std::size_t bytesTransferred)
Definition PeerImp.cpp:917
LedgerIndex maxLedger_
Definition PeerImp.h:122
boost::beast::tcp_stream MiddleType
Definition PeerImp.h:78
beast::WrappedSink pSink_
Definition PeerImp.h:90
Application & app_
Definition PeerImp.h:85
PublicKey const publicKey_
Definition PeerImp.h:115
boost::asio::ip::tcp::endpoint EndpointType
Definition PeerImp.h:81
void processGetObjectByHash(std::shared_ptr< protocol::TMGetObjectByHash > const &m)
Process a generic-query TMGetObjectByHash message.
Definition PeerImp.cpp:2731
bool cluster() const override
Returns true if this connection is a member of the cluster.
Definition PeerImp.cpp:413
Metrics recv
Definition PeerImp.h:248
static resource::Charge computeGetObjectByHashFee(int const requested, int const found)
Compute the per-message resource charge for a TMGetObjectByHash request based on how much work was ac...
Definition PeerImp.cpp:3673
std::queue< std::shared_ptr< Message > > sendQueue_
Definition PeerImp.h:196
void checkPropose(bool isTrusted, std::shared_ptr< protocol::TMProposeSet > const &packet, RCLCxPeerPos peerPos)
Definition PeerImp.cpp:3174
virtual void run()
Definition PeerImp.cpp:206
OverlayImpl & overlay_
Definition PeerImp.h:105
std::chrono::steady_clock ClockType
Definition PeerImp.h:75
std::unique_ptr< StreamType > streamPtr_
Definition PeerImp.h:93
resource::Consumer usage_
Definition PeerImp.h:183
void sendLedgerBase(std::shared_ptr< Ledger const > const &ledger, protocol::TMLedgerData &ledgerData)
Definition PeerImp.cpp:3313
HashSet< UInt256 > txQueue_
Definition PeerImp.h:209
bool hasLedger(UInt256 const &hash, std::uint32_t seq) const override
Definition PeerImp.cpp:556
beast::Journal const pJournal_
Definition PeerImp.h:92
ClockType::time_point trackingTime_
Definition PeerImp.h:112
friend class OverlayImpl
Definition PeerImp.h:216
static std::string makePrefix(std::string const &fingerprint)
Definition PeerImp.cpp:694
beast::Journal const & pJournal() const
Definition PeerImp.h:290
ChargeWithContext fee_
Definition PeerImp.h:184
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...
Definition PeerImp.cpp:2811
beast::ip::Endpoint getRemoteAddress() const override
Definition PeerImp.h:348
void onMessageUnknown(std::uint16_t type)
Definition PeerImp.cpp:1041
void processLedgerRequest(std::shared_ptr< protocol::TMGetLedger > const &m, std::vector< SHAMapNodeID > nodeIDs)
Definition PeerImp.cpp:3466
~PeerImp() override
Definition PeerImp.cpp:183
void gracefulClose()
Definition PeerImp.cpp:647
void setPublisherListSequence(PublicKey const &pubKey, std::size_t const seq) override
Definition PeerImp.h:422
bool compressionEnabled() const override
Definition PeerImp.h:466
UInt256 getClosedLedgerHash() const override
Definition PeerImp.h:434
Tracking
Whether the peer's view of the ledger converges or diverges from ours.
Definition PeerImp.h:72
protocol::TMStatusChange lastStatus_
Definition PeerImp.h:182
LedgerReplayMsgHandler ledgerReplayMsgHandler_
Definition PeerImp.h:214
boost::asio::basic_waitable_timer< std::chrono::steady_clock > WaitableTimer
Definition PeerImp.h:82
void fail(std::string const &reason)
Definition PeerImp.cpp:622
std::unique_ptr< LoadEvent > loadEvent_
Definition PeerImp.h:199
void send(std::shared_ptr< Message > const &m) override
Definition PeerImp.cpp:277
void onMessageBegin(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m, std::size_t size, std::size_t uncompressedSize, bool isCompressed)
Definition PeerImp.cpp:1047
UInt256 closedLedgerHash_
Definition PeerImp.h:123
void doFetchPack(std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
Definition PeerImp.cpp:2944
bool supportsFeature(ProtocolFeature f) const override
Definition PeerImp.cpp:541
void doProtocolStart()
Definition PeerImp.cpp:879
PublicKey const & getNodePublic() const override
Definition PeerImp.h:386
int largeSendq_
Definition PeerImp.h:198
std::shared_ptr< Ledger const > getLedger(std::shared_ptr< protocol::TMGetLedger > const &m)
Definition PeerImp.cpp:3350
bool const inbound_
Definition PeerImp.h:106
HttpResponseType response_
Definition PeerImp.h:194
boost::asio::strand< boost::asio::executor > strand_
Definition PeerImp.h:96
int getScore(bool haveItem) const override
Definition PeerImp.cpp:3699
std::string name_
Definition PeerImp.h:116
beast::Journal const journal_
Definition PeerImp.h:91
std::string fingerprint_
Definition PeerImp.h:87
boost::asio::ip::address AddressType
Definition PeerImp.h:80
void sendEndpoints(FwdIt first, FwdIt last)
Send a set of PeerFinder endpoints as a protocol message.
Definition PeerImp.h:827
bool isHighLatency() const override
Definition PeerImp.cpp:3741
void cancelTimer() noexcept
Definition PeerImp.cpp:679
ID const id_
Definition PeerImp.h:86
bool hasRange(std::uint32_t uMin, std::uint32_t uMax) override
Definition PeerImp.cpp:596
std::shared_ptr< SHAMap const > getTxSet(std::shared_ptr< protocol::TMGetLedger > const &m) const
Definition PeerImp.cpp:3434
std::optional< std::uint32_t > lastPingSeq_
Definition PeerImp.h:130
bool detaching_
Definition PeerImp.h:113
boost::system::error_code ErrorCode
Definition PeerImp.h:76
bool crawl() const
Returns true if this connection will publicly share its IP address.
Definition PeerImp.cpp:404
void stop() override
Definition PeerImp.cpp:264
HttpRequestType request_
Definition PeerImp.h:193
void onValidatorListMessage(std::string const &messageType, std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs)
Definition PeerImp.cpp:2242
resource::Charge currentFeeCharge() const
Read-only accessor for the accumulated peer-message charge.
Definition PeerImp.h:756
Peer::ID id() const override
Definition PeerImp.h:361
void charge(resource::Charge const &fee, std::string const &context) override
Adjust this peer's load balance based on the type of load imposed.
Definition PeerImp.cpp:378
std::string const & prefix() const
Definition PeerImp.h:579
void removeTxQueue(UInt256 const &hash) override
Remove transaction's hash from the transactions' hashes queue.
Definition PeerImp.cpp:369
void doTransactions(std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
Process peer's request to send missing transactions.
Definition PeerImp.cpp:2977
void doAccept()
Definition PeerImp.cpp:788
std::shared_ptr< peer_finder::Slot > const & slot()
Definition PeerImp.h:296
std::atomic< bool > chargeDisconnectFired_
Definition PeerImp.h:190
UInt256 previousLedgerHash_
Definition PeerImp.h:124
ClockType::time_point lastPingTime_
Definition PeerImp.h:131
json::Value json() override
Definition PeerImp.cpp:427
std::mutex recentLock_
Definition PeerImp.h:181
void onMessageEnd(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m)
Definition PeerImp.cpp:1088
Represents a peer connection in the overlay.
std::uint32_t ID
Uniquely identifies a peer.
A public key.
Definition PublicKey.h:53
A peer's signed, proposed position for use in RCLConsensus.
Maintains squelching of relaying messages from validators.
Definition Squelch.h:19
A consumption charge.
Definition Charge.h:13
An endpoint that consumes resources.
Definition Consumer.h:20
T is_same_v
T make_shared(T... args)
STL namespace.
Charge const kFeeTrivialPeer
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr std::size_t maximumManifestsMessageSize(std::size_t const trustedCount, std::size_t const untrustedCount)
Upper bound on the wire size of a TMManifests message.
Definition Message.h:48
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:382
static constexpr char kFeatureLedgerReplay[]
Definition Handshake.h:131
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:657
static constexpr char kFeatureTxrr[]
Definition Handshake.h:129
BaseUInt< 256 > UInt256
Definition base_uint.h:580
boost::beast::http::request< boost::beast::http::dynamic_body > HttpRequestType
Definition Handoff.h:12
std::unordered_set< Value, Hash, Pred, Allocator > HashSet
HashRouterFlags
Definition HashRouter.h:20
boost::beast::http::response< boost::beast::http::dynamic_body > HttpResponseType
Definition Handoff.h:14
constexpr std::size_t trustedManifestCount(std::optional< std::size_t > const &configured)
Number of trusted manifests allowed in a Manifest message.
Definition Manifest.h:261
std::string getFingerprint(beast::ip::Endpoint const &address, std::optional< PublicKey > const &publicKey=std::nullopt, std::optional< std::string > const &id=std::nullopt)
Definition PublicKey.h:262
bool peerFeatureEnabled(Headers const &request, std::string const &feature, std::string value, bool config)
Check if a feature should be enabled for a peer.
Definition Handshake.h:182
std::pair< std::uint16_t, std::uint16_t > ProtocolVersion
Represents a particular version of the peer-to-peer protocol.
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
constexpr std::size_t untrustedManifestCount(std::optional< std::size_t > const &configured)
Number of untrusted manifests to store in cache and allowed in one Manifest message.
Definition Manifest.h:246
static constexpr char kFeatureCompr[]
Definition Handshake.h:125
static constexpr char kFeatureVprr[]
Definition Handshake.h:127
void update(resource::Charge f, std::string const &add)
Definition PeerImp.h:169
Used to represent the information stored in the blobs_v2 Json array.
Describes a connectable peer address along with some metadata.