|
|
@ -219,7 +219,17 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
OutboundTunnel * Tunnels::GetNextOutboundTunnel () |
|
|
|
OutboundTunnel * Tunnels::GetNextOutboundTunnel () |
|
|
|
{ |
|
|
|
{ |
|
|
|
OutboundTunnel * tunnel = nullptr; |
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
|
|
|
|
uint32_t ind = rnd.GenerateWord32 (0, m_OutboundTunnels.size () - 1), i = 0; |
|
|
|
|
|
|
|
for (auto it: m_OutboundTunnels) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (i >= ind) return it; |
|
|
|
|
|
|
|
else i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: implement it base on profiling
|
|
|
|
|
|
|
|
/*OutboundTunnel * tunnel = nullptr;
|
|
|
|
size_t minSent = 0; |
|
|
|
size_t minSent = 0; |
|
|
|
for (auto it : m_OutboundTunnels) |
|
|
|
for (auto it : m_OutboundTunnels) |
|
|
|
if (!tunnel || it->GetNumSentBytes () < minSent) |
|
|
|
if (!tunnel || it->GetNumSentBytes () < minSent) |
|
|
@ -227,7 +237,7 @@ namespace tunnel |
|
|
|
tunnel = it; |
|
|
|
tunnel = it; |
|
|
|
minSent = it->GetNumSentBytes (); |
|
|
|
minSent = it->GetNumSentBytes (); |
|
|
|
} |
|
|
|
} |
|
|
|
return tunnel; |
|
|
|
return tunnel;*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) |
|
|
|
void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) |
|
|
@ -353,13 +363,13 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
//OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
|
|
|
|
LogPrint ("Creating two hops outbound tunnel..."); |
|
|
|
LogPrint ("Creating two hops outbound tunnel..."); |
|
|
|
CreateTunnel<OutboundTunnel> ( |
|
|
|
CreateTunnel<OutboundTunnel> ( |
|
|
|
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
i2p::data::netdb.GetRandomNTCPRouter (), |
|
|
|
inboundTunnel->GetTunnelConfig ()), |
|
|
|
inboundTunnel->GetTunnelConfig ())/*,
|
|
|
|
outboundTunnel); |
|
|
|
outboundTunnel*/); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -395,7 +405,7 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
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 (), |
|
|
|