Browse Source

pass I2NP as shared_ptr to netDB

pull/210/head
orignal 10 years ago
parent
commit
d65257c7b0
  1. 2
      I2NPProtocol.cpp
  2. 12
      NetDb.cpp
  3. 4
      NetDb.h
  4. 4
      Tunnel.cpp
  5. 4
      TunnelEndpoint.cpp

2
I2NPProtocol.cpp

@ -555,7 +555,7 @@ namespace i2p
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
case eI2NPDatabaseLookup: case eI2NPDatabaseLookup:
// forward to netDb // forward to netDb
i2p::data::netdb.PostI2NPMsg (msg); i2p::data::netdb.PostI2NPMsg (ToSharedI2NPMessage (msg));
break; break;
case eI2NPDeliveryStatus: case eI2NPDeliveryStatus:
{ {

12
NetDb.cpp

@ -92,7 +92,7 @@ namespace data
{ {
try try
{ {
I2NPMessage * msg = m_Queue.GetNextWithTimeout (15000); // 15 sec auto msg = m_Queue.GetNextWithTimeout (15000); // 15 sec
if (msg) if (msg)
{ {
int numMsgs = 0; int numMsgs = 0;
@ -102,19 +102,19 @@ namespace data
{ {
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
LogPrint ("DatabaseStore"); LogPrint ("DatabaseStore");
HandleDatabaseStoreMsg (ToSharedI2NPMessage (msg)); HandleDatabaseStoreMsg (msg);
break; break;
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
LogPrint ("DatabaseSearchReply"); LogPrint ("DatabaseSearchReply");
HandleDatabaseSearchReplyMsg (ToSharedI2NPMessage (msg)); HandleDatabaseSearchReplyMsg (msg);
break; break;
case eI2NPDatabaseLookup: case eI2NPDatabaseLookup:
LogPrint ("DatabaseLookup"); LogPrint ("DatabaseLookup");
HandleDatabaseLookupMsg (ToSharedI2NPMessage (msg)); HandleDatabaseLookupMsg (msg);
break; break;
default: // WTF? default: // WTF?
LogPrint (eLogError, "NetDb: unexpected message type ", msg->GetTypeID ()); LogPrint (eLogError, "NetDb: unexpected message type ", msg->GetTypeID ());
i2p::HandleI2NPMessage (msg); //i2p::HandleI2NPMessage (msg);
} }
if (numMsgs > 100) break; if (numMsgs > 100) break;
msg = m_Queue.Get (); msg = m_Queue.Get ();
@ -912,7 +912,7 @@ namespace data
return nullptr; // seems we have too few routers return nullptr; // seems we have too few routers
} }
void NetDb::PostI2NPMsg (I2NPMessage * msg) void NetDb::PostI2NPMsg (std::shared_ptr<I2NPMessage> msg)
{ {
if (msg) m_Queue.Put (msg); if (msg) m_Queue.Put (msg);
} }

4
NetDb.h

@ -56,7 +56,7 @@ namespace data
std::shared_ptr<const RouterInfo> GetClosestNonFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const; std::shared_ptr<const RouterInfo> GetClosestNonFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
void SetUnreachable (const IdentHash& ident, bool unreachable); void SetUnreachable (const IdentHash& ident, bool unreachable);
void PostI2NPMsg (I2NPMessage * msg); void PostI2NPMsg (std::shared_ptr<I2NPMessage> msg);
void Reseed (); void Reseed ();
@ -89,7 +89,7 @@ namespace data
bool m_IsRunning; bool m_IsRunning;
std::thread * m_Thread; std::thread * m_Thread;
i2p::util::Queue<I2NPMessage *> m_Queue; // of I2NPDatabaseStoreMsg i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue; // of I2NPDatabaseStoreMsg
Reseeder * m_Reseeder; Reseeder * m_Reseeder;

4
Tunnel.cpp

@ -453,8 +453,8 @@ namespace tunnel
// transit DatabaseStore my contain new/updated RI // transit DatabaseStore my contain new/updated RI
// or DatabaseSearchReply with new routers // or DatabaseSearchReply with new routers
auto ds = NewI2NPMessage (); auto ds = NewI2NPMessage ();
*ds = *msg; *ds = *msg; // TODO: don't copy once msg is shared_ptr
i2p::data::netdb.PostI2NPMsg (ds); i2p::data::netdb.PostI2NPMsg (ToSharedI2NPMessage (ds));
} }
tunnel->SendTunnelDataMsg (msg); tunnel->SendTunnelDataMsg (msg);
} }

4
TunnelEndpoint.cpp

@ -267,8 +267,8 @@ namespace tunnel
{ {
// catch RI or reply with new list of routers // catch RI or reply with new list of routers
auto ds = NewI2NPShortMessage (); auto ds = NewI2NPShortMessage ();
*ds = *(msg.data); *ds = *(msg.data); // TODO: don't copy once msg.data is shared_ptr
i2p::data::netdb.PostI2NPMsg (ds); i2p::data::netdb.PostI2NPMsg (ToSharedI2NPMessage (ds));
} }
i2p::transport::transports.SendMessage (msg.hash, msg.data); i2p::transport::transports.SendMessage (msg.hash, msg.data);
} }

Loading…
Cancel
Save