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
26#include <xrpl/beast/clock/abstract_clock.h>
27#include <xrpl/beast/utility/PropertyStream.h>
28
29#include <boost/asio/ip/tcp.hpp>
30
31namespace ripple {
32namespace PeerFinder {
33
35
38
39//------------------------------------------------------------------------------
40
42struct Config
43{
49
55
61
63 bool peerPrivate = true;
64
67
70
73
76
79
80 //--------------------------------------------------------------------------
81
83 Config();
84
87 calcOutPeers() const;
88
90 void
92
94 void
96
104 static Config
106 ripple::Config const& config,
107 std::uint16_t port,
108 bool validationPublicKey,
109 int ipLimit);
110};
111
112//------------------------------------------------------------------------------
113
116{
117 Endpoint() = default;
118
120
123};
124
125inline bool
126operator<(Endpoint const& lhs, Endpoint const& rhs)
127{
128 return lhs.address < rhs.address;
129}
130
133
134//------------------------------------------------------------------------------
135
137enum class Result { duplicate, full, success };
138
141{
142protected:
143 Manager() noexcept;
144
145public:
151 virtual ~Manager() = default;
152
158 virtual void
160
162 virtual void
163 start() = 0;
164
166 virtual void
167 stop() = 0;
168
170 virtual Config
171 config() = 0;
172
178 virtual void
180 std::string const& name,
181 std::vector<beast::IP::Endpoint> const& addresses) = 0;
182
186 virtual void
188 std::string const& name,
189 std::vector<std::string> const& strings) = 0;
190
194 /* VFALCO NOTE Unimplemented
195 virtual void addFallbackURL (std::string const& name,
196 std::string const& url) = 0;
197 */
198
199 //--------------------------------------------------------------------------
200
207 beast::IP::Endpoint const& local_endpoint,
208 beast::IP::Endpoint const& remote_endpoint) = 0;
209
215 new_outbound_slot(beast::IP::Endpoint const& remote_endpoint) = 0;
216
218 virtual void
220 std::shared_ptr<Slot> const& slot,
221 Endpoints const& endpoints) = 0;
222
227 virtual void
229
231 virtual void
233
235 virtual void
237 boost::asio::ip::tcp::endpoint const& remote_address,
239
240 //--------------------------------------------------------------------------
241
249 virtual bool
251 std::shared_ptr<Slot> const& slot,
252 beast::IP::Endpoint const& local_endpoint) = 0;
253
255 virtual Result
257 std::shared_ptr<Slot> const& slot,
258 PublicKey const& key,
259 bool reserved) = 0;
260
264
268
271
275 virtual void
277};
278
279} // namespace PeerFinder
280} // namespace ripple
281
282#endif
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
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:61
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:25
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.