rippled
Loading...
Searching...
No Matches
PeerfinderManager.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_PEERFINDER_MANAGER_H_INCLUDED
21#define RIPPLE_PEERFINDER_MANAGER_H_INCLUDED
22
23#include <xrpld/core/Config.h>
24#include <xrpld/peerfinder/Slot.h>
25#include <xrpl/beast/clock/abstract_clock.h>
26#include <xrpl/beast/utility/PropertyStream.h>
27#include <boost/asio/ip/tcp.hpp>
28
29namespace ripple {
30namespace PeerFinder {
31
33
36
37//------------------------------------------------------------------------------
38
40struct Config
41{
47
53
59
61 bool peerPrivate = true;
62
65
68
71
74
77
78 //--------------------------------------------------------------------------
79
81 Config();
82
85 calcOutPeers() const;
86
88 void
90
92 void
94
102 static Config
104 ripple::Config const& config,
105 std::uint16_t port,
106 bool validationPublicKey,
107 int ipLimit);
108};
109
110//------------------------------------------------------------------------------
111
114{
115 Endpoint() = default;
116
118
121};
122
123inline bool
124operator<(Endpoint const& lhs, Endpoint const& rhs)
125{
126 return lhs.address < rhs.address;
127}
128
131
132//------------------------------------------------------------------------------
133
135enum class Result { duplicate, full, success };
136
139{
140protected:
141 Manager() noexcept;
142
143public:
149 virtual ~Manager() = default;
150
156 virtual void
158
160 virtual void
161 start() = 0;
162
164 virtual void
165 stop() = 0;
166
168 virtual Config
169 config() = 0;
170
176 virtual void
178 std::string const& name,
179 std::vector<beast::IP::Endpoint> const& addresses) = 0;
180
184 virtual void
186 std::string const& name,
187 std::vector<std::string> const& strings) = 0;
188
192 /* VFALCO NOTE Unimplemented
193 virtual void addFallbackURL (std::string const& name,
194 std::string const& url) = 0;
195 */
196
197 //--------------------------------------------------------------------------
198
205 beast::IP::Endpoint const& local_endpoint,
206 beast::IP::Endpoint const& remote_endpoint) = 0;
207
213 new_outbound_slot(beast::IP::Endpoint const& remote_endpoint) = 0;
214
216 virtual void
218 std::shared_ptr<Slot> const& slot,
219 Endpoints const& endpoints) = 0;
220
225 virtual void
227
229 virtual void
231
233 virtual void
235 boost::asio::ip::tcp::endpoint const& remote_address,
237
238 //--------------------------------------------------------------------------
239
247 virtual bool
249 std::shared_ptr<Slot> const& slot,
250 beast::IP::Endpoint const& local_endpoint) = 0;
251
253 virtual Result
255 std::shared_ptr<Slot> const& slot,
256 PublicKey const& key,
257 bool reserved) = 0;
258
262
266
269
273 virtual void
275};
276
277} // namespace PeerFinder
278} // namespace ripple
279
280#endif
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
Subclasses can be called to write to a stream and have children.
std::string const & name() const
Returns the name of this source.
Maintains a set of IP addresses used for getting into the network.
virtual void once_per_second()=0
Perform periodic activity.
virtual void on_endpoints(std::shared_ptr< Slot > const &slot, Endpoints const &endpoints)=0
Called when mtENDPOINTS is received.
virtual void start()=0
Transition to the started state, synchronously.
virtual void setConfig(Config const &config)=0
Set the configuration for the manager.
virtual void addFixedPeer(std::string const &name, std::vector< beast::IP::Endpoint > const &addresses)=0
Add a peer that should always be connected.
virtual std::vector< beast::IP::Endpoint > autoconnect()=0
Return a set of addresses we should connect to.
virtual ~Manager()=default
Destroy the object.
virtual bool onConnected(std::shared_ptr< Slot > const &slot, beast::IP::Endpoint const &local_endpoint)=0
Called when an outbound connection attempt succeeds.
virtual Config config()=0
Returns the configuration for the manager.
virtual void on_closed(std::shared_ptr< Slot > const &slot)=0
Called when the slot is closed.
virtual void stop()=0
Transition to the stopped state, synchronously.
virtual std::vector< std::pair< std::shared_ptr< Slot >, std::vector< Endpoint > > > buildEndpointsForPeers()=0
virtual std::shared_ptr< Slot > new_outbound_slot(beast::IP::Endpoint const &remote_endpoint)=0
Create a new outbound slot with the specified remote endpoint.
virtual std::vector< Endpoint > redirect(std::shared_ptr< Slot > const &slot)=0
Returns a set of endpoints suitable for redirection.
virtual void on_failure(std::shared_ptr< Slot > const &slot)=0
Called when an outbound connection is deemed to have failed.
virtual void onRedirects(boost::asio::ip::tcp::endpoint const &remote_address, std::vector< boost::asio::ip::tcp::endpoint > const &eps)=0
Called when we received redirect IPs from a busy peer.
virtual void addFallbackStrings(std::string const &name, std::vector< std::string > const &strings)=0
Add a set of strings as fallback IP::Endpoint sources.
virtual Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved)=0
Request an active slot type.
virtual std::shared_ptr< Slot > new_inbound_slot(beast::IP::Endpoint const &local_endpoint, beast::IP::Endpoint const &remote_endpoint)=0
Add a URL as a fallback location to obtain IP::Endpoint sources.
A public key.
Definition: PublicKey.h:62
bool operator<(Endpoint const &lhs, Endpoint const &rhs)
Result
Possible results from activating a slot.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
PeerFinder configuration settings.
void onWrite(beast::PropertyStream::Map &map)
Write the configuration into a property stream.
Config()
Create a configuration with default values.
bool autoConnect
true if we want to establish connections automatically
int ipLimit
Limit how many incoming connections we allow per IP.
std::size_t inPeers
The number of automatic inbound connections to maintain.
void applyTuning()
Adjusts the values so they follow the business rules.
static Config makeConfig(ripple::Config const &config, std::uint16_t port, bool validationPublicKey, int ipLimit)
Make PeerFinder::Config from configuration parameters.
std::size_t maxPeers
The largest number of public peer slots to allow.
std::string features
The set of features we advertise.
bool wantIncoming
true if we want to accept incoming connections.
std::size_t outPeers
The number of automatic outbound connections to maintain.
std::size_t calcOutPeers() const
Returns a suitable value for outPeers according to the rules.
std::uint16_t listeningPort
The listening port number.
bool peerPrivate
true if we want our IP address kept private.
Describes a connectible peer address along with some metadata.