20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/misc/HashRouter.h>
22#include <xrpld/core/JobQueue.h>
23#include <xrpld/overlay/Overlay.h>
24#include <xrpld/overlay/PeerSet.h>
25#include <xrpl/protocol/digest.h>
43 ::google::protobuf::Message
const& message,
44 protocol::MessageType type,
61 : app_(app), journal_(app.journal(
"PeerSet"))
78 overlay.foreach([&](
auto const& peer) {
79 auto const score = peer->getScore(hasItem(peer));
86 [](ScoredPeer
const& lhs, ScoredPeer
const& rhs) {
87 return lhs.first > rhs.first;
91 for (
auto const& pair : pairs)
93 auto const peer = pair.second;
94 if (!
peers_.insert(peer->id()).second)
104 ::google::protobuf::Message
const& message,
105 protocol::MessageType type,
108 auto packet = std::make_shared<Message>(message, type);
110 auto const messageHash = [&]() {
111 auto const packetBuffer =
117 using namespace std::chrono_literals;
123 messageHash, peer->id(), interval))
127 << peer->id() <<
"]: " << messageHash;
133 <<
" message to [" << peer->id() <<
"]: " << messageHash;
142 messageHash, p->id(), interval))
146 <<
" message to [" << p->id() <<
"]: " << messageHash;
151 <<
"Suppressing sending duplicate "
153 <<
"]: " << messageHash;
174 return std::make_unique<PeerSetImpl>(
app_);
184 return std::make_unique<PeerSetBuilderImpl>(app);
200 JLOG(
j_.
error()) <<
"DummyPeerSet addPeers should not be called";
205 ::google::protobuf::Message
const& message,
206 protocol::MessageType type,
209 JLOG(
j_.
error()) <<
"DummyPeerSet sendRequest should not be called";
216 JLOG(
j_.
error()) <<
"DummyPeerSet getPeerIds should not be called";
227 return std::make_unique<DummyPeerSet>(app);
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
virtual Overlay & overlay()=0
virtual HashRouter & getHashRouter()=0
void addPeers(std::size_t limit, std::function< bool(std::shared_ptr< Peer > const &)> hasItem, std::function< void(std::shared_ptr< Peer > const &)> onPeerAdded) override
Try add more peers.
void sendRequest(::google::protobuf::Message const &message, protocol::MessageType type, std::shared_ptr< Peer > const &peer) override
DummyPeerSet(Application &app)
const std::set< Peer::id_t > & getPeerIds() const override
get the set of ids of previously added peers
bool shouldProcessForPeer(uint256 const &key, PeerShortID peer, std::chrono::seconds interval)
Determines whether the hashed item should be processed for the given peer.
virtual std::shared_ptr< Peer > findPeerByShortID(Peer::id_t const &id) const =0
Returns the peer with the matching short id, or null.
virtual std::unique_ptr< PeerSet > build() override
PeerSetBuilderImpl(Application &app)
PeerSetImpl(Application &app)
void addPeers(std::size_t limit, std::function< bool(std::shared_ptr< Peer > const &)> hasItem, std::function< void(std::shared_ptr< Peer > const &)> onPeerAdded) override
Try add more peers.
void sendRequest(::google::protobuf::Message const &message, protocol::MessageType type, std::shared_ptr< Peer > const &peer) override
Send a message to one or all peers.
const std::set< Peer::id_t > & getPeerIds() const override
get the set of ids of previously added peers
std::set< Peer::id_t > peers_
The identifiers of the peers we are tracking.
Supports data retrieval by managing a set of peers.
An immutable linear range of bytes.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string protocolMessageName(int type)
Returns the name of a protocol message given its type.
std::unique_ptr< PeerSet > make_DummyPeerSet(Application &app)
Make a dummy PeerSet that does not do anything.
std::unique_ptr< PeerSetBuilder > make_PeerSetBuilder(Application &app)
@ accepted
Manifest is valid.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.