xrpld
Loading...
Searching...
No Matches
SlotImp.h
1#pragma once
2
3#include <xrpl/beast/container/aged_unordered_map.h>
4#include <xrpl/beast/net/IPEndpoint.h>
5#include <xrpl/peerfinder/Slot.h>
6#include <xrpl/peerfinder/Types.h>
7#include <xrpl/protocol/PublicKey.h>
8
9#include <atomic>
10#include <cstdint>
11#include <memory>
12#include <optional>
13#include <string>
14
15namespace xrpl::peer_finder {
16
17class SlotImp : public Slot
18{
19public:
21
22 // inbound
23 SlotImp(
26 bool fixed,
27 clock_type& clock);
28
29 // outbound
31
32 bool
33 inbound() const override
34 {
35 return inbound_;
36 }
37
38 bool
39 fixed() const override
40 {
41 return fixed_;
42 }
43
44 bool
45 reserved() const override
46 {
47 return reserved_;
48 }
49
50 State
51 state() const override
52 {
53 return state_;
54 }
55
57 remoteEndpoint() const override
58 {
59 return remoteEndpoint_;
60 }
61
63 localEndpoint() const override
64 {
65 return localEndpoint_;
66 }
67
69 publicKey() const override
70 {
71 return publicKey_;
72 }
73
75 prefix() const
76 {
77 return "[" + getFingerprint(remoteEndpoint(), publicKey()) + "] ";
78 }
79
81 listeningPort() const override
82 {
83 std::uint32_t const value = listeningPort_;
84 if (value == kUnknownPort)
85 return std::nullopt;
86 return value;
87 }
88
89 void
91 {
92 listeningPort_ = port;
93 }
94
95 void
97 {
98 localEndpoint_ = endpoint;
99 }
100
101 void
103 {
104 remoteEndpoint_ = endpoint;
105 }
106
107 void
109 {
110 publicKey_ = key;
111 }
112
113 void
115 {
117 }
118
119 //--------------------------------------------------------------------------
120
121 void
123
124 void
126
127 // "Memberspace"
128 //
129 // The set of all recent addresses that we have seen from this peer.
130 // We try to avoid sending a peer the same addresses they gave us.
131 //
133 {
134 public:
135 explicit RecentT(clock_type& clock);
136
142 void
144
148 bool
150
151 private:
152 void
153 expire();
154
155 friend class SlotImp;
158
159 void
161 {
162 recent.expire();
163 }
164
165private:
166 bool const inbound_;
167 bool const fixed_;
173
174 static std::int32_t constexpr kUnknownPort = -1;
176
177public:
178 // DEPRECATED public data members
179
180 // Tells us if we checked the connection. Outbound connections
181 // are always considered checked since we successfully connected.
183
184 // Set to indicate if the connection can receive incoming at the
185 // address advertised in mtENDPOINTS. Only valid if checked is true.
187
188 // Set to indicate that a connection check for this peer is in
189 // progress. Valid always.
191
192 // The time after which we will accept mtENDPOINTS from the peer
193 // This is to prevent flooding or spamming. Receipt of mtENDPOINTS
194 // sooner than the allotted time should impose a load charge.
195 //
197};
198
199} // namespace xrpl::peer_finder
std::chrono::steady_clock::time_point time_point
A version-independent IP address and port combination.
Definition IPEndpoint.h:24
A public key.
Definition PublicKey.h:53
bool filter(beast::ip::Endpoint const &ep, std::uint32_t hops)
Returns true if we should not send endpoint to the slot.
Definition SlotImp.cpp:118
void insert(beast::ip::Endpoint const &ep, std::uint32_t hops)
Called for each valid endpoint received for a slot.
Definition SlotImp.cpp:103
beast::aged_unordered_map< beast::ip::Endpoint, std::uint32_t > cache_
Definition SlotImp.h:156
std::atomic< std::int32_t > listeningPort_
Definition SlotImp.h:175
void reserved(bool reserved)
Definition SlotImp.h:114
class xrpl::peer_finder::SlotImp::RecentT recent
std::shared_ptr< SlotImp > ptr
Definition SlotImp.h:20
std::optional< beast::ip::Endpoint > const & localEndpoint() const override
The local endpoint of the socket, when known.
Definition SlotImp.h:63
State state() const override
Returns the state of the connection.
Definition SlotImp.h:51
std::optional< PublicKey > const & publicKey() const override
The peer's public key, when known.
Definition SlotImp.h:69
beast::ip::Endpoint const & remoteEndpoint() const override
The remote endpoint of socket.
Definition SlotImp.h:57
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:196
std::optional< PublicKey > publicKey_
Definition SlotImp.h:172
SlotImp(beast::ip::Endpoint const &localEndpoint, beast::ip::Endpoint remoteEndpoint, bool fixed, clock_type &clock)
Definition SlotImp.cpp:14
void setListeningPort(std::uint16_t port)
Definition SlotImp.h:90
void localEndpoint(beast::ip::Endpoint const &endpoint)
Definition SlotImp.h:96
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:81
std::string prefix() const
Definition SlotImp.h:75
bool reserved() const override
Returns true if this is a reserved connection.
Definition SlotImp.h:45
std::optional< beast::ip::Endpoint > localEndpoint_
Definition SlotImp.h:171
void remoteEndpoint(beast::ip::Endpoint const &endpoint)
Definition SlotImp.h:102
bool fixed() const override
Returns true if this is a fixed connection.
Definition SlotImp.h:39
bool inbound() const override
Returns true if this is an inbound connection.
Definition SlotImp.h:33
static std::int32_t constexpr kUnknownPort
Definition SlotImp.h:174
std::optional< std::uint16_t > listeningPort() const override
Definition SlotImp.h:81
beast::ip::Endpoint remoteEndpoint_
Definition SlotImp.h:170
void publicKey(PublicKey const &key)
Definition SlotImp.h:108
Properties and state associated with a peer to peer overlay connection.
detail::AgedUnorderedContainer< false, true, Key, T, Clock, Hash, KeyEqual, Allocator > aged_unordered_map
beast::AbstractClock< std::chrono::steady_clock > clock_type
std::string getFingerprint(beast::ip::Endpoint const &address, std::optional< PublicKey > const &publicKey=std::nullopt, std::optional< std::string > const &id=std::nullopt)
Definition PublicKey.h:262