diff --git a/NetDb.cpp b/NetDb.cpp index 0ec8c41d..5ba3c17d 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -732,28 +732,13 @@ namespace data if (!replyMsg) { LogPrint ("Requested ", key, " not found. ", numExcluded, " excluded"); - std::vector routers; - if (numExcluded > 0) - { - std::set excludedRouters; - for (int i = 0; i < numExcluded; i++) - { - excludedRouters.insert (excluded); - excluded += 32; - } - for (int i = 0; i < 3; i++) - { - auto floodfill = GetClosestFloodfill (ident, excludedRouters); - if (floodfill) - { - routers.push_back (floodfill->GetIdentHash ()); - excludedRouters.insert (floodfill->GetIdentHash ()); - } - } - } - else - routers = GetClosestFloodfills (ident, 3); - replyMsg = CreateDatabaseSearchReply (ident, routers); + std::set excludedRouters; + for (int i = 0; i < numExcluded; i++) + { + excludedRouters.insert (excluded); + excluded += 32; + } + replyMsg = CreateDatabaseSearchReply (ident, GetClosestFloodfills (ident, 3, excludedRouters)); } } @@ -955,7 +940,8 @@ namespace data return r; } - std::vector NetDb::GetClosestFloodfills (const IdentHash& destination, size_t num) const + std::vector NetDb::GetClosestFloodfills (const IdentHash& destination, size_t num, + std::set& excluded) const { struct Sorted { @@ -990,8 +976,12 @@ namespace data { if (i < num) { - res.push_back (it.r->GetIdentHash ()); - i++; + auto& ident = it.r->GetIdentHash (); + if (!excluded.count (ident)) + { + res.push_back (ident); + i++; + } } else break; diff --git a/NetDb.h b/NetDb.h index 1a7ee0de..2c6e78be 100644 --- a/NetDb.h +++ b/NetDb.h @@ -51,7 +51,8 @@ namespace data std::shared_ptr GetRandomPeerTestRouter () const; std::shared_ptr GetRandomIntroducer () const; std::shared_ptr GetClosestFloodfill (const IdentHash& destination, const std::set& excluded) const; - std::vector GetClosestFloodfills (const IdentHash& destination, size_t num) const; + std::vector GetClosestFloodfills (const IdentHash& destination, size_t num, + std::set& excluded) const; std::shared_ptr GetClosestNonFloodfill (const IdentHash& destination, const std::set& excluded) const; void SetUnreachable (const IdentHash& ident, bool unreachable);