Merge branch 'fix-up-introset-lookup-fails-2020-03-02' of ssh://github.com/majestrate/loki-network into fix-up-introset-lookup-fails-2020-03-02

pull/1151/head
Jeff Becker 4 years ago
commit d4ccf895e3
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -23,6 +23,15 @@ namespace llarp
namespace dht
{
/// number of routers to publish to
static constexpr size_t IntroSetRelayRedundancy = 2;
/// number of dht locations handled per relay
static constexpr size_t IntroSetRequestsPerRelay = 2;
static constexpr size_t IntroSetStorageRedundancy =
(IntroSetRelayRedundancy * IntroSetRequestsPerRelay);
struct AbstractContext
{
using PendingIntrosetLookups =

@ -98,28 +98,26 @@ namespace llarp
// we are relaying this message for e.g. a client
if(relayed)
{
// TODO: this is now defined in 3 places; consolidate
static constexpr size_t StorageRedundancy = 4;
if (relayOrder >= StorageRedundancy)
if(relayOrder >= IntroSetStorageRedundancy)
{
llarp::LogWarn("Invalid relayOrder received: ", relayOrder);
replies.emplace_back(new GotIntroMessage({}, txID));
return true;
}
auto closestRCs =
dht.GetRouter()->nodedb()->FindClosestTo(location, StorageRedundancy);
auto closestRCs = dht.GetRouter()->nodedb()->FindClosestTo(
location, IntroSetStorageRedundancy);
if (closestRCs.size() <= relayOrder)
if(closestRCs.size() <= relayOrder)
{
llarp::LogWarn("Can't fulfill FindIntro for relayOrder: ", relayOrder);
llarp::LogWarn("Can't fulfill FindIntro for relayOrder: ",
relayOrder);
replies.emplace_back(new GotIntroMessage({}, txID));
return true;
}
const auto& entry = closestRCs[relayOrder];
Key_t peer = Key_t(entry.pubkey);
Key_t peer = Key_t(entry.pubkey);
dht.LookupIntroSetForPath(location, txID, pathID, peer, 0);
}
else

@ -81,10 +81,9 @@ namespace llarp
const llarp::dht::Key_t addr(introset.derivedSigningKey);
// identify closest 4 routers
static constexpr size_t StorageRedundancy = 4;
auto closestRCs =
dht.GetRouter()->nodedb()->FindClosestTo(addr, StorageRedundancy);
if(closestRCs.size() != StorageRedundancy)
auto closestRCs = dht.GetRouter()->nodedb()->FindClosestTo(
addr, IntroSetStorageRedundancy);
if(closestRCs.size() != IntroSetStorageRedundancy)
{
llarp::LogWarn("Received PublishIntroMessage but only know ",
closestRCs.size(), " nodes");
@ -96,7 +95,7 @@ namespace llarp
// function to identify the closest 4 routers we know of for this introset
auto propagateIfNotUs = [&](size_t index) {
assert(index < StorageRedundancy);
assert(index < IntroSetStorageRedundancy);
const auto &rc = closestRCs[index];
const Key_t peer{rc.pubkey};
@ -125,7 +124,7 @@ namespace llarp
if(relayed)
{
if(relayOrder >= StorageRedundancy)
if(relayOrder >= IntroSetStorageRedundancy)
{
llarp::LogWarn(
"Received PublishIntroMessage with invalid relayOrder: ",
@ -166,7 +165,7 @@ namespace llarp
"!!! Received PubIntro with relayed==false but we aren't"
" candidate, intro derived key: ",
keyStr, ", txid=", txID, ", message from: ", From);
for(size_t i = 0; i < StorageRedundancy; ++i)
for(size_t i = 0; i < IntroSetStorageRedundancy; ++i)
{
propagateIfNotUs(i);
}

@ -1,6 +1,7 @@
#include <chrono>
#include <service/endpoint.hpp>
#include <dht/context.hpp>
#include <dht/messages/findintro.hpp>
#include <dht/messages/findrouter.hpp>
#include <dht/messages/gotintro.hpp>
@ -454,23 +455,13 @@ namespace llarp
Endpoint::PublishIntroSet(const EncryptedIntroSet& introset,
AbstractRouter* r)
{
/// number of routers to publish to
static constexpr size_t RelayRedundancy = 2;
const auto paths = GetManyPathsWithUniqueEndpoints(
this, llarp::dht::IntroSetRelayRedundancy);
/// number of dht locations handled per relay
static constexpr size_t RequestsPerRelay = 2;
/// total number of dht locations that should store this introset
static constexpr size_t StorageRedundancy =
(RelayRedundancy * RequestsPerRelay);
assert(StorageRedundancy == 4);
const auto paths = GetManyPathsWithUniqueEndpoints(this, RelayRedundancy);
if(paths.size() != RelayRedundancy)
if(paths.size() != llarp::dht::IntroSetRelayRedundancy)
{
LogWarn("Cannot publish intro set because we only have ", paths.size(),
" paths, but need ", RelayRedundancy);
" paths, but need ", llarp::dht::IntroSetRelayRedundancy);
return false;
}
@ -478,16 +469,16 @@ namespace llarp
size_t published = 0;
for(const auto& path : paths)
{
for(size_t i = 0; i < RequestsPerRelay; ++i)
for(size_t i = 0; i < llarp::dht::IntroSetRequestsPerRelay; ++i)
{
if(PublishIntroSetVia(introset, r, path, published))
published++;
}
}
if(published != StorageRedundancy)
if(published != llarp::dht::IntroSetStorageRedundancy)
LogWarn("Publish introset failed: could only publish ", published,
" copies but wanted ", StorageRedundancy);
return published == StorageRedundancy;
" copies but wanted ", llarp::dht::IntroSetStorageRedundancy);
return published == llarp::dht::IntroSetStorageRedundancy;
}
struct PublishIntroSetJob : public IServiceLookup

Loading…
Cancel
Save