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