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, typename list_type::const_iterator>;
73 boost::transform_iterator<Transform, typename list_type::const_reverse_iterator>;
129 auto& e(
const_cast<Element&
>(*pos.base()));
146 template <
bool IsConst>
170template <
class Allocator = std::allocator<
char>>
208 template <
bool IsConst>
220 return make_hop<IsConst>(list);
225 using iterator = boost::transform_iterator<Transform<false>,
typename lists_type::iterator>;
228 boost::transform_iterator<Transform<true>,
typename lists_type::const_iterator>;
231 boost::transform_iterator<Transform<false>,
typename lists_type::reverse_iterator>;
234 boost::transform_iterator<Transform<true>,
typename lists_type::const_reverse_iterator>;
316 explicit hops_t(Allocator
const& alloc);
362template <
class Allocator>
364 : m_journal(journal), m_cache(clock, alloc), hops(alloc)
368template <
class Allocator>
380 iter = m_cache.
erase(iter);
386 << ((n > 1) ?
" entries" :
" entry");
390template <
class Allocator>
402 "xrpl::PeerFinder::Livecache::insert : maximum input hops");
404 Element& e(result.first->second);
409 <<
" at hops " << ep.
hops;
417 <<
" at hops +" << excess;
421 m_cache.
touch(result.first);
426 hops.reinsert(e, ep.
hops);
428 <<
" at hops " << ep.
hops;
433 <<
" at hops " << ep.
hops;
437template <
class Allocator>
443 map[
"size"] = size();
444 map[
"hist"] = hops.histogram();
446 for (
auto iter(m_cache.
cbegin()); iter != m_cache.
cend(); ++iter)
448 auto const& e(iter->second);
450 item[
"hops"] = e.endpoint.hops;
451 item[
"address"] = e.endpoint.address.to_string();
453 ss << (iter.when() -
expired).count();
454 item[
"expires"] = ss.
str();
460template <
class Allocator>
476template <
class Allocator>
481 for (
auto const& h : m_hist)
490template <
class Allocator>
493 std::fill(m_hist.begin(), m_hist.end(), 0);
496template <
class Allocator>
502 "xrpl::PeerFinder::Livecache::hops_t::insert : maximum input hops");
508template <
class Allocator>
514 "xrpl::PeerFinder::Livecache::hops_t::reinsert : maximum hops input");
517 list.erase(list.iterator_to(e));
525template <
class Allocator>
532 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.
Stream trace() const
Severity stream access functions.
virtual time_point now() const =0
Returns the current time.
time_point const & when() const
Associative container where each element is also indexed by time.
const_iterator cend() const
beast::detail::aged_container_iterator< false, Iterator > erase(beast::detail::aged_container_iterator< is_const, Iterator > pos)
const_iterator cbegin() const
void touch(beast::detail::aged_container_iterator< is_const, Iterator > pos)
class beast::detail::aged_ordered_container::chronological_t chronological
size_type size() const noexcept
auto emplace(Args &&... args) -> typename std::enable_if<!maybe_multi, std::pair< iterator, bool > >::type
bool empty() const noexcept
typename clock_type::time_point time_point
const_iterator end() const
void shuffle()
Shuffle each hop list.
boost::transform_iterator< Transform< true >, typename lists_type::const_iterator > const_iterator
const_reverse_iterator rbegin() const
const_iterator begin() const
const_reverse_iterator crbegin() const
boost::transform_iterator< Transform< false >, typename lists_type::reverse_iterator > reverse_iterator
reverse_iterator rbegin()
std::string histogram() const
const_iterator cbegin() const
void reinsert(Element &e, std::uint32_t hops)
boost::transform_iterator< Transform< true >, typename lists_type::const_reverse_iterator > const_reverse_iterator
hops_t(Allocator const &alloc)
boost::transform_iterator< Transform< false >, typename lists_type::iterator > iterator
const_reverse_iterator rend() const
const_reverse_iterator crend() const
const_iterator cend() const
The Livecache holds the short-lived relayed Endpoint messages.
cache_type::size_type size() const
Returns the number of entries in the cache.
Livecache(clock_type &clock, beast::Journal journal, Allocator alloc=Allocator())
Create the cache.
class xrpl::PeerFinder::Livecache::hops_t 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...
boost::transform_iterator< Transform, typename list_type::const_iterator > iterator
reverse_iterator crbegin() const
std::reference_wrapper< typename beast::maybe_const< IsConst, list_type >::type > m_list
reverse_iterator crend() const
reverse_iterator const_reverse_iterator
Hop(typename beast::maybe_const< IsConst, list_type >::type &list)
void move_back(const_iterator pos)
reverse_iterator rend() const
reverse_iterator rbegin() const
boost::transform_iterator< Transform, typename list_type::const_reverse_iterator > reverse_iterator
static Hop< IsConst > make_hop(typename beast::maybe_const< IsConst, list_type >::type &list)
boost::intrusive::make_list< Element, boost::intrusive::constant_time_size< false > >::type list_type
std::uint32_t constexpr maxHops
std::chrono::seconds constexpr liveCacheSecondsToLive(30)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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,...
@ expired
List is expired, but has the largest non-pending sequence seen so far.
beast::xor_shift_engine & default_prng()
Return the default random engine.
Left justifies a field at the specified width.
typename std::conditional< IsConst, typename std::remove_const< T >::type const, typename std::remove_const< T >::type >::type type
Describes a connectable peer address along with some metadata.
beast::IP::Endpoint address
Element(Endpoint const &endpoint_)