|
|
@ -151,8 +151,8 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
Tunnels tunnels; |
|
|
|
Tunnels tunnels; |
|
|
|
|
|
|
|
|
|
|
|
Tunnels::Tunnels (): m_IsRunning (false), m_IsTunnelCreated (false), m_NextReplyMsgID (555), |
|
|
|
Tunnels::Tunnels (): m_IsRunning (false), m_IsTunnelCreated (false), |
|
|
|
m_ZeroHopsInboundTunnel (nullptr), m_ZeroHopsOutboundTunnel (nullptr), m_Thread (0) |
|
|
|
m_NextReplyMsgID (555),m_Thread (0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -173,9 +173,6 @@ namespace tunnel |
|
|
|
for (auto& it : m_PendingTunnels) |
|
|
|
for (auto& it : m_PendingTunnels) |
|
|
|
delete it.second; |
|
|
|
delete it.second; |
|
|
|
m_PendingTunnels.clear (); |
|
|
|
m_PendingTunnels.clear (); |
|
|
|
|
|
|
|
|
|
|
|
delete m_ZeroHopsInboundTunnel; |
|
|
|
|
|
|
|
delete m_ZeroHopsOutboundTunnel; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
InboundTunnel * Tunnels::GetInboundTunnel (uint32_t tunnelID) |
|
|
|
InboundTunnel * Tunnels::GetInboundTunnel (uint32_t tunnelID) |
|
|
@ -259,10 +256,6 @@ namespace tunnel |
|
|
|
{ |
|
|
|
{ |
|
|
|
sleep (1); // wait for other parts are ready
|
|
|
|
sleep (1); // wait for other parts are ready
|
|
|
|
|
|
|
|
|
|
|
|
// we must start with zero hops tunnels
|
|
|
|
|
|
|
|
CreateZeroHopsInboundTunnel (); |
|
|
|
|
|
|
|
CreateZeroHopsOutboundTunnel (); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t lastTs = 0; |
|
|
|
uint32_t lastTs = 0; |
|
|
|
while (m_IsRunning) |
|
|
|
while (m_IsRunning) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -314,8 +307,8 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
m_PendingTunnels.clear (); |
|
|
|
m_PendingTunnels.clear (); |
|
|
|
|
|
|
|
|
|
|
|
ManageOutboundTunnels (); |
|
|
|
|
|
|
|
ManageInboundTunnels (); |
|
|
|
ManageInboundTunnels (); |
|
|
|
|
|
|
|
ManageOutboundTunnels (); |
|
|
|
|
|
|
|
|
|
|
|
/* if (!m_IsTunnelCreated)
|
|
|
|
/* if (!m_IsTunnelCreated)
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -347,10 +340,9 @@ namespace tunnel |
|
|
|
if (m_OutboundTunnels.size () < 10) |
|
|
|
if (m_OutboundTunnels.size () < 10) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// trying to create one more oubound tunnel
|
|
|
|
// trying to create one more oubound tunnel
|
|
|
|
InboundTunnel * inboundTunnel = m_ZeroHopsInboundTunnel; |
|
|
|
if (m_InboundTunnels.empty ()) return; |
|
|
|
if (!m_InboundTunnels.empty ()) |
|
|
|
|
|
|
|
inboundTunnel = m_InboundTunnels.rbegin ()->second; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InboundTunnel * inboundTunnel = GetNextInboundTunnel (); |
|
|
|
if (m_OutboundTunnels.empty () || m_OutboundTunnels.size () < 3) |
|
|
|
if (m_OutboundTunnels.empty () || m_OutboundTunnels.size () < 3) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Creating one hop outbound tunnel..."); |
|
|
|
LogPrint ("Creating one hop outbound tunnel..."); |
|
|
@ -360,10 +352,10 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
OutboundTunnel * outboundTunnel = *m_OutboundTunnels.begin (); |
|
|
|
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
LogPrint ("Creating two hops outbound tunnel..."); |
|
|
|
LogPrint ("Creating two hops outbound tunnel..."); |
|
|
|
CreateTunnel<OutboundTunnel> ( |
|
|
|
CreateTunnel<OutboundTunnel> ( |
|
|
|
new TunnelConfig (inboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router, |
|
|
|
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
inboundTunnel->GetTunnelConfig ()), |
|
|
|
inboundTunnel->GetTunnelConfig ()), |
|
|
|
outboundTunnel); |
|
|
|
outboundTunnel); |
|
|
@ -385,6 +377,13 @@ namespace tunnel |
|
|
|
it++; |
|
|
|
it++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_InboundTunnels.empty ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("Creating zero hops inbound tunnel..."); |
|
|
|
|
|
|
|
CreateZeroHopsInboundTunnel (); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_InboundTunnels.size () < 10) |
|
|
|
if (m_InboundTunnels.size () < 10) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// trying to create one more inbound tunnel
|
|
|
|
// trying to create one more inbound tunnel
|
|
|
@ -395,12 +394,11 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
OutboundTunnel * outboundTunnel = *m_OutboundTunnels.rbegin (); |
|
|
|
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
InboundTunnel * inboundTunnel = m_InboundTunnels.rbegin ()->second; |
|
|
|
|
|
|
|
LogPrint ("Creating two hops inbound tunnel..."); |
|
|
|
LogPrint ("Creating two hops inbound tunnel..."); |
|
|
|
CreateTunnel<InboundTunnel> ( |
|
|
|
CreateTunnel<InboundTunnel> ( |
|
|
|
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
inboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router), |
|
|
|
outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router), |
|
|
|
outboundTunnel); |
|
|
|
outboundTunnel); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -423,26 +421,20 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::AddOutboundTunnel (OutboundTunnel * newTunnel) |
|
|
|
void Tunnels::AddOutboundTunnel (OutboundTunnel * newTunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (newTunnel != m_ZeroHopsOutboundTunnel) |
|
|
|
m_OutboundTunnels.push_back (newTunnel); |
|
|
|
m_OutboundTunnels.push_back (newTunnel); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel) |
|
|
|
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (newTunnel != m_ZeroHopsInboundTunnel) |
|
|
|
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel; |
|
|
|
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel; |
|
|
|
// build symmetric outbound tunnel
|
|
|
|
|
|
|
|
CreateTunnel<OutboundTunnel> (newTunnel->GetTunnelConfig ()->Invert (), GetNextOutboundTunnel ()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::CreateZeroHopsOutboundTunnel () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_ZeroHopsOutboundTunnel = CreateTunnel<OutboundTunnel> ( |
|
|
|
|
|
|
|
new TunnelConfig (&i2p::context.GetRouterInfo (), |
|
|
|
|
|
|
|
m_ZeroHopsInboundTunnel->GetTunnelConfig ())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::CreateZeroHopsInboundTunnel () |
|
|
|
void Tunnels::CreateZeroHopsInboundTunnel () |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_ZeroHopsInboundTunnel = CreateTunnel<InboundTunnel> ( |
|
|
|
CreateTunnel<InboundTunnel> ( |
|
|
|
new TunnelConfig (&i2p::context.GetRouterInfo ())); |
|
|
|
new TunnelConfig (&i2p::context.GetRouterInfo ())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|