Browse Source

send HolePunch if unreachable

pull/97/head
orignal 10 years ago
parent
commit
5c2785cfca
  1. 8
      SSU.cpp
  2. 26
      Tunnel.cpp

8
SSU.cpp

@ -485,7 +485,7 @@ namespace ssu
buf += 4; // address buf += 4; // address
uint16_t port = be16toh (*(uint16_t *)buf); uint16_t port = be16toh (*(uint16_t *)buf);
// send hole punch of 1 byte // send hole punch of 1 byte
m_Server.Send (buf, 1, boost::asio::ip::udp::endpoint (address, port)); m_Server.Send (buf, 0, boost::asio::ip::udp::endpoint (address, port));
} }
else else
LogPrint ("Address size ", size, " is not supported"); LogPrint ("Address size ", size, " is not supported");
@ -1030,7 +1030,7 @@ namespace ssu
{ {
// connect through introducer // connect through introducer
int numIntroducers = address->introducers.size (); int numIntroducers = address->introducers.size ();
if (numIntroducers > 0 && !i2p::context.GetRouterInfo ().UsesIntroducer ()) if (numIntroducers > 0)
{ {
SSUSession * introducerSession = nullptr; SSUSession * introducerSession = nullptr;
const i2p::data::RouterInfo::Introducer * introducer = nullptr; const i2p::data::RouterInfo::Introducer * introducer = nullptr;
@ -1060,11 +1060,13 @@ namespace ssu
LogPrint ("Introduce new SSU session to [", router->GetIdentHashAbbreviation (), LogPrint ("Introduce new SSU session to [", router->GetIdentHashAbbreviation (),
"] through introducer ", introducer->iHost, ":", introducer->iPort); "] through introducer ", introducer->iHost, ":", introducer->iPort);
session->WaitForIntroduction (); session->WaitForIntroduction ();
if (i2p::context.GetRouterInfo ().UsesIntroducer ()) // if we are unreachable
Send (m_ReceiveBuffer, 0, remoteEndpoint); // send HolePunch
introducerSession->Introduce (introducer->iTag, introducer->iKey); introducerSession->Introduce (introducer->iTag, introducer->iKey);
} }
else else
{ {
LogPrint ("Can't connect to unreachable router. ", numIntroducers ? "We are unreachable" : "No introducers presented"); LogPrint ("Can't connect to unreachable router. No introducers presented");
m_Sessions.erase (remoteEndpoint); m_Sessions.erase (remoteEndpoint);
delete session; delete session;
session = nullptr; session = nullptr;

26
Tunnel.cpp

@ -400,19 +400,20 @@ namespace tunnel
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex); std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();) for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();)
{ {
if (ts > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) auto tunnel = *it;
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{ {
LogPrint ("Tunnel ", (*it)->GetTunnelID (), " expired"); LogPrint ("Tunnel ", tunnel->GetTunnelID (), " expired");
auto pool = (*it)->GetTunnelPool (); auto pool = (*it)->GetTunnelPool ();
if (pool) if (pool)
pool->TunnelExpired (*it); pool->TunnelExpired (tunnel);
delete *it; delete *it;
it = m_OutboundTunnels.erase (it); it = m_OutboundTunnels.erase (it);
} }
else else
{ {
if ((*it)->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) if (tunnel->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
(*it)->SetState (eTunnelStateExpiring); tunnel->SetState (eTunnelStateExpiring);
it++; it++;
} }
} }
@ -440,19 +441,20 @@ namespace tunnel
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex); std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();) for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();)
{ {
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) auto tunnel = it->second;
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{ {
LogPrint ("Tunnel ", it->second->GetTunnelID (), " expired"); LogPrint ("Tunnel ", tunnel->GetTunnelID (), " expired");
auto pool = it->second->GetTunnelPool (); auto pool = tunnel->GetTunnelPool ();
if (pool) if (pool)
pool->TunnelExpired (it->second); pool->TunnelExpired (tunnel);
delete it->second; delete tunnel;
it = m_InboundTunnels.erase (it); it = m_InboundTunnels.erase (it);
} }
else else
{ {
if (it->second->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) if (tunnel->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
it->second->SetState (eTunnelStateExpiring); tunnel->SetState (eTunnelStateExpiring);
it++; it++;
} }
} }

Loading…
Cancel
Save