rippled
Loading...
Searching...
No Matches
SlotImp.cpp
1#include <xrpld/peerfinder/PeerfinderManager.h>
2#include <xrpld/peerfinder/detail/SlotImp.h>
3#include <xrpld/peerfinder/detail/Tuning.h>
4
5namespace xrpl {
6namespace PeerFinder {
7
9 beast::IP::Endpoint const& local_endpoint,
10 beast::IP::Endpoint const& remote_endpoint,
11 bool fixed,
12 clock_type& clock)
13 : recent(clock)
14 , m_inbound(true)
15 , m_fixed(fixed)
16 , m_reserved(false)
17 , m_state(accept)
18 , m_remote_endpoint(remote_endpoint)
19 , m_local_endpoint(local_endpoint)
20 , m_listening_port(unknownPort)
21 , checked(false)
22 , canAccept(false)
23 , connectivityCheckInProgress(false)
24{
25}
26
27SlotImp::SlotImp(beast::IP::Endpoint const& remote_endpoint, bool fixed, clock_type& clock)
28 : recent(clock)
29 , m_inbound(false)
30 , m_fixed(fixed)
31 , m_reserved(false)
32 , m_state(connect)
33 , m_remote_endpoint(remote_endpoint)
34 , m_listening_port(unknownPort)
35 , checked(true)
36 , canAccept(true)
37 , connectivityCheckInProgress(false)
38{
39}
40
41void
43{
44 // Must go through activate() to set active state
45 XRPL_ASSERT(state_ != active, "xrpl::PeerFinder::SlotImp::state : input state is not active");
46
47 // The state must be different
48 XRPL_ASSERT(
49 state_ != m_state,
50 "xrpl::PeerFinder::SlotImp::state : input state is different from "
51 "current");
52
53 // You can't transition into the initial states
54 XRPL_ASSERT(
55 state_ != accept && state_ != connect, "xrpl::PeerFinder::SlotImp::state : input state is not an initial");
56
57 // Can only become connected from outbound connect state
58 XRPL_ASSERT(
59 state_ != connected || (!m_inbound && m_state == connect),
60 "xrpl::PeerFinder::SlotImp::state : input state is not connected an "
61 "invalid state");
62
63 // Can't gracefully close on an outbound connection attempt
64 XRPL_ASSERT(
65 state_ != closing || m_state != connect,
66 "xrpl::PeerFinder::SlotImp::state : input state is not closing an "
67 "invalid state");
68
69 m_state = state_;
70}
71
72void
74{
75 // Can only become active from the accept or connected state
76 XRPL_ASSERT(m_state == accept || m_state == connected, "xrpl::PeerFinder::SlotImp::activate : valid state");
77
80}
81
82//------------------------------------------------------------------------------
83
84Slot::~Slot() = default;
85
86//------------------------------------------------------------------------------
87
89{
90}
91
92void
94{
95 auto const result(cache.emplace(ep, hops));
96 if (!result.second)
97 {
98 // NOTE Other logic depends on this <= inequality.
99 if (hops <= result.first->second)
100 {
101 result.first->second = hops;
102 cache.touch(result.first);
103 }
104 }
105}
106
107bool
109{
110 auto const iter(cache.find(ep));
111 if (iter == cache.end())
112 return false;
113 // We avoid sending an endpoint if we heard it
114 // from them recently at the same or lower hop count.
115 // NOTE Other logic depends on this <= inequality.
116 return iter->second <= hops;
117}
118
119void
124
125} // namespace PeerFinder
126} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:19
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
SlotImp(beast::IP::Endpoint const &local_endpoint, beast::IP::Endpoint const &remote_endpoint, bool fixed, clock_type &clock)
Definition SlotImp.cpp:8
State state() const override
Returns the state of the connection.
Definition SlotImp.h:49
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:191
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:73
std::enable_if< is_aged_container< AgedContainer >::value, std::size_t >::type expire(AgedContainer &c, std::chrono::duration< Rep, Period > const &age)
Expire aged container items past the specified age.
std::chrono::seconds constexpr liveCacheSecondsToLive(30)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
static FunctionType fixed(Keylet const &keylet)