1#include <xrpld/peerfinder/detail/Bootcache.h>
3#include <xrpld/peerfinder/PeerfinderManager.h>
4#include <xrpld/peerfinder/detail/Store.h>
5#include <xrpld/peerfinder/detail/Tuning.h>
6#include <xrpld/peerfinder/detail/iosformat.h>
8#include <xrpl/basics/Log.h>
9#include <xrpl/beast/net/IPEndpoint.h>
10#include <xrpl/beast/utility/Journal.h>
11#include <xrpl/beast/utility/PropertyStream.h>
12#include <xrpl/beast/utility/instrumentation.h>
38Bootcache::map_type::size_type
82 auto const result(this->map_.insert(value_type(endpoint, valence)));
85 JLOG(this->journal_.error()) << beast::Leftw(18) <<
"Bootcache discard " << endpoint;
91 JLOG(journal_.info()) <<
beast::Leftw(18) <<
"Bootcache loaded " << n
92 << ((n > 1) ?
" addresses" :
" address");
107 return result.second;
115 if (!result.second && (result.first->right.valence() <
kStaticValence))
118 map_.erase(result.first);
128 return result.second;
141 Entry entry(result.first->right);
142 entry.valence() =
std::max(entry.valence(), 0);
144 map_.erase(result.first);
146 XRPL_ASSERT(result.second,
"xrpl::PeerFinder::Bootcache::onSuccess : endpoint inserted");
148 Entry const& entry(result.first->right);
150 << entry.valence() << ((entry.valence() > 1) ?
" successes" :
" success");
164 Entry entry(result.first->right);
165 entry.valence() =
std::min(entry.valence(), 0);
167 map_.erase(result.first);
169 XRPL_ASSERT(result.second,
"xrpl::PeerFinder::Bootcache::onFailure : endpoint inserted");
171 Entry const& entry(result.first->right);
172 auto const n(std::abs(entry.valence()));
174 << ((n > 1) ?
" attempts" :
" attempt");
190 for (
auto iter =
map_.right.begin(); iter !=
map_.right.end(); ++iter)
193 entry[
"endpoint"] = iter->get_left().toString();
194 entry[
"valence"] =
std::int32_t(iter->get_right().valence());
207 decltype(count) pruned(0);
212 for (
auto iter(
map_.right.end()); count-- > 0 && iter !=
map_.right.begin(); ++pruned)
216 Entry const& entry(iter->get_right());
218 <<
" at valence " << entry.valence();
219 iter =
map_.right.erase(iter);
222 JLOG(
journal_.debug()) <<
beast::Leftw(18) <<
"Bootcache pruned " << pruned <<
" entries total";
233 for (
auto const& e :
map_)
237 se.
valence = e.get_right().valence();
A version-independent IP address and port combination.
A generic endpoint for log messages.
bool insert(beast::IP::Endpoint const &endpoint)
Add a newly-learned address to the cache.
static constexpr int kStaticValence
void periodicActivity()
Stores the cache in the persistent database on a timer.
const_iterator cbegin() const
const_iterator cend() const
void onFailure(beast::IP::Endpoint const &endpoint)
Called when an outbound connection attempt fails to handshake.
void onWrite(beast::PropertyStream::Map &map)
Write the cache state to the property stream.
void onSuccess(beast::IP::Endpoint const &endpoint)
Called when an outbound connection handshake completes.
map_type::value_type value_type
const_iterator begin() const
IP::Endpoint iterators that traverse in decreasing valence.
void load()
Load the persisted data from the Store into the container.
bool insertStatic(beast::IP::Endpoint const &endpoint)
Add a staticallyconfigured address to the cache.
clock_type::time_point whenUpdate_
const_iterator end() const
bool empty() const
Returns true if the cache is empty.
map_type::size_type size() const
Returns the number of entries in the cache.
Bootcache(Store &store, clock_type &clock, beast::Journal journal)
Abstract persistence for PeerFinder data.
static constexpr auto kBootcachePrunePercent
static std::chrono::seconds const kBootcacheCooldownTime(60)
static constexpr auto kBootcacheSize
beast::AbstractClock< std::chrono::steady_clock > clock_type
Left justifies a field at the specified width.
beast::IP::Endpoint endpoint