rippled
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 <ripple/app/main/Application.h>
24 #include <ripple/beast/clock/abstract_clock.h>
25 #include <ripple/beast/utility/Journal.h>
26 #include <ripple/overlay/Peer.h>
27 #include <ripple/overlay/impl/ProtocolMessage.h>
28 #include <boost/asio/basic_waitable_timer.hpp>
29 #include <mutex>
30 #include <set>
31 
32 namespace ripple {
33 
44 class PeerSet
45 {
46 public:
47  virtual ~PeerSet() = default;
48 
55  virtual void
56  addPeers(
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 {
82 public:
83  virtual ~PeerSetBuilder() = default;
84 
86  build() = 0;
87 };
88 
91 
99 
100 } // namespace ripple
101 
102 #endif
ripple::make_DummyPeerSet
std::unique_ptr< PeerSet > make_DummyPeerSet(Application &app)
Make a dummy PeerSet that does not do anything.
Definition: PeerSet.cpp:187
ripple::Application
Definition: Application.h:115
std::shared_ptr
STL class.
ripple::PeerSet::getPeerIds
virtual const std::set< Peer::id_t > & getPeerIds() const =0
get the set of ids of previously added peers
std::function
ripple::PeerSet::sendRequest
void sendRequest(MessageType const &message, std::shared_ptr< Peer > const &peer)
send a message
Definition: PeerSet.h:64
ripple::PeerSetBuilder
Definition: PeerSet.h:80
ripple::PeerSet::addPeers
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.
ripple::PeerSet::~PeerSet
virtual ~PeerSet()=default
ripple::protocolMessageType
protocol::MessageType protocolMessageType(protocol::TMGetLedger const &)
Definition: ProtocolMessage.h:42
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::make_PeerSetBuilder
std::unique_ptr< PeerSetBuilder > make_PeerSetBuilder(Application &app)
Definition: PeerSet.cpp:144
ripple::PeerSet
Supports data retrieval by managing a set of peers.
Definition: PeerSet.h:44
ripple::PeerSetBuilder::build
virtual std::unique_ptr< PeerSet > build()=0
mutex
std::size_t
ripple::PeerSetBuilder::~PeerSetBuilder
virtual ~PeerSetBuilder()=default
std::unique_ptr
STL class.
set