From 8ad9f2681cb643ed8df753602d43b020cb3ba9e3 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 1 Feb 2015 19:58:26 -0500 Subject: [PATCH] send 3 closest floodfills --- I2NPProtocol.cpp | 8 ++++---- I2NPProtocol.h | 2 +- NetDb.cpp | 24 +++++++++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 087caa0b..ff434924 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -184,18 +184,18 @@ namespace i2p I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, - const i2p::data::RouterInfo * floodfill) + std::vector routers) { I2NPMessage * m = NewI2NPShortMessage (); uint8_t * buf = m->GetPayload (); size_t len = 0; memcpy (buf, ident, 32); len += 32; - buf[len] = floodfill ? 1 : 0; // 1 router for now + buf[len] = routers.size (); len++; - if (floodfill) + for (auto it: routers) { - memcpy (buf + len, floodfill->GetIdentHash (), 32); + memcpy (buf + len, it, 32); len += 32; } memcpy (buf + len, i2p::context.GetRouterInfo ().GetIdentHash (), 32); diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 5b68792c..31d7dbf9 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -194,7 +194,7 @@ namespace tunnel I2NPMessage * CreateLeaseSetDatabaseLookupMsg (const i2p::data::IdentHash& dest, const std::set& excludedFloodfills, const i2p::tunnel::InboundTunnel * replyTunnel, const uint8_t * replyKey, const uint8_t * replyTag); - I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill); + I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, std::vector routers); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr, uint32_t replyToken = 0); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken = 0); diff --git a/NetDb.cpp b/NetDb.cpp index da564ed2..d03b994c 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -664,16 +664,15 @@ namespace data I2NPMessage * replyMsg = nullptr; + auto router = FindRouter (buf); + if (router) { - auto router = FindRouter (buf); - if (router) - { - LogPrint ("Requested RouterInfo ", key, " found"); - router->LoadBuffer (); - if (router->GetBuffer ()) - replyMsg = CreateDatabaseStoreMsg (router.get ()); - } + LogPrint ("Requested RouterInfo ", key, " found"); + router->LoadBuffer (); + if (router->GetBuffer ()) + replyMsg = CreateDatabaseStoreMsg (router.get ()); } + if (!replyMsg) { auto leaseSet = FindLeaseSet (buf); @@ -693,7 +692,14 @@ namespace data excludedRouters.insert (excluded); excluded += 32; } - replyMsg = CreateDatabaseSearchReply (buf, GetClosestFloodfill (buf, excludedRouters).get ()); + std::vector routers; + for (int i = 0; i < 3; i++) + { + auto floodfill = GetClosestFloodfill (buf, excludedRouters); + if (floodfill) + routers.push_back (floodfill->GetIdentHash ()); + } + replyMsg = CreateDatabaseSearchReply (buf, routers); } else excluded += numExcluded*32; // we don't care about exluded