Remove redundant lookup logic from relays

pull/1151/head
Stephen Shelton 4 years ago
parent 158a9018f3
commit bbee45118e
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -98,35 +98,29 @@ namespace llarp
// we are relaying this message for e.g. a client
if(relayed)
{
uint32_t numDesired = 0;
if(relayOrder == 0)
numDesired = 2;
else if(relayOrder == 1)
numDesired = 4;
else
// TODO: this is now defined in 3 places; consolidate
static constexpr size_t StorageRedundancy = 4;
if (relayOrder >= StorageRedundancy)
{
// TODO: consider forward-compatibility here
LogError("Error: relayOrder must be 0 or 1");
return false;
llarp::LogWarn("Invalid relayOrder received: ", relayOrder);
replies.emplace_back(new GotIntroMessage({}, txID));
return true;
}
auto closestRCs =
dht.GetRouter()->nodedb()->FindClosestTo(location, numDesired);
dht.GetRouter()->nodedb()->FindClosestTo(location, StorageRedundancy);
// if relayOrder == 1, we want the 3rd and 4th closest, so remove the
// 1st and 2nd closest
if(relayOrder == 1)
if (closestRCs.size() <= relayOrder)
{
auto itr = closestRCs.begin();
std::advance(itr, 2);
closestRCs.erase(closestRCs.begin(), itr);
llarp::LogWarn("Can't fulfill FindIntro for relayOrder: ", relayOrder);
replies.emplace_back(new GotIntroMessage({}, txID));
return true;
}
for(const auto& entry : closestRCs)
{
Key_t peer = Key_t(entry.pubkey);
dht.LookupIntroSetForPath(location, txID, pathID, peer, 0);
}
const auto& entry = closestRCs[relayOrder];
Key_t peer = Key_t(entry.pubkey);
dht.LookupIntroSetForPath(location, txID, pathID, peer, 0);
}
else
{

Loading…
Cancel
Save