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::
68 unordered_set_of<beast::IP::Endpoint, boost::hash<beast::IP::Endpoint>, xrpl::equal_to<beast::IP::Endpoint>>;
69 using right_t = boost::bimaps::multiset_of<Entry, xrpl::less<Entry>>;
70 using map_type = boost::bimap<left_t, right_t>;
71 using value_type = map_type::value_type;
72
73 struct Transform
74 {
75 using first_argument_type = map_type::right_map::const_iterator::value_type const&;
77
78 explicit Transform() = default;
79
81 operator()(map_type::right_map::const_iterator::value_type const& v) const
82 {
83 return v.get_left();
84 }
85 };
86
87private:
89
93
94 // Time after which we can update the database again
96
97 // Set to true when a database update is needed
99
100public:
101 static constexpr int staticValence = 32;
102
103 using iterator = boost::transform_iterator<Transform, map_type::right_map::const_iterator>;
104
106
107 Bootcache(Store& store, clock_type& clock, beast::Journal journal);
108
109 ~Bootcache();
110
112 bool
113 empty() const;
114
116 map_type::size_type
117 size() const;
118
122 begin() const;
124 cbegin() const;
126 end() const;
128 cend() const;
129 void
130 clear();
134 void
135 load();
136
138 bool
139 insert(beast::IP::Endpoint const& endpoint);
140
142 bool
143 insertStatic(beast::IP::Endpoint const& endpoint);
144
146 void
147 on_success(beast::IP::Endpoint const& endpoint);
148
150 void
151 on_failure(beast::IP::Endpoint const& endpoint);
152
154 void
156
158 void
160
161private:
162 void
163 prune();
164 void
165 update();
166 void
167 checkUpdate();
168 void
170};
171
172} // namespace PeerFinder
173} // 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:85
boost::transform_iterator< Transform, map_type::right_map::const_iterator > iterator
Definition Bootcache.h:103
void periodicActivity()
Stores the cache in the persistent database on a timer.
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:70
const_iterator cbegin() const
Definition Bootcache.cpp:39
beast::Journal m_journal
Definition Bootcache.h:92
const_iterator cend() const
Definition Bootcache.cpp:51
boost::bimaps::unordered_set_of< beast::IP::Endpoint, boost::hash< beast::IP::Endpoint >, xrpl::equal_to< beast::IP::Endpoint > > left_t
Definition Bootcache.h:68
void onWrite(beast::PropertyStream::Map &map)
Write the cache state to the property stream.
map_type::value_type value_type
Definition Bootcache.h:71
const_iterator begin() const
IP::Endpoint iterators that traverse in decreasing valence.
Definition Bootcache.cpp:33
void load()
Load the persisted data from the Store into the container.
Definition Bootcache.cpp:66
bool insertStatic(beast::IP::Endpoint const &endpoint)
Add a staticallyconfigured address to the cache.
Definition Bootcache.cpp:98
const_iterator end() const
Definition Bootcache.cpp:45
bool empty() const
Returns true if the cache is empty.
Definition Bootcache.cpp:21
boost::bimaps::multiset_of< Entry, xrpl::less< Entry > > right_t
Definition Bootcache.h:69
clock_type::time_point m_whenUpdate
Definition Bootcache.h:95
map_type::size_type size() const
Returns the number of entries in the cache.
Definition Bootcache.cpp:27
static constexpr int staticValence
Definition Bootcache.h:101
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:75
beast::IP::Endpoint const & operator()(map_type::right_map::const_iterator::value_type const &v) const
Definition Bootcache.h:81
beast::IP::Endpoint const & result_type
Definition Bootcache.h:76