1#include <xrpld/peerfinder/detail/Bootcache.h> 
    2#include <xrpld/peerfinder/detail/Tuning.h> 
    3#include <xrpld/peerfinder/detail/iosformat.h> 
    5#include <xrpl/basics/Log.h> 
   14    , m_whenUpdate(m_clock.now())
 
   15    , m_needsUpdate(false)
 
 
   30Bootcache::map_type::size_type
 
   76                this->m_map.insert(value_type(endpoint, valence)));
 
   79                JLOG(this->m_journal.error())
 
   80                    << beast::leftw(18) << 
"Bootcache discard " << endpoint;
 
   86        JLOG(m_journal.info()) << 
beast::leftw(18) << 
"Bootcache loaded " << n
 
   87                               << ((n > 1) ? 
" addresses" : 
" address");
 
 
   95    auto const result(m_map.insert(
value_type(endpoint, 0)));
 
   98        JLOG(m_journal.trace())
 
  103    return result.second;
 
 
  109    auto result(m_map.insert(
value_type(endpoint, staticValence)));
 
  111    if (!result.second && (result.first->right.valence() < staticValence))
 
  114        m_map.erase(result.first);
 
  115        result = m_map.insert(
value_type(endpoint, staticValence));
 
  120        JLOG(m_journal.trace())
 
  125    return result.second;
 
 
  131    auto result(m_map.insert(
value_type(endpoint, 1)));
 
  138        Entry entry(result.first->right);
 
  139        if (entry.valence() < 0)
 
  142        m_map.erase(result.first);
 
  143        result = m_map.insert(
value_type(endpoint, entry));
 
  146            "ripple:PeerFinder::Bootcache::on_success : endpoint inserted");
 
  148    Entry const& entry(result.first->right);
 
  149    JLOG(m_journal.info()) << 
beast::leftw(18) << 
"Bootcache connect " 
  150                           << endpoint << 
" with " << entry.valence()
 
  151                           << ((entry.valence() > 1) ? 
" successes" 
 
  159    auto result(m_map.insert(
value_type(endpoint, -1)));
 
  166        Entry entry(result.first->right);
 
  167        if (entry.valence() > 0)
 
  170        m_map.erase(result.first);
 
  171        result = m_map.insert(
value_type(endpoint, entry));
 
  174            "ripple:PeerFinder::Bootcache::on_failure : endpoint inserted");
 
  176    Entry const& entry(result.first->right);
 
  177    auto const n(std::abs(entry.valence()));
 
  178    JLOG(m_journal.debug())
 
  179        << 
beast::leftw(18) << 
"Bootcache failed " << endpoint << 
" with " << n
 
  180        << ((n > 1) ? 
" attempts" : 
" attempt");
 
 
  185Bootcache::periodicActivity()
 
 
  196    for (
auto iter = m_map.right.begin(); iter != m_map.right.end(); ++iter)
 
  199        entry[
"endpoint"] = iter->get_left().to_string();
 
  200        entry[
"valence"] = 
std::int32_t(iter->get_right().valence());
 
 
  208    if (size() <= Tuning::bootcacheSize)
 
  212    auto count((size() * Tuning::bootcachePrunePercent) / 100);
 
  213    decltype(count) pruned(0);
 
  218    for (
auto iter(m_map.right.end());
 
  219         count-- > 0 && iter != m_map.right.begin();
 
  224        Entry const& entry(iter->get_right());
 
  225        JLOG(m_journal.trace())
 
  227            << 
" at valence " << entry.valence();
 
  228        iter = m_map.right.erase(iter);
 
  231    JLOG(m_journal.debug()) << 
beast::leftw(18) << 
"Bootcache pruned " << pruned
 
 
  243    for (
auto const& e : m_map)
 
  247        se.
valence = e.get_right().valence();
 
  252    m_needsUpdate = 
false;
 
  253    m_whenUpdate = m_clock.now() + Tuning::bootcacheCooldownTime;
 
 
  258Bootcache::checkUpdate()
 
  260    if (m_needsUpdate && m_whenUpdate < m_clock.now())
 
 
  266Bootcache::flagForUpdate()
 
  268    m_needsUpdate = 
true;
 
 
A version-independent IP address and port combination.
 
A generic endpoint for log messages.
 
map_type::size_type size() const
Returns the number of entries in the cache.
 
const_iterator cbegin() const
 
const_iterator end() const
 
const_iterator cend() const
 
Bootcache(Store &store, clock_type &clock, beast::Journal journal)
 
map_type::value_type value_type
 
const_iterator begin() const
IP::Endpoint iterators that traverse in decreasing valence.
 
bool empty() const
Returns true if the cache is empty.
 
void load()
Load the persisted data from the Store into the container.
 
Abstract persistence for PeerFinder data.
 
virtual std::size_t load(load_callback const &cb)=0
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
Left justifies a field at the specified width.
 
beast::IP::Endpoint endpoint