rippled
Loading...
Searching...
No Matches
Bootcache.h
1#pragma once
2
3#include <xrpld/peerfinder/PeerfinderManager.h>
4#include <xrpld/peerfinder/detail/Store.h>
5
6#include <xrpl/basics/comparators.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/beast/utility/PropertyStream.h>
9
10#include <boost/bimap.hpp>
11#include <boost/bimap/multiset_of.hpp>
12#include <boost/bimap/unordered_set_of.hpp>
13#include <boost/iterator/transform_iterator.hpp>
14
15namespace xrpl {
16namespace PeerFinder {
17
34{
35private:
36 class Entry
37 {
38 public:
40 {
41 }
42
43 int&
45 {
46 return m_valence;
47 }
48
49 int
50 valence() const
51 {
52 return m_valence;
53 }
54
55 friend bool
56 operator<(Entry const& lhs, Entry const& rhs)
57 {
58 if (lhs.valence() > rhs.valence())
59 return true;
60 return false;
61 }
62
63 private:
65 };
66
67 using left_t = boost::bimaps::unordered_set_of<
69 boost::hash<beast::IP::Endpoint>,
71 using right_t = boost::bimaps::multiset_of<Entry, xrpl::less<Entry>>;
72 using map_type = boost::bimap<left_t, right_t>;
73 using value_type = map_type::value_type;
74
75 struct Transform
76 {
77 using first_argument_type = map_type::right_map::const_iterator::value_type const&;
79
80 explicit Transform() = default;
81
83 operator()(map_type::right_map::const_iterator::value_type const& v) const
84 {
85 return v.get_left();
86 }
87 };
88
89private:
91
95
96 // Time after which we can update the database again
98
99 // Set to true when a database update is needed
100 bool m_needsUpdate{false};
101
102public:
103 static constexpr int staticValence = 32;
104
105 using iterator = boost::transform_iterator<Transform, map_type::right_map::const_iterator>;
106
108
109 Bootcache(Store& store, clock_type& clock, beast::Journal journal);
110
111 ~Bootcache();
112
114 bool
115 empty() const;
116
118 map_type::size_type
119 size() const;
120
124 begin() const;
126 cbegin() const;
128 end() const;
130 cend() const;
131 void
132 clear();
136 void
137 load();
138
140 bool
141 insert(beast::IP::Endpoint const& endpoint);
142
144 bool
145 insertStatic(beast::IP::Endpoint const& endpoint);
146
148 void
149 on_success(beast::IP::Endpoint const& endpoint);
150
152 void
153 on_failure(beast::IP::Endpoint const& endpoint);
154
156 void
158
160 void
162
163private:
164 void
165 prune();
166 void
167 update();
168 void
169 checkUpdate();
170 void
172};
173
174} // namespace PeerFinder
175} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:18
A generic endpoint for log messages.
Definition Journal.h:40
friend bool operator<(Entry const &lhs, Entry const &rhs)
Definition Bootcache.h:56
Stores IP addresses useful for gaining initial connections.
Definition Bootcache.h:34
void on_failure(beast::IP::Endpoint const &endpoint)
Called when an outbound connection attempt fails to handshake.
bool insert(beast::IP::Endpoint const &endpoint)
Add a newly-learned address to the cache.
Definition Bootcache.cpp:89
boost::transform_iterator< Transform, map_type::right_map::const_iterator > iterator
Definition Bootcache.h:105
void periodicActivity()
Stores the cache in the persistent database on a timer.
boost::bimaps::unordered_set_of< beast::IP::Endpoint, boost::hash< beast::IP::Endpoint >, xrpl::equal_to< beast::IP::Endpoint > > left_t
Definition Bootcache.h:70
void on_success(beast::IP::Endpoint const &endpoint)
Called when an outbound connection handshake completes.
boost::bimap< left_t, right_t > map_type
Definition Bootcache.h:72
const_iterator cbegin() const
Definition Bootcache.cpp:42
beast::Journal m_journal
Definition Bootcache.h:94
const_iterator cend() const
Definition Bootcache.cpp:54
void onWrite(beast::PropertyStream::Map &map)
Write the cache state to the property stream.
map_type::value_type value_type
Definition Bootcache.h:73
const_iterator begin() const
IP::Endpoint iterators that traverse in decreasing valence.
Definition Bootcache.cpp:36
void load()
Load the persisted data from the Store into the container.
Definition Bootcache.cpp:69
bool insertStatic(beast::IP::Endpoint const &endpoint)
Add a staticallyconfigured address to the cache.
const_iterator end() const
Definition Bootcache.cpp:48
bool empty() const
Returns true if the cache is empty.
Definition Bootcache.cpp:24
boost::bimaps::multiset_of< Entry, xrpl::less< Entry > > right_t
Definition Bootcache.h:71
clock_type::time_point m_whenUpdate
Definition Bootcache.h:97
map_type::size_type size() const
Returns the number of entries in the cache.
Definition Bootcache.cpp:30
static constexpr int staticValence
Definition Bootcache.h:103
Abstract persistence for PeerFinder data.
Definition Store.h:8
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
map_type::right_map::const_iterator::value_type const & first_argument_type
Definition Bootcache.h:77
beast::IP::Endpoint const & operator()(map_type::right_map::const_iterator::value_type const &v) const
Definition Bootcache.h:83
beast::IP::Endpoint const & result_type
Definition Bootcache.h:78