20#ifndef RIPPLE_PEERFINDER_LIVECACHE_H_INCLUDED
21#define RIPPLE_PEERFINDER_LIVECACHE_H_INCLUDED
23#include <xrpld/peerfinder/PeerfinderManager.h>
24#include <xrpld/peerfinder/detail/Tuning.h>
25#include <xrpld/peerfinder/detail/iosformat.h>
27#include <xrpl/basics/Log.h>
28#include <xrpl/basics/random.h>
29#include <xrpl/beast/container/aged_map.h>
30#include <xrpl/beast/utility/maybe_const.h>
32#include <boost/intrusive/list.hpp>
33#include <boost/iterator/transform_iterator.hpp>
51 struct Element : boost::intrusive::list_base_hook<>
61 make_list<Element, boost::intrusive::constant_time_size<false>>::type;
68 template <
bool IsConst>
89 transform_iterator<Transform, typename list_type::const_iterator>;
95 typename list_type::const_reverse_iterator>;
151 auto& e(
const_cast<Element&
>(*pos.base()));
172 template <
bool IsConst>
196template <
class Allocator = std::allocator<
char>>
217 Allocator alloc = Allocator());
237 template <
bool IsConst>
248 typename lists_type::value_type>::type& list)
const
250 return make_hop<IsConst>(list);
256 transform_iterator<Transform<false>,
typename lists_type::iterator>;
260 typename lists_type::const_iterator>;
264 typename lists_type::reverse_iterator>;
268 typename lists_type::const_reverse_iterator>;
350 explicit hops_t(Allocator
const& alloc);
396template <
class Allocator>
401 : m_journal(journal), m_cache(clock, alloc), hops(alloc)
405template <
class Allocator>
417 iter = m_cache.
erase(iter);
423 << ((n > 1) ?
" entries" :
" entry");
427template <
class Allocator>
439 "ripple::PeerFinder::Livecache::insert : maximum input hops");
441 Element& e(result.first->second);
454 << ep.
address <<
" at hops +" << excess;
458 m_cache.
touch(result.first);
463 hops.reinsert(e, ep.
hops);
474template <
class Allocator>
480 map[
"size"] = size();
481 map[
"hist"] = hops.histogram();
483 for (
auto iter(m_cache.
cbegin()); iter != m_cache.
cend(); ++iter)
485 auto const& e(iter->second);
487 item[
"hops"] = e.endpoint.hops;
488 item[
"address"] = e.endpoint.address.to_string();
490 ss << (iter.when() -
expired).count();
491 item[
"expires"] = ss.
str();
497template <
class Allocator>
513template <
class Allocator>
518 for (
auto const& h : m_hist)
527template <
class Allocator>
530 std::fill(m_hist.begin(), m_hist.end(), 0);
533template <
class Allocator>
539 "ripple::PeerFinder::Livecache::hops_t::insert : maximum input hops");
545template <
class Allocator>
551 "ripple::PeerFinder::Livecache::hops_t::reinsert : maximum hops input");
554 list.erase(list.iterator_to(e));
562template <
class Allocator>
569 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
boost::transform_iterator< Transform< true >, typename lists_type::const_iterator > const_iterator
const_iterator begin() const
void shuffle()
Shuffle each hop list.
const_iterator end() const
std::string histogram() const
hops_t(Allocator const &alloc)
const_reverse_iterator crend() const
const_reverse_iterator rend() const
void reinsert(Element &e, std::uint32_t hops)
const_reverse_iterator rbegin() const
boost::transform_iterator< Transform< false >, typename lists_type::reverse_iterator > reverse_iterator
reverse_iterator rbegin()
const_iterator cbegin() const
boost::transform_iterator< Transform< false >, typename lists_type::iterator > iterator
const_iterator cend() const
const_reverse_iterator crbegin() const
boost::transform_iterator< Transform< true >, typename lists_type::const_reverse_iterator > const_reverse_iterator
The Livecache holds the short-lived relayed Endpoint messages.
cache_type::size_type size() const
Returns the number of entries in the cache.
void expire()
Erase entries whose time has expired.
Livecache(clock_type &clock, beast::Journal journal, Allocator alloc=Allocator())
Create the cache.
void insert(Endpoint const &ep)
Creates or updates an existing Element based on a new message.
void onWrite(beast::PropertyStream::Map &map)
Output statistics.
class ripple::PeerFinder::Livecache::hops_t hops
bool empty() const
Returns true if the cache is empty.
A list of Endpoint at the same hops This is a lightweight wrapper around a reference to the underlyin...
reverse_iterator crbegin() const
void move_back(const_iterator pos)
Hop(typename beast::maybe_const< IsConst, list_type >::type &list)
reverse_iterator rend() const
std::reference_wrapper< typename beast::maybe_const< IsConst, list_type >::type > m_list
boost::transform_iterator< Transform, typename list_type::const_iterator > iterator
reverse_iterator crend() const
reverse_iterator rbegin() const
boost::transform_iterator< Transform, typename list_type::const_reverse_iterator > reverse_iterator
reverse_iterator const_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::chrono::seconds constexpr liveCacheSecondsToLive(30)
std::uint32_t constexpr maxHops
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.
Makes T const or non const depending on a bool.
typename std::conditional< IsConst, typename std::remove_const< T >::type const, typename std::remove_const< T >::type >::type type
Describes a connectible peer address along with some metadata.
beast::IP::Endpoint address
Element(Endpoint const &endpoint_)