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