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

2
I2NPProtocol.h

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

24
NetDb.cpp

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

2
RouterInfo.cpp

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

2
RouterInfo.h

@ -99,7 +99,7 @@ namespace data
bool IsUnreachable () const { return m_IsUnreachable; }; bool IsUnreachable () const { return m_IsUnreachable; };
const uint8_t * GetBuffer () const { return m_Buffer; }; 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; }; int GetBufferLen () const { return m_BufferLen; };
void CreateBuffer (); void CreateBuffer ();

Loading…
Cancel
Save