xrpld
Loading...
Searching...
No Matches
SlotImp.h
1#pragma once
2
3#include <xrpld/peerfinder/PeerfinderManager.h>
4#include <xrpld/peerfinder/Slot.h>
5
6#include <xrpl/beast/container/aged_unordered_map.h>
7
8#include <atomic>
9#include <optional>
10
11namespace xrpl::PeerFinder {
12
13class SlotImp : public Slot
14{
15public:
17
18 // inbound
19 SlotImp(
22 bool fixed,
23 clock_type& clock);
24
25 // outbound
27
28 bool
29 inbound() const override
30 {
31 return inbound_;
32 }
33
34 bool
35 fixed() const override
36 {
37 return fixed_;
38 }
39
40 bool
41 reserved() const override
42 {
43 return reserved_;
44 }
45
46 State
47 state() const override
48 {
49 return state_;
50 }
51
53 remoteEndpoint() const override
54 {
55 return remoteEndpoint_;
56 }
57
59 localEndpoint() const override
60 {
61 return localEndpoint_;
62 }
63
65 publicKey() const override
66 {
67 return publicKey_;
68 }
69
71 prefix() const
72 {
73 return "[" + getFingerprint(remoteEndpoint(), publicKey()) + "] ";
74 }
75
77 listeningPort() const override
78 {
79 std::uint32_t const value = listeningPort_;
80 if (value == kUnknownPort)
81 return std::nullopt;
82 return value;
83 }
84
85 void
87 {
88 listeningPort_ = port;
89 }
90
91 void
93 {
94 localEndpoint_ = endpoint;
95 }
96
97 void
99 {
100 remoteEndpoint_ = endpoint;
101 }
102
103 void
105 {
106 publicKey_ = key;
107 }
108
109 void
111 {
113 }
114
115 //--------------------------------------------------------------------------
116
117 void
119
120 void
122
123 // "Memberspace"
124 //
125 // The set of all recent addresses that we have seen from this peer.
126 // We try to avoid sending a peer the same addresses they gave us.
127 //
129 {
130 public:
131 explicit RecentT(clock_type& clock);
132
137 void
139
141 bool
143
144 private:
145 void
146 expire();
147
148 friend class SlotImp;
151
152 void
154 {
155 recent.expire();
156 }
157
158private:
159 bool const inbound_;
160 bool const fixed_;
166
167 static constexpr std::int32_t kUnknownPort = -1;
169
170public:
171 // DEPRECATED public data members
172
173 // Tells us if we checked the connection. Outbound connections
174 // are always considered checked since we successfully connected.
176
177 // Set to indicate if the connection can receive incoming at the
178 // address advertised in mtENDPOINTS. Only valid if checked is true.
180
181 // Set to indicate that a connection check for this peer is in
182 // progress. Valid always.
184
185 // The time after which we will accept mtENDPOINTS from the peer
186 // This is to prevent flooding or spamming. Receipt of mtENDPOINTS
187 // sooner than the allotted time should impose a load charge.
188 //
190};
191
192} // namespace xrpl::PeerFinder
std::chrono::steady_clock::time_point time_point
A version-independent IP address and port combination.
Definition IPEndpoint.h:17
beast::aged_unordered_map< beast::IP::Endpoint, std::uint32_t > cache_
Definition SlotImp.h:149
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:120
void insert(beast::IP::Endpoint const &ep, std::uint32_t hops)
Called for each valid endpoint received for a slot.
Definition SlotImp.cpp:105
static constexpr std::int32_t kUnknownPort
Definition SlotImp.h:167
bool fixed() const override
Returns true if this is a fixed connection.
Definition SlotImp.h:35
void localEndpoint(beast::IP::Endpoint const &endpoint)
Definition SlotImp.h:92
class xrpl::PeerFinder::SlotImp::RecentT recent
std::shared_ptr< SlotImp > ptr
Definition SlotImp.h:16
bool reserved() const override
Returns true if this is a reserved connection.
Definition SlotImp.h:41
SlotImp(beast::IP::Endpoint const &localEndpoint, beast::IP::Endpoint remoteEndpoint, bool fixed, clock_type &clock)
Definition SlotImp.cpp:16
std::string prefix() const
Definition SlotImp.h:71
void remoteEndpoint(beast::IP::Endpoint const &endpoint)
Definition SlotImp.h:98
std::atomic< std::int32_t > listeningPort_
Definition SlotImp.h:168
void setListeningPort(std::uint16_t port)
Definition SlotImp.h:86
std::optional< beast::IP::Endpoint > const & localEndpoint() const override
The local endpoint of the socket, when known.
Definition SlotImp.h:59
void reserved(bool reserved)
Definition SlotImp.h:110
State state() const override
Returns the state of the connection.
Definition SlotImp.h:47
std::optional< PublicKey > const & publicKey() const override
The peer's public key, when known.
Definition SlotImp.h:65
std::optional< PublicKey > publicKey_
Definition SlotImp.h:165
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:189
beast::IP::Endpoint const & remoteEndpoint() const override
The remote endpoint of socket.
Definition SlotImp.h:53
bool inbound() const override
Returns true if this is an inbound connection.
Definition SlotImp.h:29
beast::IP::Endpoint remoteEndpoint_
Definition SlotImp.h:163
std::optional< beast::IP::Endpoint > localEndpoint_
Definition SlotImp.h:164
void publicKey(PublicKey const &key)
Definition SlotImp.h:104
std::optional< std::uint16_t > listeningPort() const override
Definition SlotImp.h:77
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:83
Properties and state associated with a peer to peer overlay connection.
A public key.
Definition PublicKey.h:42
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:242