rippled
Loading...
Searching...
No Matches
SlotImp.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_SLOTIMP_H_INCLUDED
21#define RIPPLE_PEERFINDER_SLOTIMP_H_INCLUDED
22
23#include <xrpld/peerfinder/PeerfinderManager.h>
24#include <xrpld/peerfinder/Slot.h>
25
26#include <xrpl/beast/container/aged_unordered_map.h>
27
28#include <atomic>
29#include <optional>
30
31namespace ripple {
32namespace PeerFinder {
33
34class SlotImp : public Slot
35{
36public:
38
39 // inbound
40 SlotImp(
43 bool fixed,
44 clock_type& clock);
45
46 // outbound
47 SlotImp(
49 bool fixed,
50 clock_type& clock);
51
52 bool
53 inbound() const override
54 {
55 return m_inbound;
56 }
57
58 bool
59 fixed() const override
60 {
61 return m_fixed;
62 }
63
64 bool
65 reserved() const override
66 {
67 return m_reserved;
68 }
69
70 State
71 state() const override
72 {
73 return m_state;
74 }
75
77 remote_endpoint() const override
78 {
79 return m_remote_endpoint;
80 }
81
83 local_endpoint() const override
84 {
85 return m_local_endpoint;
86 }
87
89 public_key() const override
90 {
91 return m_public_key;
92 }
93
95 listening_port() const override
96 {
97 std::uint32_t const value = m_listening_port;
98 if (value == unknownPort)
99 return std::nullopt;
100 return value;
101 }
102
103 void
105 {
106 m_listening_port = port;
107 }
108
109 void
111 {
112 m_local_endpoint = endpoint;
113 }
114
115 void
117 {
118 m_remote_endpoint = endpoint;
119 }
120
121 void
123 {
124 m_public_key = key;
125 }
126
127 void
128 reserved(bool reserved_)
129 {
130 m_reserved = reserved_;
131 }
132
133 //--------------------------------------------------------------------------
134
135 void
136 state(State state_);
137
138 void
140
141 // "Memberspace"
142 //
143 // The set of all recent addresses that we have seen from this peer.
144 // We try to avoid sending a peer the same addresses they gave us.
145 //
147 {
148 public:
149 explicit recent_t(clock_type& clock);
150
155 void
157
159 bool
161
162 private:
163 void
164 expire();
165
166 friend class SlotImp;
169
170 void
172 {
173 recent.expire();
174 }
175
176private:
177 bool const m_inbound;
178 bool const m_fixed;
184
185 static std::int32_t constexpr unknownPort = -1;
187
188public:
189 // DEPRECATED public data members
190
191 // Tells us if we checked the connection. Outbound connections
192 // are always considered checked since we successfuly connected.
194
195 // Set to indicate if the connection can receive incoming at the
196 // address advertised in mtENDPOINTS. Only valid if checked is true.
198
199 // Set to indicate that a connection check for this peer is in
200 // progress. Valid always.
202
203 // The time after which we will accept mtENDPOINTS from the peer
204 // This is to prevent flooding or spamming. Receipt of mtENDPOINTS
205 // sooner than the allotted time should impose a load charge.
206 //
208};
209
210} // namespace PeerFinder
211} // namespace ripple
212
213#endif
A version-independent IP address and port combination.
Definition IPEndpoint.h:38
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:135
beast::aged_unordered_map< beast::IP::Endpoint, std::uint32_t > cache
Definition SlotImp.h:167
void insert(beast::IP::Endpoint const &ep, std::uint32_t hops)
Called for each valid endpoint received for a slot.
Definition SlotImp.cpp:120
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:83
void local_endpoint(beast::IP::Endpoint const &endpoint)
Definition SlotImp.h:110
bool fixed() const override
Returns true if this is a fixed connection.
Definition SlotImp.h:59
std::optional< std::uint16_t > listening_port() const override
Definition SlotImp.h:95
std::atomic< std::int32_t > m_listening_port
Definition SlotImp.h:186
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:98
static std::int32_t constexpr unknownPort
Definition SlotImp.h:185
bool inbound() const override
Returns true if this is an inbound connection.
Definition SlotImp.h:53
void public_key(PublicKey const &key)
Definition SlotImp.h:122
beast::IP::Endpoint m_remote_endpoint
Definition SlotImp.h:181
void reserved(bool reserved_)
Definition SlotImp.h:128
std::optional< beast::IP::Endpoint > m_local_endpoint
Definition SlotImp.h:182
void set_listening_port(std::uint16_t port)
Definition SlotImp.h:104
State state() const override
Returns the state of the connection.
Definition SlotImp.h:71
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:207
std::optional< PublicKey > m_public_key
Definition SlotImp.h:183
std::optional< PublicKey > const & public_key() const override
The peer's public key, when known.
Definition SlotImp.h:89
void remote_endpoint(beast::IP::Endpoint const &endpoint)
Definition SlotImp.h:116
beast::IP::Endpoint const & remote_endpoint() const override
The remote endpoint of socket.
Definition SlotImp.h:77
bool reserved() const override
Returns true if this is a reserved connection.
Definition SlotImp.h:65
Properties and state associated with a peer to peer overlay connection.
A public key.
Definition PublicKey.h:61
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25