rippled
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 {
12namespace PeerFinder {
13
14class SlotImp : public Slot
15{
16public:
18
19 // inbound
20 SlotImp(
23 bool fixed,
24 clock_type& clock);
25
26 // outbound
28
29 bool
30 inbound() const override
31 {
32 return m_inbound;
33 }
34
35 bool
36 fixed() const override
37 {
38 return m_fixed;
39 }
40
41 bool
42 reserved() const override
43 {
44 return m_reserved;
45 }
46
47 State
48 state() const override
49 {
50 return m_state;
51 }
52
54 remote_endpoint() const override
55 {
56 return m_remote_endpoint;
57 }
58
60 local_endpoint() const override
61 {
62 return m_local_endpoint;
63 }
64
66 public_key() const override
67 {
68 return m_public_key;
69 }
70
72 prefix() const
73 {
74 return "[" + getFingerprint(remote_endpoint(), public_key()) + "] ";
75 }
76
78 listening_port() const override
79 {
80 std::uint32_t const value = m_listening_port;
81 if (value == unknownPort)
82 return std::nullopt;
83 return value;
84 }
85
86 void
91
92 void
94 {
95 m_local_endpoint = endpoint;
96 }
97
98 void
100 {
101 m_remote_endpoint = endpoint;
102 }
103
104 void
106 {
107 m_public_key = key;
108 }
109
110 void
111 reserved(bool reserved_)
112 {
113 m_reserved = reserved_;
114 }
115
116 //--------------------------------------------------------------------------
117
118 void
119 state(State state_);
120
121 void
123
124 // "Memberspace"
125 //
126 // The set of all recent addresses that we have seen from this peer.
127 // We try to avoid sending a peer the same addresses they gave us.
128 //
130 {
131 public:
132 explicit recent_t(clock_type& clock);
133
138 void
140
142 bool
144
145 private:
146 void
147 expire();
148
149 friend class SlotImp;
152
153 void
155 {
156 recent.expire();
157 }
158
159private:
160 bool const m_inbound;
161 bool const m_fixed;
167
168 static std::int32_t constexpr unknownPort = -1;
170
171public:
172 // DEPRECATED public data members
173
174 // Tells us if we checked the connection. Outbound connections
175 // are always considered checked since we successfully connected.
177
178 // Set to indicate if the connection can receive incoming at the
179 // address advertised in mtENDPOINTS. Only valid if checked is true.
181
182 // Set to indicate that a connection check for this peer is in
183 // progress. Valid always.
185
186 // The time after which we will accept mtENDPOINTS from the peer
187 // This is to prevent flooding or spamming. Receipt of mtENDPOINTS
188 // sooner than the allotted time should impose a load charge.
189 //
191};
192
193} // namespace PeerFinder
194} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:18
Associative container where each element is also indexed by time.
void insert(beast::IP::Endpoint const &ep, std::uint32_t hops)
Called for each valid endpoint received for a slot.
Definition SlotImp.cpp:93
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:108
beast::aged_unordered_map< beast::IP::Endpoint, std::uint32_t > cache
Definition SlotImp.h:150
std::optional< beast::IP::Endpoint > const & local_endpoint() const override
The local endpoint of the socket, when known.
Definition SlotImp.h:60
void local_endpoint(beast::IP::Endpoint const &endpoint)
Definition SlotImp.h:93
class xrpl::PeerFinder::SlotImp::recent_t recent
bool fixed() const override
Returns true if this is a fixed connection.
Definition SlotImp.h:36
void set_listening_port(std::uint16_t port)
Definition SlotImp.h:87
void reserved(bool reserved_)
Definition SlotImp.h:111
bool reserved() const override
Returns true if this is a reserved connection.
Definition SlotImp.h:42
beast::IP::Endpoint const & remote_endpoint() const override
The remote endpoint of socket.
Definition SlotImp.h:54
void remote_endpoint(beast::IP::Endpoint const &endpoint)
Definition SlotImp.h:99
std::string prefix() const
Definition SlotImp.h:72
std::atomic< std::int32_t > m_listening_port
Definition SlotImp.h:169
std::optional< std::uint16_t > listening_port() const override
Definition SlotImp.h:78
std::optional< PublicKey > const & public_key() const override
The peer's public key, when known.
Definition SlotImp.h:66
std::optional< PublicKey > m_public_key
Definition SlotImp.h:166
State state() const override
Returns the state of the connection.
Definition SlotImp.h:48
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:190
static std::int32_t constexpr unknownPort
Definition SlotImp.h:168
bool inbound() const override
Returns true if this is an inbound connection.
Definition SlotImp.h:30
void public_key(PublicKey const &key)
Definition SlotImp.h:105
beast::IP::Endpoint m_remote_endpoint
Definition SlotImp.h:164
std::optional< beast::IP::Endpoint > m_local_endpoint
Definition SlotImp.h:165
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:73
Properties and state associated with a peer to peer overlay connection.
A public key.
Definition PublicKey.h:42
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
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:241