Browse Source

LeaseSet database lookup

pull/125/merge
orignal 10 years ago
parent
commit
7bfb73dacf
  1. 10
      Destination.cpp
  2. 39
      I2NPProtocol.cpp
  3. 4
      I2NPProtocol.h

10
Destination.cpp

@ -457,9 +457,15 @@ namespace client
request->requestTime = i2p::util::GetSecondsSinceEpoch (); request->requestTime = i2p::util::GetSecondsSinceEpoch ();
request->requestTimeoutTimer.cancel (); request->requestTimeoutTimer.cancel ();
CryptoPP::AutoSeededRandomPool rnd;
uint8_t replyKey[32], replyTag[32];
rnd.GenerateBlock (replyKey, 32); // random session key
rnd.GenerateBlock (replyTag, 32); // random session tag
AddSessionKey (replyKey, replyTag);
I2NPMessage * msg = WrapMessage (*nextFloodfill, I2NPMessage * msg = WrapMessage (*nextFloodfill,
CreateDatabaseLookupMsg (dest, replyTunnel->GetNextIdentHash (), CreateLeaseSetDatabaseLookupMsg (dest, request->excluded,
replyTunnel->GetNextTunnelID (), false, &request->excluded, true, m_Pool)); replyTunnel, replyKey, replyTag));
outboundTunnel->SendTunnelDataMsg ( outboundTunnel->SendTunnelDataMsg (
{ {
i2p::tunnel::TunnelMessageBlock i2p::tunnel::TunnelMessageBlock

39
I2NPProtocol.cpp

@ -171,6 +171,45 @@ namespace i2p
return m; return m;
} }
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)
{
I2NPMessage * m = NewI2NPMessage ();
uint8_t * buf = m->GetPayload ();
memcpy (buf, dest, 32); // key
buf += 32;
memcpy (buf, replyTunnel->GetNextIdentHash (), 32); // reply tunnel GW
buf += 32;
*buf = 7; // flags (01 - tunnel, 10 - encrypted, 0100 - LS lookup
htobe32buf (buf + 1, replyTunnel->GetNextTunnelID ()); // reply tunnel ID
buf += 5;
// excluded
int cnt = excludedFloodfills.size ();
htobe16buf (buf, cnt);
buf += 2;
if (cnt > 0)
{
for (auto& it: excludedFloodfills)
{
memcpy (buf, it, 32);
buf += 32;
}
}
// encryption
memcpy (buf, replyKey, 32);
buf[32] = 1; // 1 tag
memcpy (buf + 33, replyTag, 32);
buf += 65;
m->len += (buf - m->GetPayload ());
FillI2NPMessageHeader (m, eI2NPDatabaseLookup);
return m;
}
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident,
const i2p::data::RouterInfo * floodfill) const i2p::data::RouterInfo * floodfill)
{ {

4
I2NPProtocol.h

@ -5,6 +5,7 @@
#include <set> #include <set>
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "I2PEndian.h"
#include "Identity.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "LeaseSet.h" #include "LeaseSet.h"
@ -180,6 +181,9 @@ namespace tunnel
uint32_t replyTunnelID, bool exploratory = false, uint32_t replyTunnelID, bool exploratory = false,
std::set<i2p::data::IdentHash> * excludedPeers = nullptr, bool encryption = false, std::set<i2p::data::IdentHash> * excludedPeers = nullptr, bool encryption = false,
i2p::tunnel::TunnelPool * pool = nullptr); i2p::tunnel::TunnelPool * pool = 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);
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill); I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);

Loading…
Cancel
Save