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
27namespace ripple {
28
40{
41public:
42 virtual ~PeerSet() = default;
43
50 virtual void
52 std::size_t limit,
53 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
54 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) = 0;
55
57 template <typename MessageType>
58 void
59 sendRequest(MessageType const& message, std::shared_ptr<Peer> const& peer)
60 {
61 this->sendRequest(message, protocolMessageType(message), peer);
62 }
63
64 virtual void
66 ::google::protobuf::Message const& message,
67 protocol::MessageType type,
68 std::shared_ptr<Peer> const& peer) = 0;
69
71 virtual std::set<Peer::id_t> const&
72 getPeerIds() const = 0;
73};
74
76{
77public:
78 virtual ~PeerSetBuilder() = default;
79
81 build() = 0;
82};
83
86
94
95} // namespace ripple
96
97#endif
virtual ~PeerSetBuilder()=default
virtual std::unique_ptr< PeerSet > build()=0
Supports data retrieval by managing a set of peers.
Definition PeerSet.h:40
virtual std::set< Peer::id_t > const & getPeerIds() const =0
get the set of ids of previously added peers
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:59
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:25
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