xrpld
Loading...
Searching...
No Matches
PeerSet.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/overlay/Peer.h>
5#include <xrpld/overlay/detail/ProtocolMessage.h>
6
7#include <google/protobuf/message.h>
8
9#include <xrpl.pb.h>
10
11#include <cstddef>
12#include <functional>
13#include <memory>
14#include <set>
15
16namespace xrpl {
17
30{
31public:
32 virtual ~PeerSet() = default;
33
40 virtual void
42 std::size_t limit,
43 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
44 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) = 0;
45
49 template <typename MessageType>
50 void
51 sendRequest(MessageType const& message, std::shared_ptr<Peer> const& peer)
52 {
53 this->sendRequest(message, protocolMessageType(message), peer);
54 }
55
56 virtual void
58 ::google::protobuf::Message const& message,
59 protocol::MessageType type,
60 std::shared_ptr<Peer> const& peer) = 0;
61
65 [[nodiscard]] virtual std::set<Peer::id_t> const&
66 getPeerIds() const = 0;
67};
68
70{
71public:
72 virtual ~PeerSetBuilder() = default;
73
75 build() = 0;
76};
77
80
88
89} // namespace xrpl
virtual ~PeerSetBuilder()=default
virtual std::unique_ptr< PeerSet > build()=0
Supports data retrieval by managing a set of peers.
Definition PeerSet.h:30
virtual ~PeerSet()=default
virtual std::set< Peer::id_t > const & getPeerIds() const =0
get the set of ids of previously added peers
void sendRequest(MessageType const &message, std::shared_ptr< Peer > const &peer)
send a message
Definition PeerSet.h:51
virtual void addPeers(std::size_t limit, std::function< bool(std::shared_ptr< Peer > const &)> hasItem, std::function< void(std::shared_ptr< Peer > const &)> onPeerAdded)=0
Try add more peers.
virtual void sendRequest(::google::protobuf::Message const &message, protocol::MessageType type, std::shared_ptr< Peer > const &peer)=0
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
protocol::MessageType protocolMessageType(protocol::TMGetLedger const &)
std::unique_ptr< PeerSetBuilder > makePeerSetBuilder(Application &app)
Definition PeerSet.cpp:141
std::unique_ptr< PeerSet > makeDummyPeerSet(Application &app)
Make a dummy PeerSet that does not do anything.
Definition PeerSet.cpp:184