renew connected receintly timestamp, add endpoint to the list if hole punch is being sent

This commit is contained in:
orignal 2024-09-18 14:35:59 -04:00
parent ae26758170
commit 2fa4237acd
3 changed files with 13 additions and 5 deletions

View file

@ -210,12 +210,17 @@ namespace transport
return ep.port ();
}
bool SSU2Server::IsConnectedRecently (const boost::asio::ip::udp::endpoint& ep) const
bool SSU2Server::IsConnectedRecently (const boost::asio::ip::udp::endpoint& ep)
{
if (!ep.port () || ep.address ().is_unspecified ()) return false;
auto it = m_ConnectedRecently.find (ep);
if (it != m_ConnectedRecently.end ())
return i2p::util::GetSecondsSinceEpoch () <= it->second + SSU2_HOLE_PUNCH_EXPIRATION;
{
if (i2p::util::GetSecondsSinceEpoch () <= it->second + SSU2_HOLE_PUNCH_EXPIRATION)
return true;
else
m_ConnectedRecently.erase (it);
}
return false;
}
@ -223,7 +228,9 @@ namespace transport
{
if (!ep.port () || ep.address ().is_unspecified () ||
i2p::util::GetSecondsSinceEpoch () > ts + SSU2_HOLE_PUNCH_EXPIRATION) return;
m_ConnectedRecently.try_emplace (ep, ts);
auto [it, added] = m_ConnectedRecently.try_emplace (ep, ts);
if (!added && ts > it->second)
it->second = ts; // renew timestamp of existing endpoint
}
void SSU2Server::AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from)