From d65257c7b0a15c25c189b17f7327960a781260ad Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 16 Jun 2015 13:32:42 -0400 Subject: [PATCH] pass I2NP as shared_ptr to netDB --- I2NPProtocol.cpp | 2 +- NetDb.cpp | 12 ++++++------ NetDb.h | 4 ++-- Tunnel.cpp | 4 ++-- TunnelEndpoint.cpp | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 3948afec..5d7afdfd 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -555,7 +555,7 @@ namespace i2p case eI2NPDatabaseSearchReply: case eI2NPDatabaseLookup: // forward to netDb - i2p::data::netdb.PostI2NPMsg (msg); + i2p::data::netdb.PostI2NPMsg (ToSharedI2NPMessage (msg)); break; case eI2NPDeliveryStatus: { diff --git a/NetDb.cpp b/NetDb.cpp index 5ba3c17d..a72e919a 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -92,7 +92,7 @@ namespace data { try { - I2NPMessage * msg = m_Queue.GetNextWithTimeout (15000); // 15 sec + auto msg = m_Queue.GetNextWithTimeout (15000); // 15 sec if (msg) { int numMsgs = 0; @@ -102,19 +102,19 @@ namespace data { case eI2NPDatabaseStore: LogPrint ("DatabaseStore"); - HandleDatabaseStoreMsg (ToSharedI2NPMessage (msg)); + HandleDatabaseStoreMsg (msg); break; case eI2NPDatabaseSearchReply: LogPrint ("DatabaseSearchReply"); - HandleDatabaseSearchReplyMsg (ToSharedI2NPMessage (msg)); + HandleDatabaseSearchReplyMsg (msg); break; case eI2NPDatabaseLookup: LogPrint ("DatabaseLookup"); - HandleDatabaseLookupMsg (ToSharedI2NPMessage (msg)); + HandleDatabaseLookupMsg (msg); break; default: // WTF? LogPrint (eLogError, "NetDb: unexpected message type ", msg->GetTypeID ()); - i2p::HandleI2NPMessage (msg); + //i2p::HandleI2NPMessage (msg); } if (numMsgs > 100) break; msg = m_Queue.Get (); @@ -912,7 +912,7 @@ namespace data return nullptr; // seems we have too few routers } - void NetDb::PostI2NPMsg (I2NPMessage * msg) + void NetDb::PostI2NPMsg (std::shared_ptr msg) { if (msg) m_Queue.Put (msg); } diff --git a/NetDb.h b/NetDb.h index 6b96f155..5028819e 100644 --- a/NetDb.h +++ b/NetDb.h @@ -56,7 +56,7 @@ namespace data std::shared_ptr GetClosestNonFloodfill (const IdentHash& destination, const std::set& excluded) const; void SetUnreachable (const IdentHash& ident, bool unreachable); - void PostI2NPMsg (I2NPMessage * msg); + void PostI2NPMsg (std::shared_ptr msg); void Reseed (); @@ -89,7 +89,7 @@ namespace data bool m_IsRunning; std::thread * m_Thread; - i2p::util::Queue m_Queue; // of I2NPDatabaseStoreMsg + i2p::util::Queue > m_Queue; // of I2NPDatabaseStoreMsg Reseeder * m_Reseeder; diff --git a/Tunnel.cpp b/Tunnel.cpp index 59a9de2b..7c8714d9 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -453,8 +453,8 @@ namespace tunnel // transit DatabaseStore my contain new/updated RI // or DatabaseSearchReply with new routers auto ds = NewI2NPMessage (); - *ds = *msg; - i2p::data::netdb.PostI2NPMsg (ds); + *ds = *msg; // TODO: don't copy once msg is shared_ptr + i2p::data::netdb.PostI2NPMsg (ToSharedI2NPMessage (ds)); } tunnel->SendTunnelDataMsg (msg); } diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 24d86e57..db7ed7a6 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -267,8 +267,8 @@ namespace tunnel { // catch RI or reply with new list of routers auto ds = NewI2NPShortMessage (); - *ds = *(msg.data); - i2p::data::netdb.PostI2NPMsg (ds); + *ds = *(msg.data); // TODO: don't copy once msg.data is shared_ptr + i2p::data::netdb.PostI2NPMsg (ToSharedI2NPMessage (ds)); } i2p::transport::transports.SendMessage (msg.hash, msg.data); }