xrpld
Loading...
Searching...
No Matches
xrpl::PeerFinder::Bootcache Class Reference

Stores IP addresses useful for gaining initial connections. More...

#include <Bootcache.h>

Collaboration diagram for xrpl::PeerFinder::Bootcache:

Classes

class  Entry
struct  Transform

Public Types

using iterator = boost::transform_iterator<Transform, map_type::right_map::const_iterator>
using const_iterator = iterator

Public Member Functions

 Bootcache (Store &store, clock_type &clock, beast::Journal journal)
 ~Bootcache ()
bool empty () const
 Returns true if the cache is empty.
map_type::size_type size () const
 Returns the number of entries in the cache.
void load ()
 Load the persisted data from the Store into the container.
bool insert (beast::IP::Endpoint const &endpoint)
 Add a newly-learned address to the cache.
bool insertStatic (beast::IP::Endpoint const &endpoint)
 Add a staticallyconfigured address to the cache.
void onSuccess (beast::IP::Endpoint const &endpoint)
 Called when an outbound connection handshake completes.
void onFailure (beast::IP::Endpoint const &endpoint)
 Called when an outbound connection attempt fails to handshake.
void periodicActivity ()
 Stores the cache in the persistent database on a timer.
void onWrite (beast::PropertyStream::Map &map)
 Write the cache state to the property stream.
const_iterator begin () const
 IP::Endpoint iterators that traverse in decreasing valence.
const_iterator cbegin () const
const_iterator end () const
const_iterator cend () const
void clear ()

Static Public Attributes

static constexpr int kStaticValence = 32

Private Types

using left_t
using right_t = boost::bimaps::multiset_of<Entry, xrpl::less<Entry>>
using map_type = boost::bimap<left_t, right_t>
using value_type = map_type::value_type

Private Member Functions

void prune ()
void update ()
void checkUpdate ()
void flagForUpdate ()

Private Attributes

map_type map_
Storestore_
clock_typeclock_
beast::Journal journal_
clock_type::time_point whenUpdate_
bool needsUpdate_ {false}

Detailed Description

Stores IP addresses useful for gaining initial connections.

This is one of the caches that is consulted when additional outgoing connections are needed. Along with the address, each entry has this additional metadata:

Valence A signed integer which represents the number of successful consecutive connection attempts when positive, and the number of failed consecutive connection attempts when negative.

When choosing addresses from the boot cache for the purpose of establishing outgoing connections, addresses are ranked in decreasing order of high uptime, with valence as the tie breaker.

Definition at line 32 of file Bootcache.h.

Member Typedef Documentation

◆ left_t

Initial value:
boost::bimaps::unordered_set_of<
boost::hash<beast::IP::Endpoint>,
A version-independent IP address and port combination.
Definition IPEndpoint.h:17

Definition at line 64 of file Bootcache.h.

◆ right_t

using xrpl::PeerFinder::Bootcache::right_t = boost::bimaps::multiset_of<Entry, xrpl::less<Entry>>
private

Definition at line 68 of file Bootcache.h.

◆ map_type

using xrpl::PeerFinder::Bootcache::map_type = boost::bimap<left_t, right_t>
private

Definition at line 69 of file Bootcache.h.

◆ value_type

using xrpl::PeerFinder::Bootcache::value_type = map_type::value_type
private

Definition at line 70 of file Bootcache.h.

◆ iterator

using xrpl::PeerFinder::Bootcache::iterator = boost::transform_iterator<Transform, map_type::right_map::const_iterator>

Definition at line 102 of file Bootcache.h.

◆ const_iterator

Constructor & Destructor Documentation

◆ Bootcache()

xrpl::PeerFinder::Bootcache::Bootcache ( Store & store,
clock_type & clock,
beast::Journal journal )

Definition at line 21 of file Bootcache.cpp.

◆ ~Bootcache()

xrpl::PeerFinder::Bootcache::~Bootcache ( )

Definition at line 27 of file Bootcache.cpp.

Member Function Documentation

◆ empty()

bool xrpl::PeerFinder::Bootcache::empty ( ) const
nodiscard

Returns true if the cache is empty.

Definition at line 33 of file Bootcache.cpp.

◆ size()

Bootcache::map_type::size_type xrpl::PeerFinder::Bootcache::size ( ) const
nodiscard

Returns the number of entries in the cache.

Definition at line 39 of file Bootcache.cpp.

◆ begin()

Bootcache::const_iterator xrpl::PeerFinder::Bootcache::begin ( ) const
nodiscard

IP::Endpoint iterators that traverse in decreasing valence.

Definition at line 45 of file Bootcache.cpp.

◆ cbegin()

Bootcache::const_iterator xrpl::PeerFinder::Bootcache::cbegin ( ) const
nodiscard

Definition at line 51 of file Bootcache.cpp.

◆ end()

Bootcache::const_iterator xrpl::PeerFinder::Bootcache::end ( ) const
nodiscard

Definition at line 57 of file Bootcache.cpp.

◆ cend()

Bootcache::const_iterator xrpl::PeerFinder::Bootcache::cend ( ) const
nodiscard

Definition at line 63 of file Bootcache.cpp.

◆ clear()

void xrpl::PeerFinder::Bootcache::clear ( )

Definition at line 69 of file Bootcache.cpp.

◆ load()

void xrpl::PeerFinder::Bootcache::load ( )

Load the persisted data from the Store into the container.

Definition at line 78 of file Bootcache.cpp.

◆ insert()

bool xrpl::PeerFinder::Bootcache::insert ( beast::IP::Endpoint const & endpoint)

Add a newly-learned address to the cache.

Definition at line 98 of file Bootcache.cpp.

◆ insertStatic()

bool xrpl::PeerFinder::Bootcache::insertStatic ( beast::IP::Endpoint const & endpoint)

Add a staticallyconfigured address to the cache.

Definition at line 111 of file Bootcache.cpp.

◆ onSuccess()

void xrpl::PeerFinder::Bootcache::onSuccess ( beast::IP::Endpoint const & endpoint)

Called when an outbound connection handshake completes.

Definition at line 132 of file Bootcache.cpp.

◆ onFailure()

void xrpl::PeerFinder::Bootcache::onFailure ( beast::IP::Endpoint const & endpoint)

Called when an outbound connection attempt fails to handshake.

Definition at line 155 of file Bootcache.cpp.

◆ periodicActivity()

void xrpl::PeerFinder::Bootcache::periodicActivity ( )

Stores the cache in the persistent database on a timer.

Definition at line 179 of file Bootcache.cpp.

◆ onWrite()

void xrpl::PeerFinder::Bootcache::onWrite ( beast::PropertyStream::Map & map)

Write the cache state to the property stream.

Definition at line 187 of file Bootcache.cpp.

◆ prune()

void xrpl::PeerFinder::Bootcache::prune ( )
private

Definition at line 200 of file Bootcache.cpp.

◆ update()

void xrpl::PeerFinder::Bootcache::update ( )
private

Definition at line 227 of file Bootcache.cpp.

◆ checkUpdate()

void xrpl::PeerFinder::Bootcache::checkUpdate ( )
private

Definition at line 248 of file Bootcache.cpp.

◆ flagForUpdate()

void xrpl::PeerFinder::Bootcache::flagForUpdate ( )
private

Definition at line 256 of file Bootcache.cpp.

Member Data Documentation

◆ map_

map_type xrpl::PeerFinder::Bootcache::map_
private

Definition at line 87 of file Bootcache.h.

◆ store_

Store& xrpl::PeerFinder::Bootcache::store_
private

Definition at line 89 of file Bootcache.h.

◆ clock_

clock_type& xrpl::PeerFinder::Bootcache::clock_
private

Definition at line 90 of file Bootcache.h.

◆ journal_

beast::Journal xrpl::PeerFinder::Bootcache::journal_
private

Definition at line 91 of file Bootcache.h.

◆ whenUpdate_

clock_type::time_point xrpl::PeerFinder::Bootcache::whenUpdate_
private

Definition at line 94 of file Bootcache.h.

◆ needsUpdate_

bool xrpl::PeerFinder::Bootcache::needsUpdate_ {false}
private

Definition at line 97 of file Bootcache.h.

◆ kStaticValence

int xrpl::PeerFinder::Bootcache::kStaticValence = 32
staticconstexpr

Definition at line 100 of file Bootcache.h.