Browse Source

check tunnel where DatabaseStore message comes from

pull/102/head
orignal 10 years ago
parent
commit
d1a3f11c7a
  1. 4
      Garlic.cpp
  2. 3
      I2NPProtocol.cpp
  3. 2
      I2NPProtocol.h
  4. 14
      NetDb.cpp
  5. 6
      NetDb.h

4
Garlic.cpp

@ -429,7 +429,7 @@ namespace garlic
{ {
case eGarlicDeliveryTypeLocal: case eGarlicDeliveryTypeLocal:
LogPrint ("Garlic type local"); LogPrint ("Garlic type local");
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from));
break; break;
case eGarlicDeliveryTypeDestination: case eGarlicDeliveryTypeDestination:
{ {
@ -458,7 +458,7 @@ namespace garlic
tunnel = from->GetTunnelPool ()->GetNextOutboundTunnel (); tunnel = from->GetTunnelPool ()->GetNextOutboundTunnel ();
if (tunnel) // we have send it through an outbound tunnel if (tunnel) // we have send it through an outbound tunnel
{ {
I2NPMessage * msg = CreateI2NPMessage (buf, GetI2NPMessageLength (buf)); I2NPMessage * msg = CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from);
tunnel->SendTunnelDataMsg (gwHash, gwTunnel, msg); tunnel->SendTunnelDataMsg (gwHash, gwTunnel, msg);
} }
else else

3
I2NPProtocol.cpp

@ -76,11 +76,12 @@ namespace i2p
return msg; return msg;
} }
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len) I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from)
{ {
I2NPMessage * msg = NewI2NPMessage (); I2NPMessage * msg = NewI2NPMessage ();
memcpy (msg->GetBuffer (), buf, len); memcpy (msg->GetBuffer (), buf, len);
msg->len = msg->offset + len; msg->len = msg->offset + len;
msg->from = from;
return msg; return msg;
} }

2
I2NPProtocol.h

@ -163,7 +163,7 @@ namespace tunnel
void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0); void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader (I2NPMessage * msg); void RenewI2NPMessageHeader (I2NPMessage * msg);
I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0); I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0);
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len); I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from = nullptr);
I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID); I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID);
I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from, I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,

14
NetDb.cpp

@ -111,8 +111,7 @@ namespace data
{ {
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
LogPrint ("DatabaseStore"); LogPrint ("DatabaseStore");
HandleDatabaseStoreMsg (msg->GetPayload (), be16toh (msg->GetHeader ()->size)); // TODO HandleDatabaseStoreMsg (msg);
i2p::DeleteI2NPMessage (msg);
break; break;
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
LogPrint ("DatabaseSearchReply"); LogPrint ("DatabaseSearchReply");
@ -166,7 +165,7 @@ namespace data
} }
} }
void NetDb::AddRouterInfo (const IdentHash& ident, uint8_t * buf, int len) void NetDb::AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len)
{ {
DeleteRequestedDestination (ident); DeleteRequestedDestination (ident);
auto it = m_RouterInfos.find(ident); auto it = m_RouterInfos.find(ident);
@ -187,7 +186,7 @@ namespace data
} }
} }
void NetDb::AddLeaseSet (const IdentHash& ident, uint8_t * buf, int len) void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len)
{ {
bool unsolicited = !DeleteRequestedDestination (ident); bool unsolicited = !DeleteRequestedDestination (ident);
auto it = m_LeaseSets.find(ident); auto it = m_LeaseSets.find(ident);
@ -408,8 +407,10 @@ namespace data
} }
} }
void NetDb::HandleDatabaseStoreMsg (uint8_t * buf, size_t len) void NetDb::HandleDatabaseStoreMsg (I2NPMessage * m)
{ {
const uint8_t * buf = m->GetPayload ();
size_t len = be16toh (m->GetHeader ()->size);
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)buf; I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)buf;
size_t offset = sizeof (I2NPDatabaseStoreMsg); size_t offset = sizeof (I2NPDatabaseStoreMsg);
if (msg->replyToken) if (msg->replyToken)
@ -437,6 +438,7 @@ namespace data
decompressor.Get (uncompressed, uncomressedSize); decompressor.Get (uncompressed, uncomressedSize);
AddRouterInfo (msg->key, uncompressed, uncomressedSize); AddRouterInfo (msg->key, uncompressed, uncomressedSize);
} }
i2p::DeleteI2NPMessage (m);
} }
void NetDb::HandleDatabaseSearchReplyMsg (I2NPMessage * msg) void NetDb::HandleDatabaseSearchReplyMsg (I2NPMessage * msg)

6
NetDb.h

@ -62,8 +62,8 @@ namespace data
void Start (); void Start ();
void Stop (); void Stop ();
void AddRouterInfo (const IdentHash& ident, uint8_t * buf, int len); void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
void AddLeaseSet (const IdentHash& ident, uint8_t * buf, int len); void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len);
RouterInfo * FindRouter (const IdentHash& ident) const; RouterInfo * FindRouter (const IdentHash& ident) const;
LeaseSet * FindLeaseSet (const IdentHash& destination) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const;
const IdentHash * FindAddress (const std::string& address) { return m_AddressBook.FindAddress (address); }; // TODO: move AddressBook away from NetDb const IdentHash * FindAddress (const std::string& address) { return m_AddressBook.FindAddress (address); }; // TODO: move AddressBook away from NetDb
@ -75,7 +75,7 @@ namespace data
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false, void RequestDestination (const IdentHash& destination, bool isLeaseSet = false,
i2p::tunnel::TunnelPool * pool = nullptr); i2p::tunnel::TunnelPool * pool = nullptr);
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len); void HandleDatabaseStoreMsg (I2NPMessage * msg);
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg); void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
void HandleDatabaseLookupMsg (I2NPMessage * msg); void HandleDatabaseLookupMsg (I2NPMessage * msg);

Loading…
Cancel
Save