diff --git a/src/ripple/peerfinder/impl/Bootcache.cpp b/src/ripple/peerfinder/impl/Bootcache.cpp index f9c5257c06..1d0622e594 100644 --- a/src/ripple/peerfinder/impl/Bootcache.cpp +++ b/src/ripple/peerfinder/impl/Bootcache.cpp @@ -129,6 +129,30 @@ Bootcache::insert (beast::IP::Endpoint const& endpoint) return result.second; } +bool +Bootcache::insertStatic (beast::IP::Endpoint const& endpoint) +{ + auto result (m_map.insert ( + value_type (endpoint, staticValence))); + + if (! result.second && (result.first->right.valence() < staticValence)) + { + // An existing entry has too low a valence, replace it + m_map.erase (result.first); + result = m_map.insert ( + value_type (endpoint, staticValence)); + } + + if (result.second) + { + JLOG(m_journal.trace()) << beast::leftw (18) << + "Bootcache insert " << endpoint; + prune (); + flagForUpdate(); + } + return result.second; +} + void Bootcache::on_success (beast::IP::Endpoint const& endpoint) { @@ -197,7 +221,13 @@ Bootcache::periodicActivity () void Bootcache::onWrite (beast::PropertyStream::Map& map) { - map ["entries"] = std::uint32_t (m_map.size()); + beast::PropertyStream::Set entries ("entries", map); + for (auto iter = m_map.right.begin(); iter != m_map.right.end(); ++iter) + { + beast::PropertyStream::Map entry (entries); + entry["endpoint"] = iter->get_left().to_string(); + entry["valence"] = std::int32_t (iter->get_right().valence()); + } } // Checks the cache size and prunes if its over the limit. diff --git a/src/ripple/peerfinder/impl/Bootcache.h b/src/ripple/peerfinder/impl/Bootcache.h index d8f56e7f89..319a76a7d8 100644 --- a/src/ripple/peerfinder/impl/Bootcache.h +++ b/src/ripple/peerfinder/impl/Bootcache.h @@ -110,6 +110,8 @@ private: bool m_needsUpdate; public: + static constexpr int staticValence = 32; + using iterator = boost::transform_iterator ; @@ -140,9 +142,12 @@ public: /** Load the persisted data from the Store into the container. */ void load (); - /** Add the address to the cache. */ + /** Add a newly-learned address to the cache. */ bool insert (beast::IP::Endpoint const& endpoint); + /** Add a staticallyconfigured address to the cache. */ + bool insertStatic (beast::IP::Endpoint const& endpoint); + /** Called when an outbound connection handshake completes. */ void on_success (beast::IP::Endpoint const& endpoint); diff --git a/src/ripple/peerfinder/impl/Logic.h b/src/ripple/peerfinder/impl/Logic.h index dc5354b152..34734311dc 100644 --- a/src/ripple/peerfinder/impl/Logic.h +++ b/src/ripple/peerfinder/impl/Logic.h @@ -990,7 +990,7 @@ public: std::lock_guard _(lock_); for (auto addr : list) { - if (bootcache_.insert (addr)) + if (bootcache_.insertStatic (addr)) ++count; } return count;