1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

connect to closer nodes for introset lookups

This commit is contained in:
Jeff Becker 2020-01-22 17:30:24 -05:00
parent 3b66cf6e75
commit 49f696de9c
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
3 changed files with 33 additions and 1 deletions

View file

@ -2,6 +2,8 @@
#include <dht/messages/findintro.hpp>
#include <dht/messages/gotintro.hpp>
#include <routing/message.hpp>
#include <router/abstractrouter.hpp>
#include <nodedb.hpp>
namespace llarp
{
@ -112,8 +114,14 @@ namespace llarp
Key_t us = dht.OurKey();
Key_t target = S.ToKey();
// we are recursive
if(dht.Nodes()->FindCloseExcluding(target, peer, exclude))
const auto rc = dht.GetRouter()->nodedb()->FindClosestTo(target);
{
peer = Key_t(rc.pubkey);
if(peer == us)
{
replies.emplace_back(new GotIntroMessage({}, T));
return true;
}
if(relayed)
dht.LookupIntroSetForPath(S, T, pathID, peer, R - 1);
else

View file

@ -9,6 +9,7 @@
#include <util/mem.hpp>
#include <util/thread/logic.hpp>
#include <util/thread/thread_pool.hpp>
#include <dht/kademlia.hpp>
#include <fstream>
#include <unordered_map>
@ -92,6 +93,25 @@ llarp_nodedb::Has(const llarp::RouterID &pk)
return entries.find(pk) != entries.end();
}
llarp::RouterContact
llarp_nodedb::FindClosestTo(const llarp::dht::Key_t &location)
{
llarp::RouterContact rc;
const llarp::dht::XorMetric compare(location);
visit([&rc, compare](const auto &otherRC) -> bool {
if(rc.pubkey.IsZero())
{
rc = otherRC;
return true;
}
if(compare(llarp::dht::Key_t{otherRC.pubkey.as_array()},
llarp::dht::Key_t{rc.pubkey.as_array()}))
rc = otherRC;
return true;
});
return rc;
}
/// skiplist directory is hex encoded first nibble
/// skiplist filename is <base32encoded>.snode.signed
std::string

View file

@ -6,6 +6,7 @@
#include <util/common.hpp>
#include <util/fs.hpp>
#include <util/thread/threading.hpp>
#include <dht/key.hpp>
#include <absl/base/thread_annotations.h>
@ -73,6 +74,9 @@ struct llarp_nodedb
NetDBMap_t entries GUARDED_BY(access);
fs::path nodePath;
llarp::RouterContact
FindClosestTo(const llarp::dht::Key_t &location);
/// return true if we should save our nodedb to disk
bool
ShouldSaveToDisk(llarp_time_t now = 0) const;