mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-08-27 10:40:23 +01:00
lookup LeaseSet before sending ping
This commit is contained in:
parent
5dadecba03
commit
a2073a8751
2 changed files with 65 additions and 33 deletions
|
@ -823,46 +823,76 @@ namespace client
|
||||||
SendReplyError ("No local destination");
|
SendReplyError ("No local destination");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto streamingDestination = localDestination->GetStreamingDestination ();
|
|
||||||
if (!streamingDestination)
|
|
||||||
{
|
|
||||||
SendReplyError ("No streaming destination");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto timer = std::make_shared<boost::asio::deadline_timer>(localDestination->GetService ());
|
|
||||||
timer->expires_from_now (boost::posix_time::milliseconds(BOB_PING_TIMEOUT));
|
|
||||||
timer->async_wait ([streamingDestination, s = shared_from_this ()](const boost::system::error_code& ecode)
|
|
||||||
{
|
|
||||||
if (ecode != boost::asio::error::operation_aborted)
|
|
||||||
{
|
|
||||||
LogPrint (eLogDebug, "BOB: Pong not received after ", BOB_PING_TIMEOUT, " millliseconds");
|
|
||||||
streamingDestination->ResetPongHandler ();
|
|
||||||
s->SendReplyError ("timeout");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
|
||||||
streamingDestination->SetPongHandler (
|
|
||||||
[streamingDestination, timer, ts, s = shared_from_this ()](const i2p::data::IdentHash * from)
|
|
||||||
{
|
|
||||||
int t = i2p::util::GetMillisecondsSinceEpoch () - ts;
|
|
||||||
if (t < 0) t = 0;
|
|
||||||
streamingDestination->ResetPongHandler ();
|
|
||||||
timer->cancel ();
|
|
||||||
if (from)
|
|
||||||
s->SendReplyOK ({"pong ", "from ", from->ToBase32(), ".b32.i2p: time=", std::to_string (t), " ms"});
|
|
||||||
else
|
|
||||||
s->SendReplyOK ({"pong: time=", std::to_string (t), " ms"});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (addr->IsIdentHash ())
|
if (addr->IsIdentHash ())
|
||||||
localDestination->SendPing (addr->identHash);
|
{
|
||||||
|
// we might have leaseset already
|
||||||
|
auto leaseSet = localDestination->FindLeaseSet (addr->identHash);
|
||||||
|
if (leaseSet)
|
||||||
|
{
|
||||||
|
boost::asio::post (localDestination->GetService (),
|
||||||
|
std::bind (&BOBCommandSession::SendPing, shared_from_this (), leaseSet));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// request LeaseSet
|
||||||
|
if (addr->IsIdentHash ())
|
||||||
|
localDestination->RequestDestination (addr->identHash,
|
||||||
|
std::bind (&BOBCommandSession::SendPing, shared_from_this (), std::placeholders::_1));
|
||||||
else
|
else
|
||||||
localDestination->SendPing (addr->blindedPublicKey);
|
localDestination->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey,
|
||||||
|
std::bind (&BOBCommandSession::SendPing, shared_from_this (), std::placeholders::_1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SendReplyError ("empty ping address");
|
SendReplyError ("empty ping address");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BOBCommandSession::SendPing (std::shared_ptr<const i2p::data::LeaseSet> ls)
|
||||||
|
{
|
||||||
|
if (!ls)
|
||||||
|
{
|
||||||
|
SendReplyError ("LeaseSet Not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto localDestination = (m_CurrentDestination && m_CurrentDestination->IsRunning ()) ?
|
||||||
|
m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination ();
|
||||||
|
if (!localDestination)
|
||||||
|
{
|
||||||
|
SendReplyError ("No local destination");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto streamingDestination = localDestination->GetStreamingDestination ();
|
||||||
|
if (!streamingDestination)
|
||||||
|
{
|
||||||
|
SendReplyError ("No streaming destination");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto timer = std::make_shared<boost::asio::deadline_timer>(localDestination->GetService ());
|
||||||
|
timer->expires_from_now (boost::posix_time::milliseconds(BOB_PING_TIMEOUT));
|
||||||
|
timer->async_wait ([streamingDestination, s = shared_from_this ()](const boost::system::error_code& ecode)
|
||||||
|
{
|
||||||
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "BOB: Pong not received after ", BOB_PING_TIMEOUT, " millliseconds");
|
||||||
|
streamingDestination->ResetPongHandler ();
|
||||||
|
s->SendReplyError ("timeout");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
|
streamingDestination->SetPongHandler (
|
||||||
|
[streamingDestination, timer, ts, s = shared_from_this ()](const i2p::data::IdentHash * from)
|
||||||
|
{
|
||||||
|
int t = i2p::util::GetMillisecondsSinceEpoch () - ts;
|
||||||
|
if (t < 0) t = 0;
|
||||||
|
streamingDestination->ResetPongHandler ();
|
||||||
|
timer->cancel ();
|
||||||
|
if (from)
|
||||||
|
s->SendReplyOK ({"pong ", "from ", from->ToBase32(), ".b32.i2p: time=", std::to_string (t), " ms"});
|
||||||
|
else
|
||||||
|
s->SendReplyOK ({"pong: time=", std::to_string (t), " ms"});
|
||||||
|
});
|
||||||
|
streamingDestination->SendPing (ls);
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: clear");
|
LogPrint (eLogDebug, "BOB: clear");
|
||||||
|
|
|
@ -261,6 +261,8 @@ namespace client
|
||||||
|
|
||||||
void BuildStatusLine(bool currentTunnel, std::shared_ptr<BOBDestination> destination, std::string &out);
|
void BuildStatusLine(bool currentTunnel, std::shared_ptr<BOBDestination> destination, std::string &out);
|
||||||
|
|
||||||
|
void SendPing (std::shared_ptr<const i2p::data::LeaseSet> ls);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
BOBCommandChannel& m_Owner;
|
BOBCommandChannel& m_Owner;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue