Browse Source

send RouterInfo if found by DatabseLookup

pull/93/head
orignal 10 years ago
parent
commit
d512c90193
  1. 21
      I2NPProtocol.cpp
  2. 2
      I2NPProtocol.h
  3. 24
      NetDb.cpp
  4. 2
      RouterInfo.cpp
  5. 2
      RouterInfo.h

21
I2NPProtocol.cpp

@ -172,23 +172,26 @@ namespace i2p @@ -172,23 +172,26 @@ namespace i2p
return m;
}
I2NPMessage * CreateDatabaseStoreMsg ()
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router)
{
if (!router) // we send own RouterInfo
router = &context.GetRouterInfo ();
I2NPMessage * m = NewI2NPMessage ();
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload ();
memcpy (msg->key, context.GetRouterInfo ().GetIdentHash (), 32);
memcpy (msg->key, router->GetIdentHash (), 32);
msg->type = 0;
msg->replyToken = 0;
CryptoPP::Gzip compressor;
compressor.Put (context.GetRouterInfo ().GetBuffer (), context.GetRouterInfo ().GetBufferLen ());
compressor.Put (router->GetBuffer (), router->GetBufferLen ());
compressor.MessageEnd();
// WARNING!!! MaxRetrievable() return uint64_t. Åñòü ïîäîçðåíèå, ÷òî ÷òî-òî íå òàê
int size = compressor.MaxRetrievable ();
auto size = compressor.MaxRetrievable ();
uint8_t * buf = m->GetPayload () + sizeof (I2NPDatabaseStoreMsg);
*(uint16_t *)buf = htobe16 (size); // size
buf += 2;
// TODO: check if size doesn't exceed buffer
compressor.Get (buf, size);
m->len += sizeof (I2NPDatabaseStoreMsg) + 2 + size; // payload size
FillI2NPMessageHeader (m, eI2NPDatabaseStore);
@ -504,15 +507,9 @@ namespace i2p @@ -504,15 +507,9 @@ namespace i2p
i2p::garlic::routing.HandleGarlicMessage (msg);
break;
case eI2NPDatabaseStore:
LogPrint ("DatabaseStore");
i2p::data::netdb.PostI2NPMsg (msg);
break;
case eI2NPDatabaseSearchReply:
LogPrint ("DatabaseSearchReply");
i2p::data::netdb.PostI2NPMsg (msg);
break;
case eI2NPDatabaseLookup:
LogPrint ("DatabaseLookup");
// forward to netDb
i2p::data::netdb.PostI2NPMsg (msg);
break;
case eI2NPDeliveryStatus:

2
I2NPProtocol.h

@ -156,7 +156,7 @@ namespace tunnel @@ -156,7 +156,7 @@ namespace tunnel
std::set<i2p::data::IdentHash> * excludedPeers = nullptr, bool encryption = false);
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident);
I2NPMessage * CreateDatabaseStoreMsg ();
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);
I2NPBuildRequestRecordClearText CreateBuildRequestRecord (
const uint8_t * ourIdent, uint32_t receiveTunnelID,

24
NetDb.cpp

@ -109,13 +109,16 @@ namespace data @@ -109,13 +109,16 @@ namespace data
switch (msg->GetHeader ()->typeID)
{
case eI2NPDatabaseStore:
LogPrint ("DatabaseStore");
HandleDatabaseStoreMsg (msg->GetPayload (), msg->GetLength ()); // TODO
i2p::DeleteI2NPMessage (msg);
break;
case eI2NPDatabaseSearchReply:
LogPrint ("DatabaseSearchReply");
HandleDatabaseSearchReplyMsg (msg);
break;
case eI2NPDatabaseLookup:
LogPrint ("DatabaseLookup");
HandleDatabaseLookupMsg (msg);
break;
default: // WTF?
@ -560,12 +563,23 @@ namespace data @@ -560,12 +563,23 @@ namespace data
uint32_t replyTunnelID = 0;
if (flag & 0x01) //reply to tunnel
replyTunnelID = be32toh (*(uint32_t *)(buf + 64));
// TODO: implement search. We send non-found for now
I2NPMessage * replyMsg = CreateDatabaseSearchReply (buf);
if (replyTunnelID)
i2p::tunnel::tunnels.GetNextOutboundTunnel ()->SendTunnelDataMsg (buf+32, replyTunnelID, replyMsg);
I2NPMessage * replyMsg = nullptr;
auto router = FindRouter (buf);
if (router)
{
router->LoadBuffer ();
replyMsg = CreateDatabaseStoreMsg (router);
}
else
i2p::transports.SendMessage (buf, replyMsg);
replyMsg = CreateDatabaseSearchReply (buf);
if (replyMsg)
{
if (replyTunnelID)
i2p::tunnel::tunnels.GetNextOutboundTunnel ()->SendTunnelDataMsg (buf+32, replyTunnelID, replyMsg);
else
i2p::transports.SendMessage (buf, replyMsg);
}
i2p::DeleteI2NPMessage (msg);
}

2
RouterInfo.cpp

@ -346,7 +346,7 @@ namespace data @@ -346,7 +346,7 @@ namespace data
s.write (properties.str ().c_str (), properties.str ().size ());
}
const uint8_t * RouterInfo::GetBuffer ()
const uint8_t * RouterInfo::LoadBuffer ()
{
if (!m_Buffer)
{

2
RouterInfo.h

@ -99,7 +99,7 @@ namespace data @@ -99,7 +99,7 @@ namespace data
bool IsUnreachable () const { return m_IsUnreachable; };
const uint8_t * GetBuffer () const { return m_Buffer; };
const uint8_t * GetBuffer (); // load if necessary
const uint8_t * LoadBuffer (); // load if necessary
int GetBufferLen () const { return m_BufferLen; };
void CreateBuffer ();

Loading…
Cancel
Save