Give statically-configured bootcache entries priority:

Make sure statically-configured bootcache entries have at least
a reasonable minimum priority. This provides additional protection
against Sybil attacks.

Show the bootcache in the ouput of the print command.
This commit is contained in:
JoelKatz
2017-05-08 16:13:24 -07:00
committed by Nik Bougalis
parent c1d64e1b1a
commit 256e58204a
3 changed files with 38 additions and 3 deletions

View File

@@ -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.

View File

@@ -110,6 +110,8 @@ private:
bool m_needsUpdate;
public:
static constexpr int staticValence = 32;
using iterator = boost::transform_iterator <Transform,
map_type::right_map::const_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);

View File

@@ -990,7 +990,7 @@ public:
std::lock_guard<std::recursive_mutex> _(lock_);
for (auto addr : list)
{
if (bootcache_.insert (addr))
if (bootcache_.insertStatic (addr))
++count;
}
return count;