20 #include <ripple/peerfinder/impl/Bootcache.h>
21 #include <ripple/peerfinder/impl/iosformat.h>
22 #include <ripple/peerfinder/impl/Tuning.h>
23 #include <ripple/basics/Log.h>
26 namespace PeerFinder {
35 , m_whenUpdate (m_clock.now ())
36 , m_needsUpdate (false)
51 Bootcache::map_type::size_type
97 auto const result (this->m_map.insert (
98 value_type (endpoint, valence)));
101 JLOG(this->m_journal.error())
102 << beast::leftw (18) <<
103 "Bootcache discard " << endpoint;
110 "Bootcache loaded " << n <<
111 ((n > 1) ?
" addresses" :
" address");
119 auto const result (m_map.insert (
124 "Bootcache insert " << endpoint;
128 return result.second;
134 auto result (m_map.insert (
137 if (! result.second && (result.first->right.valence() < staticValence))
140 m_map.erase (result.first);
141 result = m_map.insert (
148 "Bootcache insert " << endpoint;
152 return result.second;
158 auto result (m_map.insert (
166 Entry entry (result.first->right);
170 m_map.erase (result.first);
171 result = m_map.insert (
173 assert (result.second);
175 Entry const& entry (result.first->right);
177 "Bootcache connect " << endpoint <<
179 ((entry.
valence() > 1) ?
" successes" :
" success");
186 auto result (m_map.insert (
194 Entry entry (result.first->right);
198 m_map.erase (result.first);
199 result = m_map.insert (
201 assert (result.second);
203 Entry const& entry (result.first->right);
204 auto const n (std::abs (entry.
valence()));
206 "Bootcache failed " << endpoint <<
208 ((n > 1) ?
" attempts" :
" attempt");
213 Bootcache::periodicActivity ()
224 for (
auto iter = m_map.right.begin(); iter != m_map.right.end(); ++iter)
227 entry[
"endpoint"] = iter->get_left().to_string();
228 entry[
"valence"] =
std::int32_t (iter->get_right().valence());
236 if (size() <= Tuning::bootcacheSize)
240 auto count ((size() *
241 Tuning::bootcachePrunePercent) / 100);
242 decltype(count) pruned (0);
247 for (
auto iter (m_map.right.end());
248 count-- > 0 && iter != m_map.right.begin(); ++pruned)
252 Entry const& entry (iter->get_right());
254 "Bootcache pruned" << endpoint <<
255 " at valence " << entry.
valence();
256 iter = m_map.right.erase (iter);
260 "Bootcache pruned " << pruned <<
" entries total";
271 for (
auto const& e : m_map)
275 se.
valence = e.get_right().valence();
280 m_needsUpdate =
false;
281 m_whenUpdate = m_clock.now() + Tuning::bootcacheCooldownTime;
286 Bootcache::checkUpdate ()
288 if (m_needsUpdate && m_whenUpdate < m_clock.now())
294 Bootcache::flagForUpdate ()
296 m_needsUpdate =
true;