Browse Source

hold I2NP message for 5 seconds if router is not in netDb

pull/93/head
orignal 10 years ago
parent
commit
9557adf8c2
  1. 22
      Transports.cpp
  2. 2
      Transports.h

22
Transports.cpp

@ -258,11 +258,31 @@ namespace i2p @@ -258,11 +258,31 @@ namespace i2p
{
LogPrint ("Router not found. Requested");
i2p::data::netdb.RequestDestination (ident);
DeleteI2NPMessage (msg); // TODO: implement a placeholder for router and send once it's available
auto resendTimer = new boost::asio::deadline_timer (m_Service);
resendTimer->expires_from_now (boost::posix_time::seconds(5)); // 5 seconds
resendTimer->async_wait (boost::bind (&Transports::HandleResendTimer,
this, boost::asio::placeholders::error, resendTimer, ident, msg));
}
}
}
void Transports::HandleResendTimer (const boost::system::error_code& ecode,
boost::asio::deadline_timer * timer, const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg)
{
RouterInfo * r = netdb.FindRouter (ident);
if (r)
{
LogPrint ("Router found. Sending message");
PostMessage (ident, msg);
}
else
{
LogPrint ("Router not found. Failed to send message");
DeleteI2NPMessage (msg);
}
delete timer;
}
void Transports::CloseSession (const i2p::data::RouterInfo * router)
{
if (!router) return;

2
Transports.h

@ -69,6 +69,8 @@ namespace i2p @@ -69,6 +69,8 @@ namespace i2p
void Run ();
void HandleAccept (i2p::ntcp::NTCPServerConnection * conn, const boost::system::error_code& error);
void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer,
const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void PostCloseSession (const i2p::data::RouterInfo * router);

Loading…
Cancel
Save