From 9072a018dd57f804bdd6d077c4f3d3994a087d1c Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 10 Apr 2015 18:13:11 -0400 Subject: [PATCH] reduced CPU load at floodfill --- NetDb.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index b5868600..1fc0abe6 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -704,22 +704,27 @@ namespace data if (!replyMsg) { LogPrint ("Requested ", key, " not found. ", numExcluded, " excluded"); - std::set excludedRouters; - for (int i = 0; i < numExcluded; i++) - { - excludedRouters.insert (excluded); - excluded += 32; - } std::vector routers; - for (int i = 0; i < 3; i++) - { - auto floodfill = GetClosestFloodfill (buf, excludedRouters); - if (floodfill) - { - routers.push_back (floodfill->GetIdentHash ()); - excludedRouters.insert (floodfill->GetIdentHash ()); + 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 (buf, excludedRouters); + if (floodfill) + { + routers.push_back (floodfill->GetIdentHash ()); + excludedRouters.insert (floodfill->GetIdentHash ()); + } } } + else + routers = GetClosestFloodfills (buf, 3); replyMsg = CreateDatabaseSearchReply (buf, routers); } }