diff --git a/Transports.cpp b/Transports.cpp index c24bd508..a4c8d1a8 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -215,21 +215,39 @@ namespace transport void Transports::SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg) { - m_Service.post (std::bind (&Transports::PostMessages, this, ident, std::vector {msg})); + SendMessage (ident, ToSharedI2NPMessage (msg)); } void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector& msgs) + { + std::vector > msgs1; + for (auto it: msgs) + msgs1.push_back (ToSharedI2NPMessage (it)); + SendMessages (ident, msgs1); + } + + void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr msg) + { + m_Service.post (std::bind (&Transports::PostMessages, this, ident, std::vector > {msg })); + } + + void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector >& msgs) { m_Service.post (std::bind (&Transports::PostMessages, this, ident, msgs)); } - void Transports::PostMessages (i2p::data::IdentHash ident, std::vector msgs) + void Transports::PostMessages (i2p::data::IdentHash ident, std::vector > msgs) { if (ident == i2p::context.GetRouterInfo ().GetIdentHash ()) { // we send it to ourself for (auto it: msgs) - i2p::HandleI2NPMessage (it); + { + // TODO: + auto m = NewI2NPMessage (); + *m = *(it); + i2p::HandleI2NPMessage (m); + } return; } auto it = m_Peers.find (ident); @@ -247,25 +265,14 @@ namespace transport { LogPrint (eLogError, "Transports::PostMessages ", ex.what ()); } - if (!connected) - { - for (auto it1: msgs) - DeleteI2NPMessage (it1); - return; - } + if (!connected) return; } if (!it->second.sessions.empty ()) - { - // TODO: remove this copy operation later - std::vector > msgs1; - for (auto it1: msgs) - msgs1.push_back (ToSharedI2NPMessage(it1)); - it->second.sessions.front ()->SendI2NPMessages (msgs1); - } + it->second.sessions.front ()->SendI2NPMessages (msgs); else { for (auto it1: msgs) - it->second.delayedMessages.push_back (ToSharedI2NPMessage(it1)); + it->second.delayedMessages.push_back (it1); } } diff --git a/Transports.h b/Transports.h index d660a36c..b29d7f1a 100644 --- a/Transports.h +++ b/Transports.h @@ -87,8 +87,10 @@ namespace transport i2p::transport::DHKeysPair * GetNextDHKeysPair (); void ReuseDHKeysPair (DHKeysPair * pair); - void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); - void SendMessages (const i2p::data::IdentHash& ident, const std::vector& msgs); + void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); // deprecated + void SendMessages (const i2p::data::IdentHash& ident, const std::vector& msgs); // deprecated + void SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr msg); + void SendMessages (const i2p::data::IdentHash& ident, const std::vector >& msgs); void CloseSession (std::shared_ptr router); void PeerConnected (std::shared_ptr session); @@ -110,7 +112,7 @@ namespace transport void Run (); void RequestComplete (std::shared_ptr r, const i2p::data::IdentHash& ident); void HandleRequestComplete (std::shared_ptr r, const i2p::data::IdentHash& ident); - void PostMessages (i2p::data::IdentHash ident, std::vector msgs); + void PostMessages (i2p::data::IdentHash ident, std::vector > msgs); void PostCloseSession (std::shared_ptr router); bool ConnectToPeer (const i2p::data::IdentHash& ident, Peer& peer); void HandlePeerCleanupTimer (const boost::system::error_code& ecode);