Browse Source

DatabaseLookup for RouterInfo

pull/136/head
orignal 10 years ago
parent
commit
8812a45607
  1. 56
      I2NPProtocol.cpp
  2. 6
      I2NPProtocol.h
  3. 4
      NetDb.cpp

56
I2NPProtocol.cpp

@ -99,9 +99,8 @@ namespace i2p @@ -99,9 +99,8 @@ namespace i2p
return m;
}
I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,
uint32_t replyTunnelID, bool exploratory, std::set<i2p::data::IdentHash> * excludedPeers,
bool encryption, i2p::tunnel::TunnelPool * pool)
I2NPMessage * CreateRouterInfoDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,
uint32_t replyTunnelID, bool exploratory, std::set<i2p::data::IdentHash> * excludedPeers)
{
I2NPMessage * m = NewI2NPMessage ();
uint8_t * buf = m->GetPayload ();
@ -109,60 +108,37 @@ namespace i2p @@ -109,60 +108,37 @@ namespace i2p
buf += 32;
memcpy (buf, from, 32); // from
buf += 32;
uint8_t flag = exploratory ? 0x0C : 0x08; // 1000 - RI, 1100 -exporatory
if (replyTunnelID)
{
*buf = encryption ? 0x03: 0x01; // set delivery flag
*buf = flag | 0x01; // set delivery flag
htobe32buf (buf+1, replyTunnelID);
buf += 5;
}
else
{
encryption = false; // encryption can we set for tunnels only
*buf = 0; // flag
*buf = flag; // flag
buf++;
}
if (exploratory)
if (excludedPeers)
{
htobe16buf (buf,1); // one exlude record
int cnt = excludedPeers->size ();
htobe16buf (buf, cnt);
buf += 2;
// reply with non-floodfill routers only
memset (buf, 0, 32);
buf += 32;
}
else
{
if (excludedPeers)
{
int cnt = excludedPeers->size ();
htobe16buf (buf, cnt);
buf += 2;
for (auto& it: *excludedPeers)
{
memcpy (buf, it, 32);
buf += 32;
}
}
else
for (auto& it: *excludedPeers)
{
// nothing to exclude
htobuf16 (buf, 0);
buf += 2;
memcpy (buf, it, 32);
buf += 32;
}
}
if (encryption)
else
{
// session key and tag for reply
auto& rnd = i2p::context.GetRandomNumberGenerator ();
rnd.GenerateBlock (buf, 32); // key
buf[32] = 1; // 1 tag
rnd.GenerateBlock (buf + 33, 32); // tag
if (pool && pool->GetLocalDestination ())
pool->GetLocalDestination ()->SubmitSessionKey (buf, buf + 33); // introduce new key-tag to garlic engine
else
LogPrint ("Destination for encrypteed reply not specified");
buf += 65;
// nothing to exclude
htobuf16 (buf, 0);
buf += 2;
}
m->len += (buf - m->GetPayload ());
FillI2NPMessageHeader (m, eI2NPDatabaseLookup);
return m;

6
I2NPProtocol.h

@ -189,10 +189,8 @@ namespace tunnel @@ -189,10 +189,8 @@ namespace tunnel
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from = nullptr);
I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID);
I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,
uint32_t replyTunnelID, bool exploratory = false,
std::set<i2p::data::IdentHash> * excludedPeers = nullptr, bool encryption = false,
i2p::tunnel::TunnelPool * pool = nullptr);
I2NPMessage * CreateRouterInfoDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,
uint32_t replyTunnelID, bool exploratory = false, std::set<i2p::data::IdentHash> * excludedPeers = nullptr);
I2NPMessage * CreateLeaseSetDatabaseLookupMsg (const i2p::data::IdentHash& dest,
const std::set<i2p::data::IdentHash>& excludedFloodfills,
const i2p::tunnel::InboundTunnel * replyTunnel, const uint8_t * replyKey, const uint8_t * replyTag);

4
NetDb.cpp

@ -25,7 +25,7 @@ namespace data @@ -25,7 +25,7 @@ namespace data
I2NPMessage * RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
const i2p::tunnel::InboundTunnel * replyTunnel)
{
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination,
I2NPMessage * msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory,
&m_ExcludedPeers);
m_ExcludedPeers.insert (router->GetIdentHash ());
@ -36,7 +36,7 @@ namespace data @@ -36,7 +36,7 @@ namespace data
I2NPMessage * RequestedDestination::CreateRequestMessage (const IdentHash& floodfill)
{
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination,
I2NPMessage * msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers);
m_ExcludedPeers.insert (floodfill);
m_LastRouter = nullptr;

Loading…
Cancel
Save