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/overlay/Squelch.h>
6#include <xrpld/overlay/detail/OverlayImpl.h>
7#include <xrpld/overlay/detail/ProtocolVersion.h>
8#include <xrpld/peerfinder/PeerfinderManager.h>
9
10#include <xrpl/basics/UnorderedContainers.h>
11#include <xrpl/beast/utility/WrappedSink.h>
12#include <xrpl/core/HashRouter.h>
13#include <xrpl/protocol/Protocol.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/STValidation.h>
16#include <xrpl/resource/Fees.h>
17
18#include <boost/circular_buffer.hpp>
19#include <boost/endian/conversion.hpp>
20#include <boost/thread/shared_mutex.hpp>
21
22#include <atomic>
23#include <cstdint>
24#include <optional>
25#include <queue>
26#include <utility>
27
28namespace xrpl {
29
31class SHAMap;
32
33class PeerImp : public Peer, public std::enable_shared_from_this<PeerImp>, public OverlayImpl::Child
34{
35public:
38
39private:
41 using error_code = boost::system::error_code;
42 using socket_type = boost::asio::ip::tcp::socket;
43 using middle_type = boost::beast::tcp_stream;
44 using stream_type = boost::beast::ssl_stream<middle_type>;
45 using address_type = boost::asio::ip::address;
46 using endpoint_type = boost::asio::ip::tcp::endpoint;
47 using waitable_timer = boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
49
51 id_t const id_;
61 boost::asio::strand<boost::asio::executor> strand_;
63
64 // Updated at each stage of the connection process to reflect
65 // the current conditions as closely as possible.
67
68 // These are up here to prevent warnings about order of initializations
69 //
71 bool const inbound_;
72
73 // Protocol version to use for this link
75
77 clock_type::time_point trackingTime_;
78 bool detaching_ = false;
79 // Node public key of peer.
83
84 // The indices of the smallest and largest ledgers this peer has available
85 //
90
91 boost::circular_buffer<uint256> recentLedgers_{128};
92 boost::circular_buffer<uint256> recentTxSets_{128};
93
96 clock_type::time_point lastPingTime_;
97 clock_type::time_point const creationTime_;
98
100
101 // Notes on thread locking:
102 //
103 // During an audit it was noted that some member variables that looked
104 // like they need thread protection were not receiving it. And, indeed,
105 // that was correct. But the multi-phase initialization of PeerImp
106 // makes such an audit difficult. A further audit suggests that the
107 // locking is now protecting variables that don't need it. We're
108 // leaving that locking in place (for now) as a form of future proofing.
109 //
110 // Here are the variables that appear to need locking currently:
111 //
112 // o closedLedgerHash_
113 // o previousLedgerHash_
114 // o minLedger_
115 // o maxLedger_
116 // o recentLedgers_
117 // o recentTxSets_
118 // o trackingTime_
119 // o latency_
120 //
121 // The following variables are being protected preemptively:
122 //
123 // o name_
124 // o lastStatus_
125 //
126 // June 2019
127
129 {
131 std::string context{}; // NOLINT(readability-redundant-member-init)
132
133 void
135 {
136 XRPL_ASSERT(f >= fee, "xrpl::PeerImp::ChargeWithContext::update : fee increases");
137 fee = f;
138 if (!context.empty())
139 {
140 context += " ";
141 }
142 context += add;
143 }
144 };
145
147 protocol::TMStatusChange lastStatus_;
150
151 // One-shot guard so concurrent JobQueue workers cannot double-count
152 // the per-connection peer-disconnect-by-charge metric (and cannot
153 // post duplicate fail() calls) when several queued requests cross
154 // kDropThreshold before the first fail() lands on the strand.
157 boost::beast::multi_buffer readBuffer_;
160 boost::beast::http::fields const& headers_;
162 bool gracefulClose_ = false;
163 int largeSendq_ = 0;
165 // The highest sequence of each PublisherList that has
166 // been sent to or received from this peer.
168
170
171 // Queue of transactions' hashes that have not been
172 // relayed. The hashes are sent once a second to a peer
173 // and the peer requests missing transactions from the node.
175 // true if tx reduce-relay feature is enabled on the peer.
177
180
181 friend class OverlayImpl;
182
184 {
185 public:
186 Metrics() = default;
187 Metrics(Metrics const&) = delete;
188 Metrics&
189 operator=(Metrics const&) = delete;
190 Metrics(Metrics&&) = delete;
191 Metrics&
192 operator=(Metrics&&) = delete;
193
194 void
197 averageBytes() const;
199 totalBytes() const;
200
201 private:
203 boost::circular_buffer<std::uint64_t> rollingAvg_{30, 0ull};
204 clock_type::time_point intervalStart_{clock_type::now()};
208 };
209
210 struct
211 {
215
216public:
217 PeerImp(PeerImp const&) = delete;
218 PeerImp&
219 operator=(PeerImp const&) = delete;
220
222 PeerImp(
223 Application& app,
224 id_t id,
226 http_request_type&& request,
227 PublicKey const& publicKey,
229 Resource::Consumer consumer,
231 OverlayImpl& overlay);
232
234 // VFALCO legacyPublicKey should be implied by the Slot
235 template <class Buffers>
236 PeerImp(
237 Application& app,
239 Buffers const& buffers,
241 http_response_type&& response,
242 Resource::Consumer usage,
243 PublicKey const& publicKey,
245 id_t id,
246 OverlayImpl& overlay);
247
248 ~PeerImp() override;
249
250 beast::Journal const&
251 pJournal() const
252 {
253 return pJournal_;
254 }
255
258 {
259 return slot_;
260 }
261
262 // Work-around for calling shared_from_this in constructors
263 virtual void
264 run();
265
266 // Called when Overlay gets a stop request.
267 void
268 stop() override;
269
270 //
271 // Network
272 //
273
274 void
275 send(std::shared_ptr<Message> const& m) override;
276
278 void
279 sendTxQueue() override;
280
284 void
285 addTxQueue(uint256 const& hash) override;
286
290 void
291 removeTxQueue(uint256 const& hash) override;
292
294 template <
295 class FwdIt,
296 class = std::enable_if_t<
298 void
299 sendEndpoints(FwdIt first, FwdIt last);
300
302 getRemoteAddress() const override
303 {
304 return remoteAddress_;
305 }
306
307 void
308 charge(Resource::Charge const& fee, std::string const& context) override;
309
310 //
311 // Identity
312 //
313
315 id() const override
316 {
317 return id_;
318 }
319
321 bool
322 crawl() const;
323
324 bool
325 cluster() const override;
326
330 void
331 checkTracking(std::uint32_t validationSeq);
332
333 void
335
336 PublicKey const&
337 getNodePublic() const override
338 {
339 return publicKey_;
340 }
341
344 getVersion() const;
345
346 // Return the connection elapsed time.
347 clock_type::duration
348 uptime() const
349 {
351 }
352
354 json() override;
355
356 bool
357 supportsFeature(ProtocolFeature f) const override;
358
360 publisherListSequence(PublicKey const& pubKey) const override
361 {
363
364 auto iter = publisherListSequences_.find(pubKey);
365 if (iter != publisherListSequences_.end())
366 return iter->second;
367 return {};
368 }
369
370 void
371 setPublisherListSequence(PublicKey const& pubKey, std::size_t const seq) override
372 {
374
375 publisherListSequences_[pubKey] = seq;
376 }
377
378 //
379 // Ledger
380 //
381
382 uint256 const&
383 getClosedLedgerHash() const override
384 {
385 return closedLedgerHash_;
386 }
387
388 bool
389 hasLedger(uint256 const& hash, std::uint32_t seq) const override;
390
391 void
392 ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override;
393
394 bool
395 hasTxSet(uint256 const& hash) const override;
396
397 void
398 cycleStatus() override;
399
400 bool
401 hasRange(std::uint32_t uMin, std::uint32_t uMax) override;
402
403 // Called to determine our priority for querying
404 int
405 getScore(bool haveItem) const override;
406
407 bool
408 isHighLatency() const override;
409
410 void
411 fail(std::string const& reason);
412
413 bool
414 compressionEnabled() const override
415 {
416 return compressionEnabled_ == Compressed::On;
417 }
418
419 bool
420 txReduceRelayEnabled() const override
421 {
423 }
424
425private:
426 void
427 close();
428
429 void
430 fail(std::string const& name, error_code ec);
431
432 void
434
435 void
436 setTimer();
437
438 void
439 cancelTimer() noexcept;
440
441 static std::string
442 makePrefix(std::string const& fingerprint);
443
444 // Called when the timer wait completes
445 void
446 onTimer(boost::system::error_code const& ec);
447
448 // Called when SSL shutdown completes
449 void
451
452 void
453 doAccept();
454
455 std::string
456 name() const;
457
458 std::string
459 domain() const;
460
461 //
462 // protocol message loop
463 //
464
465 // Starts the protocol message loop
466 void
468
469 // Called when protocol message bytes are received
470 void
471 onReadMessage(error_code ec, std::size_t bytesTransferred);
472
473 // Called when protocol messages bytes are sent
474 void
475 onWriteMessage(error_code ec, std::size_t bytesTransferred);
476
489 void
491 std::shared_ptr<protocol::TMTransaction> const& m,
492 bool eraseTxQueue,
493 bool batch);
494
500 void
501 handleHaveTransactions(std::shared_ptr<protocol::TMHaveTransactions> const& m);
502
503 std::string const&
504 fingerprint() const override
505 {
506 return fingerprint_;
507 }
508
509 std::string const&
510 prefix() const
511 {
512 return prefix_;
513 }
514
515public:
516 //--------------------------------------------------------------------------
517 //
518 // ProtocolStream
519 //
520 //--------------------------------------------------------------------------
521
522 void
524
525 void
527 std::uint16_t type,
529 std::size_t size,
530 std::size_t uncompressedSize,
531 bool isCompressed);
532
533 void
535
536 void
538 void
540 void
542 void
544 void
546 void
548 void
550 void
552 void
554 void
556 void
558 void
560 void
562 void
564 void
566 void
568 void
570 void
572 void
574 void
576 void
578
579private:
580 //--------------------------------------------------------------------------
581 // lockedRecentLock is passed as a reminder to callers that recentLock_
582 // must be locked.
583 void
584 addLedger(uint256 const& hash, std::scoped_lock<std::mutex> const& lockedRecentLock);
585
586 void
588
589 void
591 std::string const& messageType,
592 std::string const& manifest,
593 std::uint32_t version,
594 std::vector<ValidatorBlobInfo> const& blobs);
595
600 void
602
603 void
605 HashRouterFlags flags,
606 bool checkSignature,
608 bool batch);
609
610 void
612 bool isTrusted,
614 RCLCxPeerPos peerPos);
615
616 void
619 uint256 const& key,
621
622 void
623 sendLedgerBase(std::shared_ptr<Ledger const> const& ledger, protocol::TMLedgerData& ledgerData);
624
627
630
631 void
633
634protected:
635 // Kept `protected` so test subclasses (see
636 // TMGetObjectByHash_test) can drive the
637 // synchronous processor and the differential-pricing helper without
638 // routing through the JobQueue or going through `friend` plumbing.
639 // Production callers reach these members only via
640 // `onMessage(TMGetObjectByHash)` → JobQueue → `processGetObjectByHash`.
641
652 void
654
677 static Resource::Charge
678 computeGetObjectByHashFee(int const requested, int const found);
679
691 {
692 return fee_.fee;
693 }
694};
695
696//------------------------------------------------------------------------------
697
698template <class Buffers>
700 Application& app,
702 Buffers const& buffers,
704 http_response_type&& response,
705 Resource::Consumer usage,
706 PublicKey const& publicKey,
708 id_t id,
709 OverlayImpl& overlay)
710 : Child(overlay)
711 , app_(app)
712 , id_(id)
713 , fingerprint_(getFingerprint(slot->remoteEndpoint(), publicKey, to_string(id_)))
715 , sink_(app_.getJournal("Peer"), prefix_)
716 , pSink_(app_.getJournal("Protocol"), prefix_)
717 , journal_(sink_)
719 , streamPtr_(std::move(streamPtr))
720 , socket_(streamPtr_->next_layer().socket())
722 , strand_(boost::asio::make_strand(socket_.get_executor()))
723 , timer_(waitable_timer{socket_.get_executor()})
724 , remoteAddress_(slot->remoteEndpoint())
725 , overlay_(overlay)
726 , inbound_(false)
727 , protocol_(std::move(protocol))
729 , trackingTime_(clock_type::now())
730 , publicKey_(publicKey)
731 , lastPingTime_(clock_type::now())
732 , creationTime_(clock_type::now())
733 , squelch_(app_.getJournal("Squelch"))
734 , usage_(usage)
735 , fee_{.fee = Resource::kFeeTrivialPeer}
736 , slot_(std::move(slot))
737 , response_(std::move(response))
741 ? Compressed::On
742 : Compressed::Off)
744 peerFeatureEnabled(headers_, kFeatureTxrr, app_.config().txReduceRelayEnable))
746 peerFeatureEnabled(headers_, kFeatureLedgerReplay, app_.config().ledgerReplay))
747 , ledgerReplayMsgHandler_(app, app.getLedgerReplayer())
748{
749 readBuffer_.commit(
750 boost::asio::buffer_copy(readBuffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
751 JLOG(journal_.info())
752 << "compression enabled " << (compressionEnabled_ == Compressed::On)
753 << " vp reduce-relay base squelch enabled "
754 << peerFeatureEnabled(headers_, kFeatureVprr, app_.config().vpReduceRelayBaseSquelchEnable)
755 << " tx reduce-relay enabled " << txReduceRelayEnabled_ << " on " << remoteAddress_ << " "
756 << id_;
757}
758
759template <class FwdIt, class>
760void
761PeerImp::sendEndpoints(FwdIt first, FwdIt last)
762{
763 protocol::TMEndpoints tm;
764
765 while (first != last)
766 {
767 auto& tme2(*tm.add_endpoints_v2());
768 tme2.set_endpoint(first->address.toString());
769 tme2.set_hops(first->hops);
770 first++;
771 }
772 tm.set_version(2);
773
774 send(std::make_shared<Message>(tm, protocol::mtENDPOINTS));
775}
776
777} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:17
A generic endpoint for log messages.
Definition Journal.h:38
Wraps a Journal::Sink to prefix its output with a string.
Definition WrappedSink.h:16
Represents a JSON value.
Definition json_value.h:130
Child(OverlayImpl &overlay)
std::shared_mutex mutex_
Definition PeerImp.h:202
std::uint64_t rollingAvgBytes_
Definition PeerImp.h:207
clock_type::time_point intervalStart_
Definition PeerImp.h:204
boost::circular_buffer< std::uint64_t > rollingAvg_
Definition PeerImp.h:203
Metrics(Metrics const &)=delete
void addMessage(std::uint64_t bytes)
Definition PeerImp.cpp:3556
Metrics & operator=(Metrics const &)=delete
Metrics & operator=(Metrics &&)=delete
std::uint64_t averageBytes() const
Definition PeerImp.cpp:3580
Metrics(Metrics &&)=delete
std::uint64_t totalBytes() const
Definition PeerImp.cpp:3587
std::uint64_t accumBytes_
Definition PeerImp.h:206
std::uint64_t totalBytes_
Definition PeerImp.h:205
void checkTracking(std::uint32_t validationSeq)
Check if the peer is tracking.
Definition PeerImp.cpp:1998
void onTimer(boost::system::error_code const &ec)
Definition PeerImp.cpp:697
std::optional< std::chrono::milliseconds > latency_
Definition PeerImp.h:94
void addTxQueue(uint256 const &hash) override
Add transaction's hash to the transactions' hashes queue.
Definition PeerImp.cpp:347
std::string getVersion() const
Return the version of xrpld that the peer is running, if reported.
Definition PeerImp.cpp:412
boost::asio::ip::tcp::endpoint endpoint_type
Definition PeerImp.h:46
void onMessage(std::shared_ptr< protocol::TMManifests > const &m)
Definition PeerImp.cpp:1093
ProtocolVersion protocol_
Definition PeerImp.h:74
bool txReduceRelayEnabled_
Definition PeerImp.h:176
void checkTransaction(HashRouterFlags flags, bool checkSignature, std::shared_ptr< STTx const > const &stx, bool batch)
Definition PeerImp.cpp:2864
void setTimer()
Definition PeerImp.cpp:657
std::shared_ptr< PeerFinder::Slot > const & slot()
Definition PeerImp.h:257
boost::beast::tcp_stream middle_type
Definition PeerImp.h:43
void handleTransaction(std::shared_ptr< protocol::TMTransaction > const &m, bool eraseTxQueue, bool batch)
Called from onMessage(TMTransaction(s)).
Definition PeerImp.cpp:1285
http_request_type request_
Definition PeerImp.h:158
void removeTxQueue(uint256 const &hash) override
Remove transaction's hash from the transactions' hashes queue.
Definition PeerImp.cpp:362
beast::WrappedSink sink_
Definition PeerImp.h:54
std::string name() const
Definition PeerImp.cpp:857
bool txReduceRelayEnabled() const override
Definition PeerImp.h:420
std::shared_ptr< PeerFinder::Slot > const slot_
Definition PeerImp.h:156
boost::asio::ip::tcp::socket socket_type
Definition PeerImp.h:42
compression::Compressed Compressed
Definition PeerImp.h:48
boost::beast::http::fields const & headers_
Definition PeerImp.h:160
Compressed compressionEnabled_
Definition PeerImp.h:169
std::chrono::steady_clock clock_type
Definition PeerImp.h:40
uint256 const & getClosedLedgerHash() const override
Definition PeerImp.h:383
boost::system::error_code error_code
Definition PeerImp.h:41
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:3481
PeerImp & operator=(PeerImp const &)=delete
LedgerIndex minLedger_
Definition PeerImp.h:86
std::string prefix_
Definition PeerImp.h:53
void sendEndpoints(FwdIt first, FwdIt last)
Send a set of PeerFinder endpoints as a protocol message.
Definition PeerImp.h:761
void addLedger(uint256 const &hash, std::scoped_lock< std::mutex > const &lockedRecentLock)
Definition PeerImp.cpp:2766
boost::beast::multi_buffer readBuffer_
Definition PeerImp.h:157
id_t const id_
Definition PeerImp.h:51
Metrics sent
Definition PeerImp.h:212
std::string const & fingerprint() const override
Definition PeerImp.h:504
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:371
bool ledgerReplayEnabled_
Definition PeerImp.h:178
void sendTxQueue() override
Send aggregated transactions' hashes.
Definition PeerImp.cpp:331
struct xrpl::PeerImp::@337373043150231020277011015352151251117171316327 metrics_
std::unique_ptr< stream_type > streamPtr_
Definition PeerImp.h:58
uint256 closedLedgerHash_
Definition PeerImp.h:88
reduce_relay::Squelch< UptimeClock > squelch_
Definition PeerImp.h:99
stream_type & stream_
Definition PeerImp.h:60
PeerImp(PeerImp const &)=delete
void checkValidation(std::shared_ptr< STValidation > const &val, uint256 const &key, std::shared_ptr< protocol::TMValidation > const &packet)
Definition PeerImp.cpp:3045
void cycleStatus() override
Definition PeerImp.cpp:581
bool gracefulClose_
Definition PeerImp.h:162
std::shared_mutex nameMutex_
Definition PeerImp.h:82
socket_type & socket_
Definition PeerImp.h:59
std::string domain() const
Definition PeerImp.cpp:864
std::atomic< Tracking > tracking_
Definition PeerImp.h:76
std::optional< std::size_t > publisherListSequence(PublicKey const &pubKey) const override
Definition PeerImp.h:360
void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
Definition PeerImp.cpp:565
clock_type::duration uptime() const
Definition PeerImp.h:348
boost::asio::ip::address address_type
Definition PeerImp.h:45
LedgerIndex maxLedger_
Definition PeerImp.h:87
beast::WrappedSink pSink_
Definition PeerImp.h:55
Application & app_
Definition PeerImp.h:50
PublicKey const publicKey_
Definition PeerImp.h:80
void processGetObjectByHash(std::shared_ptr< protocol::TMGetObjectByHash > const &m)
Process a generic-query TMGetObjectByHash message.
Definition PeerImp.cpp:2573
bool cluster() const override
Returns true if this connection is a member of the cluster.
Definition PeerImp.cpp:406
Metrics recv
Definition PeerImp.h:213
std::queue< std::shared_ptr< Message > > sendQueue_
Definition PeerImp.h:161
void checkPropose(bool isTrusted, std::shared_ptr< protocol::TMProposeSet > const &packet, RCLCxPeerPos peerPos)
Definition PeerImp.cpp:2997
virtual void run()
Definition PeerImp.cpp:198
OverlayImpl & overlay_
Definition PeerImp.h:70
void sendLedgerBase(std::shared_ptr< Ledger const > const &ledger, protocol::TMLedgerData &ledgerData)
Definition PeerImp.cpp:3136
Peer::id_t id() const override
Definition PeerImp.h:315
beast::Journal const pJournal_
Definition PeerImp.h:57
friend class OverlayImpl
Definition PeerImp.h:181
static std::string makePrefix(std::string const &fingerprint)
Definition PeerImp.cpp:689
beast::Journal const & pJournal() const
Definition PeerImp.h:251
ChargeWithContext fee_
Definition PeerImp.h:149
void onShutdown(error_code ec)
Definition PeerImp.cpp:757
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:2653
beast::IP::Endpoint getRemoteAddress() const override
Definition PeerImp.h:302
void onMessageUnknown(std::uint16_t type)
Definition PeerImp.cpp:1040
~PeerImp() override
Definition PeerImp.cpp:175
void gracefulClose()
Definition PeerImp.cpp:642
void setPublisherListSequence(PublicKey const &pubKey, std::size_t const seq) override
Definition PeerImp.h:371
bool compressionEnabled() const override
Definition PeerImp.h:414
void processLedgerRequest(std::shared_ptr< protocol::TMGetLedger > const &m)
Definition PeerImp.cpp:3289
Tracking
Whether the peer's view of the ledger converges or diverges from ours.
Definition PeerImp.h:37
protocol::TMStatusChange lastStatus_
Definition PeerImp.h:147
clock_type::time_point const creationTime_
Definition PeerImp.h:97
LedgerReplayMsgHandler ledgerReplayMsgHandler_
Definition PeerImp.h:179
void fail(std::string const &reason)
Definition PeerImp.cpp:617
std::unique_ptr< LoadEvent > loadEvent_
Definition PeerImp.h:164
void send(std::shared_ptr< Message > const &m) override
Definition PeerImp.cpp:269
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:1046
hash_set< uint256 > txQueue_
Definition PeerImp.h:174
void doFetchPack(std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
Definition PeerImp.cpp:2779
bool supportsFeature(ProtocolFeature f) const override
Definition PeerImp.cpp:534
void doProtocolStart()
Definition PeerImp.cpp:874
PublicKey const & getNodePublic() const override
Definition PeerImp.h:337
int largeSendq_
Definition PeerImp.h:163
std::shared_ptr< Ledger const > getLedger(std::shared_ptr< protocol::TMGetLedger > const &m)
Definition PeerImp.cpp:3173
bool const inbound_
Definition PeerImp.h:71
boost::asio::strand< boost::asio::executor > strand_
Definition PeerImp.h:61
waitable_timer timer_
Definition PeerImp.h:62
clock_type::time_point lastPingTime_
Definition PeerImp.h:96
boost::circular_buffer< uint256 > recentLedgers_
Definition PeerImp.h:91
int getScore(bool haveItem) const override
Definition PeerImp.cpp:3507
std::string name_
Definition PeerImp.h:81
bool hasTxSet(uint256 const &hash) const override
Definition PeerImp.cpp:574
http_response_type response_
Definition PeerImp.h:159
boost::circular_buffer< uint256 > recentTxSets_
Definition PeerImp.h:92
clock_type::time_point trackingTime_
Definition PeerImp.h:77
beast::Journal const journal_
Definition PeerImp.h:56
std::string fingerprint_
Definition PeerImp.h:52
bool isHighLatency() const override
Definition PeerImp.cpp:3549
void cancelTimer() noexcept
Definition PeerImp.cpp:674
bool hasRange(std::uint32_t uMin, std::uint32_t uMax) override
Definition PeerImp.cpp:591
std::shared_ptr< SHAMap const > getTxSet(std::shared_ptr< protocol::TMGetLedger > const &m) const
Definition PeerImp.cpp:3257
uint256 previousLedgerHash_
Definition PeerImp.h:89
Resource::Consumer usage_
Definition PeerImp.h:148
std::optional< std::uint32_t > lastPingSeq_
Definition PeerImp.h:95
void onWriteMessage(error_code ec, std::size_t bytesTransferred)
Definition PeerImp.cpp:986
bool detaching_
Definition PeerImp.h:78
boost::beast::ssl_stream< middle_type > stream_type
Definition PeerImp.h:44
bool crawl() const
Returns true if this connection will publicly share its IP address.
Definition PeerImp.cpp:397
beast::IP::Endpoint const remoteAddress_
Definition PeerImp.h:66
void stop() override
Definition PeerImp.cpp:256
Resource::Charge currentFeeCharge() const
Read-only accessor for the accumulated peer-message charge.
Definition PeerImp.h:690
void onValidatorListMessage(std::string const &messageType, std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs)
Definition PeerImp.cpp:2063
std::string const & prefix() const
Definition PeerImp.h:510
void doTransactions(std::shared_ptr< protocol::TMGetObjectByHash > const &packet)
Process peer's request to send missing transactions.
Definition PeerImp.cpp:2812
void doAccept()
Definition PeerImp.cpp:783
void onReadMessage(error_code ec, std::size_t bytesTransferred)
Definition PeerImp.cpp:912
hash_map< PublicKey, std::size_t > publisherListSequences_
Definition PeerImp.h:167
std::atomic< bool > chargeDisconnectFired_
Definition PeerImp.h:155
json::Value json() override
Definition PeerImp.cpp:420
std::mutex recentLock_
Definition PeerImp.h:146
bool hasLedger(uint256 const &hash, std::uint32_t seq) const override
Definition PeerImp.cpp:551
boost::asio::basic_waitable_timer< std::chrono::steady_clock > waitable_timer
Definition PeerImp.h:47
void onMessageEnd(std::uint16_t type, std::shared_ptr<::google::protobuf::Message > const &m)
Definition PeerImp.cpp:1086
Represents a peer connection in the overlay.
std::uint32_t id_t
Uniquely identifies a peer.
A public key.
Definition PublicKey.h:42
A peer's signed, proposed position for use in RCLConsensus.
A consumption charge.
Definition Charge.h:9
An endpoint that consumes resources.
Definition Consumer.h:15
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition SHAMap.h:77
Maintains squelching of relaying messages from validators.
Definition Squelch.h:16
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
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:259
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
static constexpr char kFeatureLedgerReplay[]
Definition Handshake.h:124
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
static constexpr char kFeatureTxrr[]
Definition Handshake.h:122
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:242
HashRouterFlags
Definition HashRouter.h:14
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
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:171
std::pair< std::uint16_t, std::uint16_t > ProtocolVersion
Represents a particular version of the peer-to-peer protocol.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:12
static constexpr char kFeatureCompr[]
Definition Handshake.h:118
BaseUInt< 256 > uint256
Definition base_uint.h:562
static constexpr char kFeatureVprr[]
Definition Handshake.h:120
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_type
Definition Handoff.h:14
Describes a connectable peer address along with some metadata.
void update(Resource::Charge f, std::string const &add)
Definition PeerImp.h:134
Used to represent the information stored in the blobs_v2 Json array.