check keyspace distance and inform not found when next peer is not closer than previous peer

pull/81/head
Jeff Becker 6 years ago
parent 0bbf9c431a
commit cf57eca7c3
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -74,7 +74,7 @@ namespace llarp
Validate(const V& value) const = 0;
void
OnFound(const Key_t& askedPeer, const V& value)
OnFound(const Key_t askedPeer, const V& value)
{
peersAsked.insert(askedPeer);
if(Validate(value))
@ -98,18 +98,23 @@ namespace llarp
Key_t peer;
if(next)
{
peer = *next.get();
// explicit next peer provided
peer = next->data();
}
else
else if(!GetNextPeer(peer, peersAsked))
{
if(!GetNextPeer(peer, peersAsked))
{
// no more peers
SendReply();
return false;
}
// no more peers
return false;
}
const Key_t targetKey = target.data();
if((prevPeer ^ targetKey) < (peer ^ targetKey))
{
// next peer is not closer
return false;
}
else
peersAsked.insert(peer);
DoNextRequest(peer);
return true;
}
@ -316,12 +321,11 @@ namespace llarp
auto txitr = tx.find(from);
if(txitr == tx.end())
return;
if(next)
{
// ask for next peer
if(txitr->second->AskNextPeer(from.node, next))
sendReply = false;
}
// ask for next peer
if(txitr->second->AskNextPeer(from.node, next))
sendReply = false;
llarp::LogWarn("Target key ", txitr->second->target);
Inform(from, txitr->second->target, {}, sendReply, sendReply);
}

@ -339,36 +339,6 @@ namespace llarp
return true;
}
void
DoNextRequest(const Key_t &nextPeer)
{
// iterate to next peer
parent->LookupIntroSetIterative(
target, whoasked.node, whoasked.txid, nextPeer,
std::bind(&ServiceAddressLookup::HandleNextRequestResult, this,
std::placeholders::_1));
}
void
HandleNextRequestResult(const std::vector< service::IntroSet > &results)
{
// merge results
std::set< service::IntroSet > found;
for(const auto &introset : valuesFound)
found.insert(introset);
for(const auto &introset : results)
found.insert(introset);
valuesFound.clear();
for(const auto &introset : found)
valuesFound.push_back(introset);
// send reply
SendReply();
}
bool
GetNextPeer(Key_t &next, const std::set< Key_t > &exclude)
{
@ -383,6 +353,17 @@ namespace llarp
new FindIntroMessage(peer.txid, target, R));
}
void
DoNextRequest(const Key_t &ask) override
{
if(R)
parent->LookupIntroSetRecursive(target, whoasked.node, whoasked.txid,
ask, R - 1);
else
parent->LookupIntroSetIterative(target, whoasked.node, whoasked.txid,
ask);
}
virtual void
SendReply()
{
@ -408,7 +389,7 @@ namespace llarp
}
void
SendReply()
SendReply() override
{
auto path =
parent->router->paths.GetByUpstream(parent->OurKey(), localPath);

Loading…
Cancel
Save