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,
56 "xrpl::PeerFinder::SlotImp::state : input state is not an initial");
57
58 // Can only become connected from outbound connect state
59 XRPL_ASSERT(
60 state_ != connected || (!m_inbound && m_state == connect),
61 "xrpl::PeerFinder::SlotImp::state : input state is not connected an "
62 "invalid state");
63
64 // Can't gracefully close on an outbound connection attempt
65 XRPL_ASSERT(
66 state_ != closing || m_state != connect,
67 "xrpl::PeerFinder::SlotImp::state : input state is not closing an "
68 "invalid state");
69
70 m_state = state_;
71}
72
73void
75{
76 // Can only become active from the accept or connected state
77 XRPL_ASSERT(
79 "xrpl::PeerFinder::SlotImp::activate : valid state");
80
83}
84
85//------------------------------------------------------------------------------
86
87Slot::~Slot() = default;
88
89//------------------------------------------------------------------------------
90
92{
93}
94
95void
97{
98 auto const result(cache.emplace(ep, hops));
99 if (!result.second)
100 {
101 // NOTE Other logic depends on this <= inequality.
102 if (hops <= result.first->second)
103 {
104 result.first->second = hops;
105 cache.touch(result.first);
106 }
107 }
108}
109
110bool
112{
113 auto const iter(cache.find(ep));
114 if (iter == cache.end())
115 return false;
116 // We avoid sending an endpoint if we heard it
117 // from them recently at the same or lower hop count.
118 // NOTE Other logic depends on this <= inequality.
119 return iter->second <= hops;
120}
121
122void
127
128} // namespace PeerFinder
129} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:18
void insert(beast::IP::Endpoint const &ep, std::uint32_t hops)
Called for each valid endpoint received for a slot.
Definition SlotImp.cpp:96
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:111
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:48
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:190
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:74
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:5
static FunctionType fixed(Keylet const &keylet)