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 ripple {
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
28 beast::IP::Endpoint const& remote_endpoint,
29 bool fixed,
30 clock_type& clock)
31 : recent(clock)
32 , m_inbound(false)
33 , m_fixed(fixed)
34 , m_reserved(false)
35 , m_state(connect)
36 , m_remote_endpoint(remote_endpoint)
37 , m_listening_port(unknownPort)
38 , checked(true)
39 , canAccept(true)
40 , connectivityCheckInProgress(false)
41{
42}
43
44void
46{
47 // Must go through activate() to set active state
48 XRPL_ASSERT(
49 state_ != active,
50 "ripple::PeerFinder::SlotImp::state : input state is not active");
51
52 // The state must be different
53 XRPL_ASSERT(
54 state_ != m_state,
55 "ripple::PeerFinder::SlotImp::state : input state is different from "
56 "current");
57
58 // You can't transition into the initial states
59 XRPL_ASSERT(
60 state_ != accept && state_ != connect,
61 "ripple::PeerFinder::SlotImp::state : input state is not an initial");
62
63 // Can only become connected from outbound connect state
64 XRPL_ASSERT(
65 state_ != connected || (!m_inbound && m_state == connect),
66 "ripple::PeerFinder::SlotImp::state : input state is not connected an "
67 "invalid state");
68
69 // Can't gracefully close on an outbound connection attempt
70 XRPL_ASSERT(
71 state_ != closing || m_state != connect,
72 "ripple::PeerFinder::SlotImp::state : input state is not closing an "
73 "invalid state");
74
75 m_state = state_;
76}
77
78void
80{
81 // Can only become active from the accept or connected state
82 XRPL_ASSERT(
84 "ripple::PeerFinder::SlotImp::activate : valid state");
85
88}
89
90//------------------------------------------------------------------------------
91
92Slot::~Slot() = default;
93
94//------------------------------------------------------------------------------
95
97{
98}
99
100void
102{
103 auto const result(cache.emplace(ep, hops));
104 if (!result.second)
105 {
106 // NOTE Other logic depends on this <= inequality.
107 if (hops <= result.first->second)
108 {
109 result.first->second = hops;
110 cache.touch(result.first);
111 }
112 }
113}
114
115bool
117{
118 auto const iter(cache.find(ep));
119 if (iter == cache.end())
120 return false;
121 // We avoid sending an endpoint if we heard it
122 // from them recently at the same or lower hop count.
123 // NOTE Other logic depends on this <= inequality.
124 return iter->second <= hops;
125}
126
127void
132
133} // namespace PeerFinder
134} // namespace ripple
A version-independent IP address and port combination.
Definition IPEndpoint.h:19
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
void insert(beast::IP::Endpoint const &ep, std::uint32_t hops)
Called for each valid endpoint received for a slot.
Definition SlotImp.cpp:101
void activate(clock_type::time_point const &now)
Definition SlotImp.cpp:79
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:52
clock_type::time_point whenAcceptEndpoints
Definition SlotImp.h:194
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