xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
peerfinder
detail
Bootcache.h
1
#pragma once
2
3
#include <xrpl/beast/net/IPEndpoint.h>
4
#include <xrpl/beast/utility/Journal.h>
5
#include <xrpl/beast/utility/PropertyStream.h>
6
#include <xrpl/peerfinder/Types.h>
7
#include <xrpl/peerfinder/detail/Store.h>
8
#include <xrpl/peerfinder/detail/Tuning.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
15
#include <
functional
>
16
17
namespace
xrpl::peer_finder
{
18
35
class
Bootcache
36
{
37
private
:
38
class
Entry
39
{
40
public
:
41
Entry
(
int
valence
) :
valence_
(
valence
)
42
{
43
}
44
45
int
&
46
valence
()
47
{
48
return
valence_
;
49
}
50
51
[[nodiscard]]
int
52
valence
()
const
53
{
54
return
valence_
;
55
}
56
57
friend
bool
58
operator<
(
Entry
const
& lhs,
Entry
const
& rhs)
59
{
60
return
lhs.
valence
() > rhs.
valence
();
61
}
62
63
private
:
64
int
valence_
;
65
};
66
67
using
LeftT
= boost::bimaps::
68
unordered_set_of<beast::ip::Endpoint, boost::hash<beast::ip::Endpoint>,
std::equal_to<>
>;
69
using
RightT
= boost::bimaps::multiset_of<Entry, std::less<>>;
70
using
MapType
= boost::bimap<LeftT, RightT>;
71
using
value_type
= MapType::value_type;
72
73
struct
Transform
74
{
75
using
first_argument_type
= MapType::right_map::const_iterator::value_type
const
&;
76
using
result_type
=
beast::ip::Endpoint
const
&;
77
78
explicit
Transform
() =
default
;
79
80
beast::ip::Endpoint
const
&
81
operator()
(MapType::right_map::const_iterator::value_type
const
& v)
const
82
{
83
return
v.get_left();
84
}
85
};
86
87
private
:
88
MapType
map_
;
89
90
Store
&
store_
;
91
ClockType
&
clock_
;
92
beast::Journal
journal_
;
93
94
// Time after which we can update the database again
95
ClockType::time_point
whenUpdate_
;
96
97
// Set to true when a database update is needed
98
bool
needsUpdate_
{
false
};
99
100
public
:
101
static
constexpr
int
kStaticValence
= 32;
102
103
using
iterator
= boost::transform_iterator<Transform, MapType::right_map::const_iterator>;
104
105
using
const_iterator
=
iterator
;
106
107
Bootcache
(
Store
& store,
ClockType
& clock,
beast::Journal
journal);
108
109
~Bootcache
();
110
114
[[nodiscard]]
bool
115
empty
()
const
;
116
120
[[nodiscard]] MapType::size_type
121
size
()
const
;
122
127
[[nodiscard]]
const_iterator
128
begin
()
const
;
129
[[nodiscard]]
const_iterator
130
cbegin
()
const
;
131
[[nodiscard]]
const_iterator
132
end
()
const
;
133
[[nodiscard]]
const_iterator
134
cend
()
const
;
135
void
136
clear
();
138
142
void
143
load
();
144
148
bool
149
insert
(
beast::ip::Endpoint
const
& endpoint);
150
154
bool
155
insertStatic
(
beast::ip::Endpoint
const
& endpoint);
156
160
void
161
onSuccess
(
beast::ip::Endpoint
const
& endpoint);
162
166
void
167
onFailure
(
beast::ip::Endpoint
const
& endpoint);
168
172
void
173
periodicActivity
();
174
178
void
179
onWrite
(
beast::PropertyStream::Map
& map);
180
181
private
:
182
void
183
prune
();
184
void
185
update
();
186
void
187
checkUpdate
();
188
void
189
flagForUpdate
();
190
};
191
192
}
// namespace xrpl::peer_finder
beast::AbstractClock< std::chrono::steady_clock >::time_point
std::chrono::steady_clock::time_point time_point
Definition
abstract_clock.h:41
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::PropertyStream::Map
Definition
PropertyStream.h:207
beast::ip::Endpoint
A version-independent IP address and port combination.
Definition
IPEndpoint.h:24
xrpl::peer_finder::Bootcache::Entry::valence_
int valence_
Definition
Bootcache.h:64
xrpl::peer_finder::Bootcache::Entry::Entry
Entry(int valence)
Definition
Bootcache.h:41
xrpl::peer_finder::Bootcache::Entry::operator<
friend bool operator<(Entry const &lhs, Entry const &rhs)
Definition
Bootcache.h:58
xrpl::peer_finder::Bootcache::Entry::valence
int valence() const
Definition
Bootcache.h:52
xrpl::peer_finder::Bootcache::Entry::valence
int & valence()
Definition
Bootcache.h:46
xrpl::peer_finder::Bootcache::kStaticValence
static constexpr int kStaticValence
Definition
Bootcache.h:101
xrpl::peer_finder::Bootcache::update
void update()
Definition
Bootcache.cpp:231
xrpl::peer_finder::Bootcache::const_iterator
iterator const_iterator
Definition
Bootcache.h:105
xrpl::peer_finder::Bootcache::clear
void clear()
Definition
Bootcache.cpp:69
xrpl::peer_finder::Bootcache::insertStatic
bool insertStatic(beast::ip::Endpoint const &endpoint)
Add a staticallyconfigured address to the cache.
Definition
Bootcache.cpp:112
xrpl::peer_finder::Bootcache::value_type
MapType::value_type value_type
Definition
Bootcache.h:71
xrpl::peer_finder::Bootcache::iterator
boost::transform_iterator< Transform, MapType::right_map::const_iterator > iterator
Definition
Bootcache.h:103
xrpl::peer_finder::Bootcache::journal_
beast::Journal journal_
Definition
Bootcache.h:92
xrpl::peer_finder::Bootcache::onWrite
void onWrite(beast::PropertyStream::Map &map)
Write the cache state to the property stream.
Definition
Bootcache.cpp:189
xrpl::peer_finder::Bootcache::load
void load()
Load the persisted data from the Store into the container.
Definition
Bootcache.cpp:78
xrpl::peer_finder::Bootcache::RightT
boost::bimaps::multiset_of< Entry, std::less<> > RightT
Definition
Bootcache.h:69
xrpl::peer_finder::Bootcache::begin
const_iterator begin() const
ip::Endpoint iterators that traverse in decreasing valence.
Definition
Bootcache.cpp:45
xrpl::peer_finder::Bootcache::insert
bool insert(beast::ip::Endpoint const &endpoint)
Add a newly-learned address to the cache.
Definition
Bootcache.cpp:99
xrpl::peer_finder::Bootcache::LeftT
boost::bimaps:: unordered_set_of< beast::ip::Endpoint, boost::hash< beast::ip::Endpoint >, std::equal_to<> > LeftT
Definition
Bootcache.h:67
xrpl::peer_finder::Bootcache::empty
bool empty() const
Returns true if the cache is empty.
Definition
Bootcache.cpp:33
xrpl::peer_finder::Bootcache::whenUpdate_
ClockType::time_point whenUpdate_
Definition
Bootcache.h:95
xrpl::peer_finder::Bootcache::end
const_iterator end() const
Definition
Bootcache.cpp:57
xrpl::peer_finder::Bootcache::onFailure
void onFailure(beast::ip::Endpoint const &endpoint)
Called when an outbound connection attempt fails to handshake.
Definition
Bootcache.cpp:157
xrpl::peer_finder::Bootcache::cend
const_iterator cend() const
Definition
Bootcache.cpp:63
xrpl::peer_finder::Bootcache::store_
Store & store_
Definition
Bootcache.h:90
xrpl::peer_finder::Bootcache::onSuccess
void onSuccess(beast::ip::Endpoint const &endpoint)
Called when an outbound connection handshake completes.
Definition
Bootcache.cpp:133
xrpl::peer_finder::Bootcache::MapType
boost::bimap< LeftT, RightT > MapType
Definition
Bootcache.h:70
xrpl::peer_finder::Bootcache::periodicActivity
void periodicActivity()
Stores the cache in the persistent database on a timer.
Definition
Bootcache.cpp:181
xrpl::peer_finder::Bootcache::~Bootcache
~Bootcache()
Definition
Bootcache.cpp:27
xrpl::peer_finder::Bootcache::cbegin
const_iterator cbegin() const
Definition
Bootcache.cpp:51
xrpl::peer_finder::Bootcache::Bootcache
Bootcache(Store &store, ClockType &clock, beast::Journal journal)
Definition
Bootcache.cpp:21
xrpl::peer_finder::Bootcache::checkUpdate
void checkUpdate()
Definition
Bootcache.cpp:252
xrpl::peer_finder::Bootcache::prune
void prune()
Definition
Bootcache.cpp:202
xrpl::peer_finder::Bootcache::clock_
ClockType & clock_
Definition
Bootcache.h:91
xrpl::peer_finder::Bootcache::flagForUpdate
void flagForUpdate()
Definition
Bootcache.cpp:260
xrpl::peer_finder::Bootcache::size
MapType::size_type size() const
Returns the number of entries in the cache.
Definition
Bootcache.cpp:39
xrpl::peer_finder::Bootcache::needsUpdate_
bool needsUpdate_
Definition
Bootcache.h:98
xrpl::peer_finder::Bootcache::map_
MapType map_
Definition
Bootcache.h:88
xrpl::peer_finder::Store
Abstract persistence for PeerFinder data.
Definition
Store.h:15
std::equal_to
functional
xrpl::peer_finder
Definition
include/xrpl/peerfinder/Config.h:12
xrpl::peer_finder::ClockType
beast::AbstractClock< std::chrono::steady_clock > ClockType
Definition
peerfinder/Types.h:13
xrpl::peer_finder::Bootcache::Transform::result_type
beast::ip::Endpoint const & result_type
Definition
Bootcache.h:76
xrpl::peer_finder::Bootcache::Transform::first_argument_type
MapType::right_map::const_iterator::value_type const & first_argument_type
Definition
Bootcache.h:75
xrpl::peer_finder::Bootcache::Transform::operator()
beast::ip::Endpoint const & operator()(MapType::right_map::const_iterator::value_type const &v) const
Definition
Bootcache.h:81
xrpl::peer_finder::Bootcache::Transform::Transform
Transform()=default
Generated by
1.17.0