Browse Source

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

pull/2101/head
orignal 2 months ago
parent
commit
2fa4237acd
  1. 13
      libi2pd/SSU2.cpp
  2. 4
      libi2pd/SSU2.h
  3. 1
      libi2pd/SSU2Session.cpp

13
libi2pd/SSU2.cpp

@ -210,12 +210,17 @@ namespace transport
return ep.port (); 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; if (!ep.port () || ep.address ().is_unspecified ()) return false;
auto it = m_ConnectedRecently.find (ep); auto it = m_ConnectedRecently.find (ep);
if (it != m_ConnectedRecently.end ()) 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; return false;
} }
@ -223,7 +228,9 @@ namespace transport
{ {
if (!ep.port () || ep.address ().is_unspecified () || if (!ep.port () || ep.address ().is_unspecified () ||
i2p::util::GetSecondsSinceEpoch () > ts + SSU2_HOLE_PUNCH_EXPIRATION) return; 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) void SSU2Server::AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from)

4
libi2pd/SSU2.h

@ -39,7 +39,7 @@ namespace transport
const int SSU2_KEEP_ALIVE_INTERVAL = 15; // in seconds const int SSU2_KEEP_ALIVE_INTERVAL = 15; // in seconds
const int SSU2_KEEP_ALIVE_INTERVAL_VARIANCE = 4; // in seconds const int SSU2_KEEP_ALIVE_INTERVAL_VARIANCE = 4; // in seconds
const int SSU2_PROXY_CONNECT_RETRY_TIMEOUT = 30; // in seconds const int SSU2_PROXY_CONNECT_RETRY_TIMEOUT = 30; // in seconds
const int SSU2_HOLE_PUNCH_EXPIRATION = 20; // in seconds const int SSU2_HOLE_PUNCH_EXPIRATION = 150; // in seconds
class SSU2Server: private i2p::util::RunnableServiceWithWork class SSU2Server: private i2p::util::RunnableServiceWithWork
{ {
@ -73,7 +73,7 @@ namespace transport
bool UsesProxy () const { return m_IsThroughProxy; }; bool UsesProxy () const { return m_IsThroughProxy; };
bool IsSupported (const boost::asio::ip::address& addr) const; bool IsSupported (const boost::asio::ip::address& addr) const;
uint16_t GetPort (bool v4) const; uint16_t GetPort (bool v4) const;
bool IsConnectedRecently (const boost::asio::ip::udp::endpoint& ep) const; bool IsConnectedRecently (const boost::asio::ip::udp::endpoint& ep);
void AddConnectedRecently (const boost::asio::ip::udp::endpoint& ep, uint64_t ts); void AddConnectedRecently (const boost::asio::ip::udp::endpoint& ep, uint64_t ts);
std::mt19937& GetRng () { return m_Rng; } std::mt19937& GetRng () { return m_Rng; }
bool IsMaxNumIntroducers (bool v4) const { return (v4 ? m_Introducers.size () : m_IntroducersV6.size ()) >= SSU2_MAX_NUM_INTRODUCERS; } bool IsMaxNumIntroducers (bool v4) const { return (v4 ? m_Introducers.size () : m_IntroducersV6.size ()) >= SSU2_MAX_NUM_INTRODUCERS; }

1
libi2pd/SSU2Session.cpp

@ -2054,6 +2054,7 @@ namespace transport
token = m_Server.GetIncomingToken (ep); token = m_Server.GetIncomingToken (ep);
isV4 = ep.address ().is_v4 (); isV4 = ep.address ().is_v4 ();
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i, token); SendHolePunch (bufbe32toh (buf + 33), ep, addr->i, token);
m_Server.AddConnectedRecently (ep, i2p::util::GetSecondsSinceEpoch ());
} }
else else
{ {

Loading…
Cancel
Save