rippled
Loading...
Searching...
No Matches
PeerSet.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_PEERS_PEERSET_H_INCLUDED
21#define RIPPLE_APP_PEERS_PEERSET_H_INCLUDED
22
23#include <xrpld/app/main/Application.h>
24#include <xrpld/overlay/Peer.h>
25#include <xrpld/overlay/detail/ProtocolMessage.h>
26#include <xrpl/beast/clock/abstract_clock.h>
27#include <xrpl/beast/utility/Journal.h>
28#include <boost/asio/basic_waitable_timer.hpp>
29#include <mutex>
30#include <set>
31
32namespace ripple {
33
45{
46public:
47 virtual ~PeerSet() = default;
48
55 virtual void
57 std::size_t limit,
58 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
59 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) = 0;
60
62 template <typename MessageType>
63 void
64 sendRequest(MessageType const& message, std::shared_ptr<Peer> const& peer)
65 {
66 this->sendRequest(message, protocolMessageType(message), peer);
67 }
68
69 virtual void
71 ::google::protobuf::Message const& message,
72 protocol::MessageType type,
73 std::shared_ptr<Peer> const& peer) = 0;
74
76 virtual const std::set<Peer::id_t>&
77 getPeerIds() const = 0;
78};
79
81{
82public:
83 virtual ~PeerSetBuilder() = default;
84
86 build() = 0;
87};
88
91
99
100} // namespace ripple
101
102#endif
virtual ~PeerSetBuilder()=default
virtual std::unique_ptr< PeerSet > build()=0
Supports data retrieval by managing a set of peers.
Definition: PeerSet.h:45
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.
void sendRequest(MessageType const &message, std::shared_ptr< Peer > const &peer)
send a message
Definition: PeerSet.h:64
virtual const std::set< Peer::id_t > & getPeerIds() const =0
get the set of ids of previously added peers
virtual void sendRequest(::google::protobuf::Message const &message, protocol::MessageType type, std::shared_ptr< Peer > const &peer)=0
virtual ~PeerSet()=default
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
protocol::MessageType protocolMessageType(protocol::TMGetLedger const &)
std::unique_ptr< PeerSet > make_DummyPeerSet(Application &app)
Make a dummy PeerSet that does not do anything.
Definition: PeerSet.cpp:187
std::unique_ptr< PeerSetBuilder > make_PeerSetBuilder(Application &app)
Definition: PeerSet.cpp:144