Browse Source

moved handling of DatabaseLookup to netDb's thread

pull/93/head
orignal 11 years ago
parent
commit
5492deff21
  1. 26
      I2NPProtocol.cpp
  2. 1
      I2NPProtocol.h
  3. 44
      NetDb.cpp
  4. 1
      NetDb.h

26
I2NPProtocol.cpp

@ -160,24 +160,6 @@ namespace i2p
return m; return m;
} }
void HandleDatabaseLookupMsg (uint8_t * buf, size_t len)
{
char key[48];
int l = i2p::data::ByteStreamToBase64 (buf, 32, key, 48);
key[l] = 0;
LogPrint ("DatabaseLookup for ", key, " recieved");
uint8_t flag = buf[64];
uint32_t replyTunnelID = 0;
if (flag & 0x01) //reply to yunnel
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);
else
i2p::transports.SendMessage (buf, replyMsg);
}
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident) I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident)
{ {
I2NPMessage * m = NewI2NPMessage (); I2NPMessage * m = NewI2NPMessage ();
@ -498,10 +480,6 @@ namespace i2p
LogPrint ("TunnelBuildReply"); LogPrint ("TunnelBuildReply");
// TODO: // TODO:
break; break;
case eI2NPDatabaseLookup:
LogPrint ("DatabaseLookup");
HandleDatabaseLookupMsg (buf, size);
break;
default: default:
LogPrint ("Unexpected message ", (int)header->typeID); LogPrint ("Unexpected message ", (int)header->typeID);
} }
@ -533,6 +511,10 @@ namespace i2p
LogPrint ("DatabaseSearchReply"); LogPrint ("DatabaseSearchReply");
i2p::data::netdb.PostI2NPMsg (msg); i2p::data::netdb.PostI2NPMsg (msg);
break; break;
case eI2NPDatabaseLookup:
LogPrint ("DatabaseLookup");
i2p::data::netdb.PostI2NPMsg (msg);
break;
case eI2NPDeliveryStatus: case eI2NPDeliveryStatus:
LogPrint ("DeliveryStatus"); LogPrint ("DeliveryStatus");
if (msg->from && msg->from->GetTunnelPool ()) if (msg->from && msg->from->GetTunnelPool ())

1
I2NPProtocol.h

@ -154,7 +154,6 @@ namespace tunnel
I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from, I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,
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);
void HandleDatabaseLookupMsg (uint8_t * buf, size_t len);
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident); I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident);
I2NPMessage * CreateDatabaseStoreMsg (); I2NPMessage * CreateDatabaseStoreMsg ();

44
NetDb.cpp

@ -106,17 +106,21 @@ namespace data
{ {
while (msg) while (msg)
{ {
if (msg->GetHeader ()->typeID == eI2NPDatabaseStore) switch (msg->GetHeader ()->typeID)
{ {
HandleDatabaseStoreMsg (msg->GetPayload (), msg->GetLength ()); // TODO case eI2NPDatabaseStore:
i2p::DeleteI2NPMessage (msg); HandleDatabaseStoreMsg (msg->GetPayload (), msg->GetLength ()); // TODO
} i2p::DeleteI2NPMessage (msg);
else if (msg->GetHeader ()->typeID == eI2NPDatabaseSearchReply) break;
HandleDatabaseSearchReplyMsg (msg); case eI2NPDatabaseSearchReply:
else // WTF? HandleDatabaseSearchReplyMsg (msg);
{ break;
LogPrint ("NetDb: unexpected message type ", msg->GetHeader ()->typeID); case eI2NPDatabaseLookup:
i2p::HandleI2NPMessage (msg); HandleDatabaseLookupMsg (msg);
break;
default: // WTF?
LogPrint ("NetDb: unexpected message type ", msg->GetHeader ()->typeID);
i2p::HandleI2NPMessage (msg);
} }
msg = m_Queue.Get (); msg = m_Queue.Get ();
} }
@ -545,6 +549,26 @@ namespace data
i2p::DeleteI2NPMessage (msg); i2p::DeleteI2NPMessage (msg);
} }
void NetDb::HandleDatabaseLookupMsg (I2NPMessage * msg)
{
uint8_t * buf = msg->GetPayload ();
char key[48];
int l = i2p::data::ByteStreamToBase64 (buf, 32, key, 48);
key[l] = 0;
LogPrint ("DatabaseLookup for ", key, " recieved");
uint8_t flag = buf[64];
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);
else
i2p::transports.SendMessage (buf, replyMsg);
i2p::DeleteI2NPMessage (msg);
}
void NetDb::Explore (int numDestinations) void NetDb::Explore (int numDestinations)
{ {
// clean up previous exploratories // clean up previous exploratories

1
NetDb.h

@ -70,6 +70,7 @@ namespace data
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len); void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg); void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
void HandleDatabaseLookupMsg (I2NPMessage * msg);
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr) const; const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr) const;

Loading…
Cancel
Save