1#include <xrpl/peerfinder/detail/Bootcache.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/net/IPEndpoint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/PropertyStream.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/peerfinder/Types.h>
9#include <xrpl/peerfinder/detail/Store.h>
10#include <xrpl/peerfinder/detail/Tuning.h>
38Bootcache::map_type::size_type
82 auto const result(this->map_.insert(value_type(endpoint, valence)));
85 JLOG(this->journal_.error())
86 << std::left << std::setw(18) <<
"Bootcache discard " << endpoint;
93 << ((n > 1) ?
" addresses" :
" address");
108 return result.second;
116 if (!result.second && (result.first->right.valence() <
kStaticValence))
119 map_.erase(result.first);
129 return result.second;
142 Entry entry(result.first->right);
143 entry.valence() =
std::max(entry.valence(), 0);
145 map_.erase(result.first);
147 XRPL_ASSERT(result.second,
"xrpl::peer_finder::Bootcache::onSuccess : endpoint inserted");
149 Entry const& entry(result.first->right);
151 <<
" with " << entry.valence()
152 << ((entry.valence() > 1) ?
" successes" :
" success");
166 Entry entry(result.first->right);
167 entry.valence() =
std::min(entry.valence(), 0);
169 map_.erase(result.first);
171 XRPL_ASSERT(result.second,
"xrpl::peer_finder::Bootcache::onFailure : endpoint inserted");
173 Entry const& entry(result.first->right);
174 auto const n(std::abs(entry.valence()));
176 <<
" with " << n << ((n > 1) ?
" attempts" :
" attempt");
192 for (
auto iter =
map_.right.begin(); iter !=
map_.right.end(); ++iter)
195 entry[
"endpoint"] = iter->get_left().toString();
196 entry[
"valence"] =
std::int32_t(iter->get_right().valence());
209 decltype(count) pruned(0);
214 for (
auto iter(
map_.right.end()); count > 0 && iter !=
map_.right.begin(); ++pruned)
219 Entry const& entry(iter->get_right());
221 <<
" at valence " << entry.valence();
222 iter =
map_.right.erase(iter);
237 for (
auto const& e :
map_)
241 se.
valence = e.get_right().valence();
A generic endpoint for log messages.
A version-independent IP address and port combination.
static constexpr int kStaticValence
bool insertStatic(beast::ip::Endpoint const &endpoint)
Add a staticallyconfigured address to the cache.
void onWrite(beast::PropertyStream::Map &map)
Write the cache state to the property stream.
map_type::value_type value_type
void load()
Load the persisted data from the Store into the container.
const_iterator begin() const
ip::Endpoint iterators that traverse in decreasing valence.
bool insert(beast::ip::Endpoint const &endpoint)
Add a newly-learned address to the cache.
bool empty() const
Returns true if the cache is empty.
clock_type::time_point whenUpdate_
const_iterator end() const
map_type::size_type size() const
Returns the number of entries in the cache.
void onFailure(beast::ip::Endpoint const &endpoint)
Called when an outbound connection attempt fails to handshake.
const_iterator cend() const
void onSuccess(beast::ip::Endpoint const &endpoint)
Called when an outbound connection handshake completes.
void periodicActivity()
Stores the cache in the persistent database on a timer.
const_iterator cbegin() const
Bootcache(Store &store, clock_type &clock, beast::Journal journal)
Abstract persistence for PeerFinder data.
static constexpr auto kBootcachePrunePercent
static constexpr auto kBootcacheSize
static std::chrono::seconds const kBootcacheCooldownTime(60)
beast::AbstractClock< std::chrono::steady_clock > clock_type
beast::ip::Endpoint endpoint