Browse Source

send 3 closest floodfills

pull/151/head
orignal 10 years ago
parent
commit
8ad9f2681c
  1. 8
      I2NPProtocol.cpp
  2. 2
      I2NPProtocol.h
  3. 12
      NetDb.cpp

8
I2NPProtocol.cpp

@ -184,18 +184,18 @@ namespace i2p
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident,
const i2p::data::RouterInfo * floodfill) std::vector<i2p::data::IdentHash> routers)
{ {
I2NPMessage * m = NewI2NPShortMessage (); I2NPMessage * m = NewI2NPShortMessage ();
uint8_t * buf = m->GetPayload (); uint8_t * buf = m->GetPayload ();
size_t len = 0; size_t len = 0;
memcpy (buf, ident, 32); memcpy (buf, ident, 32);
len += 32; len += 32;
buf[len] = floodfill ? 1 : 0; // 1 router for now buf[len] = routers.size ();
len++; len++;
if (floodfill) for (auto it: routers)
{ {
memcpy (buf + len, floodfill->GetIdentHash (), 32); memcpy (buf + len, it, 32);
len += 32; len += 32;
} }
memcpy (buf + len, i2p::context.GetRouterInfo ().GetIdentHash (), 32); memcpy (buf + len, i2p::context.GetRouterInfo ().GetIdentHash (), 32);

2
I2NPProtocol.h

@ -194,7 +194,7 @@ namespace tunnel
I2NPMessage * CreateLeaseSetDatabaseLookupMsg (const i2p::data::IdentHash& dest, I2NPMessage * CreateLeaseSetDatabaseLookupMsg (const i2p::data::IdentHash& dest,
const std::set<i2p::data::IdentHash>& excludedFloodfills, const std::set<i2p::data::IdentHash>& excludedFloodfills,
const i2p::tunnel::InboundTunnel * replyTunnel, const uint8_t * replyKey, const uint8_t * replyTag); 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<i2p::data::IdentHash> routers);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr, uint32_t replyToken = 0); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr, uint32_t replyToken = 0);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken = 0); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken = 0);

12
NetDb.cpp

@ -664,7 +664,6 @@ namespace data
I2NPMessage * replyMsg = nullptr; I2NPMessage * replyMsg = nullptr;
{
auto router = FindRouter (buf); auto router = FindRouter (buf);
if (router) if (router)
{ {
@ -673,7 +672,7 @@ namespace data
if (router->GetBuffer ()) if (router->GetBuffer ())
replyMsg = CreateDatabaseStoreMsg (router.get ()); replyMsg = CreateDatabaseStoreMsg (router.get ());
} }
}
if (!replyMsg) if (!replyMsg)
{ {
auto leaseSet = FindLeaseSet (buf); auto leaseSet = FindLeaseSet (buf);
@ -693,7 +692,14 @@ namespace data
excludedRouters.insert (excluded); excludedRouters.insert (excluded);
excluded += 32; excluded += 32;
} }
replyMsg = CreateDatabaseSearchReply (buf, GetClosestFloodfill (buf, excludedRouters).get ()); std::vector<IdentHash> 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 else
excluded += numExcluded*32; // we don't care about exluded excluded += numExcluded*32; // we don't care about exluded

Loading…
Cancel
Save