3#include <xrpld/peerfinder/PeerfinderManager.h>
4#include <xrpld/peerfinder/detail/Tuning.h>
5#include <xrpld/peerfinder/detail/iosformat.h>
7#include <xrpl/basics/Log.h>
8#include <xrpl/basics/random.h>
9#include <xrpl/beast/container/aged_map.h>
10#include <xrpl/beast/utility/maybe_const.h>
12#include <boost/intrusive/list.hpp>
13#include <boost/iterator/transform_iterator.hpp>
31 struct Element : boost::intrusive::list_base_hook<>
41 boost::intrusive::make_list<Element, boost::intrusive::constant_time_size<false>>::type;
48 template <
bool IsConst>
68 using iterator = boost::transform_iterator<Transform, list_type::const_iterator>;
73 boost::transform_iterator<Transform, list_type::const_reverse_iterator>;
129 auto& e(
const_cast<Element&
>(*pos.base()));
130 list_.get().erase(
list_.get().iterator_to(e));
131 list_.get().push_back(e);
146 template <
bool IsConst>
170template <
class Allocator = std::allocator<
char>>
208 template <
bool IsConst>
224 using iterator = boost::transform_iterator<Transform<false>, lists_type::iterator>;
227 boost::transform_iterator<Transform<true>, lists_type::const_iterator>;
230 boost::transform_iterator<Transform<false>, lists_type::reverse_iterator>;
233 boost::transform_iterator<Transform<true>, lists_type::const_reverse_iterator>;
315 explicit HopsT(Allocator
const& alloc);
361template <
class Allocator>
367template <
class Allocator>
374 for (
auto iter(
cache_.chronological.begin());
375 iter !=
cache_.chronological.end() && iter.when() <= expired;)
379 iter =
cache_.erase(iter);
385 << ((n > 1) ?
" entries" :
" entry");
389template <
class Allocator>
401 "xrpl::PeerFinder::Livecache::insert : maximum input hops");
403 Element& e(result.first->second);
408 <<
" at hops " << ep.
hops;
416 <<
" at hops +" << excess;
420 cache_.touch(result.first);
427 <<
" at hops " << ep.
hops;
432 <<
" at hops " << ep.
hops;
436template <
class Allocator>
442 map[
"size"] =
size();
443 map[
"hist"] =
hops.histogram();
445 for (
auto iter(
cache_.cbegin()); iter !=
cache_.cend(); ++iter)
447 auto const& e(iter->second);
449 item[
"hops"] = e.endpoint.hops;
450 item[
"address"] = e.endpoint.address.toString();
452 ss << (iter.when() - expired).count();
453 item[
"expires"] = ss.
str();
459template <
class Allocator>
475template <
class Allocator>
480 for (
auto const& h :
hist_)
489template <
class Allocator>
495template <
class Allocator>
501 "xrpl::PeerFinder::Livecache::HopsT::insert : maximum input hops");
507template <
class Allocator>
513 "xrpl::PeerFinder::Livecache::HopsT::reinsert : maximum hops input");
516 list.erase(list.iterator_to(e));
524template <
class Allocator>
531 list.erase(list.iterator_to(e));
T back_inserter(T... args)
A version-independent IP address and port combination.
A generic endpoint for log messages.
clock_type::time_point time_point
const_reverse_iterator rbegin() const
const_iterator begin() const
const_iterator cend() const
reverse_iterator rbegin()
void reinsert(Element &e, std::uint32_t hops)
boost::transform_iterator< Transform< true >, lists_type::const_iterator > const_iterator
HopsT(Allocator const &alloc)
const_iterator cbegin() const
const_reverse_iterator crbegin() const
boost::transform_iterator< Transform< false >, lists_type::iterator > iterator
const_reverse_iterator crend() const
boost::transform_iterator< Transform< false >, lists_type::reverse_iterator > reverse_iterator
std::array< int, 1+Tuning::kMaxHops+1 > Histogram
boost::transform_iterator< Transform< true >, lists_type::const_reverse_iterator > const_reverse_iterator
const_reverse_iterator rend() const
std::array< list_type, 1+Tuning::kMaxHops+1 > lists_type
void shuffle()
Shuffle each hop list.
const_iterator end() const
std::string histogram() const
The Livecache holds the short-lived relayed Endpoint messages.
cache_type::size_type size() const
Returns the number of entries in the cache.
beast::aged_map< beast::IP::Endpoint, Element, std::chrono::steady_clock, std::less< beast::IP::Endpoint >, Allocator > cache_type
Livecache(clock_type &clock, beast::Journal journal, Allocator alloc=Allocator())
Create the cache.
class xrpl::PeerFinder::Livecache::HopsT hops
void expire()
Erase entries whose time has expired.
void insert(Endpoint const &ep)
Creates or updates an existing Element based on a new message.
bool empty() const
Returns true if the cache is empty.
void onWrite(beast::PropertyStream::Map &map)
Output statistics.
A list of Endpoint at the same hops This is a lightweight wrapper around a reference to the underlyin...
reverse_iterator crbegin() const
reverse_iterator crend() const
Hop(beast::MaybeConst< IsConst, list_type >::type &list)
void moveBack(const_iterator pos)
boost::transform_iterator< Transform, list_type::const_iterator > iterator
reverse_iterator const_reverse_iterator
std::reference_wrapper< typename beast::MaybeConst< IsConst, list_type >::type > list_
friend class LivecacheBase
reverse_iterator rend() const
boost::transform_iterator< Transform, list_type::const_reverse_iterator > reverse_iterator
reverse_iterator rbegin() const
static Hop< IsConst > makeHop(beast::MaybeConst< IsConst, list_type >::type &list)
boost::intrusive::make_list< Element, boost::intrusive::constant_time_size< false > >::type list_type
detail::AgedOrderedContainer< false, true, Key, T, Clock, Compare, Allocator > aged_map
constexpr std::uint32_t kMaxHops
constexpr std::chrono::seconds kLiveCacheSecondsToLive(30)
beast::AbstractClock< std::chrono::steady_clock > clock_type
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
Dir::ConstIterator const_iterator
beast::xor_shift_engine & defaultPrng()
Return the default random engine.
Left justifies a field at the specified width.
std:: conditional_t< IsConst, typename std::remove_const< T >::type const, std::remove_const_t< T > > type
Describes a connectable peer address along with some metadata.
beast::IP::Endpoint address
Element(Endpoint endpoint)