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