actually insert entries when they exist

This commit is contained in:
Jeff Becker 2019-02-07 07:40:44 -05:00
parent fae2b1a444
commit 10f9d6444d
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
1 changed files with 5 additions and 0 deletions

View File

@ -106,6 +106,9 @@ llarp_nodedb::Insert(const llarp::RouterContact &rc)
llarp_buffer_t buf(tmp);
{
llarp::util::Lock lock(access);
auto itr = entries.find(rc.pubkey.as_array());
if(itr != entries.end())
entries.erase(itr);
entries.emplace(rc.pubkey.as_array(), rc);
}
if(!rc.BEncode(&buf))
@ -388,6 +391,7 @@ llarp_nodedb::num_loaded() const
bool
llarp_nodedb::select_random_exit(llarp::RouterContact &result)
{
llarp::util::Lock lock(access);
const auto sz = entries.size();
auto itr = entries.begin();
if(sz < 3)
@ -422,6 +426,7 @@ bool
llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
llarp::RouterContact &result, size_t N)
{
llarp::util::Lock lock(access);
/// checking for "guard" status for N = 0 is done by caller inside of
/// pathbuilder's scope
size_t sz = entries.size();