mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-12 01:57:55 +00:00
send I2NP messages as shared_ptr
This commit is contained in:
parent
3a63f6775a
commit
25a163cdeb
@ -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<i2p::I2NPMessage *> {msg}));
|
||||
SendMessage (ident, ToSharedI2NPMessage (msg));
|
||||
}
|
||||
|
||||
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<i2p::I2NPMessage *>& msgs)
|
||||
{
|
||||
std::vector<std::shared_ptr<i2p::I2NPMessage> > msgs1;
|
||||
for (auto it: msgs)
|
||||
msgs1.push_back (ToSharedI2NPMessage (it));
|
||||
SendMessages (ident, msgs1);
|
||||
}
|
||||
|
||||
void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr<i2p::I2NPMessage> msg)
|
||||
{
|
||||
m_Service.post (std::bind (&Transports::PostMessages, this, ident, std::vector<std::shared_ptr<i2p::I2NPMessage> > {msg }));
|
||||
}
|
||||
|
||||
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs)
|
||||
{
|
||||
m_Service.post (std::bind (&Transports::PostMessages, this, ident, msgs));
|
||||
}
|
||||
|
||||
void Transports::PostMessages (i2p::data::IdentHash ident, std::vector<i2p::I2NPMessage *> msgs)
|
||||
void Transports::PostMessages (i2p::data::IdentHash ident, std::vector<std::shared_ptr<i2p::I2NPMessage> > 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<std::shared_ptr<i2p::I2NPMessage> > 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<i2p::I2NPMessage *>& msgs);
|
||||
void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); // deprecated
|
||||
void SendMessages (const i2p::data::IdentHash& ident, const std::vector<i2p::I2NPMessage *>& msgs); // deprecated
|
||||
void SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr<i2p::I2NPMessage> msg);
|
||||
void SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs);
|
||||
void CloseSession (std::shared_ptr<const i2p::data::RouterInfo> router);
|
||||
|
||||
void PeerConnected (std::shared_ptr<TransportSession> session);
|
||||
@ -110,7 +112,7 @@ namespace transport
|
||||
void Run ();
|
||||
void RequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, const i2p::data::IdentHash& ident);
|
||||
void HandleRequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, const i2p::data::IdentHash& ident);
|
||||
void PostMessages (i2p::data::IdentHash ident, std::vector<i2p::I2NPMessage *> msgs);
|
||||
void PostMessages (i2p::data::IdentHash ident, std::vector<std::shared_ptr<i2p::I2NPMessage> > msgs);
|
||||
void PostCloseSession (std::shared_ptr<const i2p::data::RouterInfo> router);
|
||||
bool ConnectToPeer (const i2p::data::IdentHash& ident, Peer& peer);
|
||||
void HandlePeerCleanupTimer (const boost::system::error_code& ecode);
|
||||
|
Loading…
Reference in New Issue
Block a user