clean line trailing spaces and tabs

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2021-11-27 23:30:35 +03:00
parent 94661f697b
commit edc0162163
No known key found for this signature in database
GPG key ID: 66F6C87B98EBCFE2
66 changed files with 998 additions and 999 deletions

View file

@ -27,28 +27,28 @@ namespace tunnel
void Path::Add (std::shared_ptr<const i2p::data::RouterInfo> r)
{
if (r)
{
{
peers.push_back (r->GetRouterIdentity ());
if (r->GetVersion () < i2p::data::NETDB_MIN_SHORT_TUNNEL_BUILD_VERSION ||
if (r->GetVersion () < i2p::data::NETDB_MIN_SHORT_TUNNEL_BUILD_VERSION ||
r->GetRouterIdentity ()->GetCryptoKeyType () != i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)
isShort = false;
}
}
}
}
void Path::Reverse ()
{
std::reverse (peers.begin (), peers.end ());
}
}
TunnelPool::TunnelPool (int numInboundHops, int numOutboundHops, int numInboundTunnels, int numOutboundTunnels):
m_NumInboundHops (numInboundHops), m_NumOutboundHops (numOutboundHops),
m_NumInboundTunnels (numInboundTunnels), m_NumOutboundTunnels (numOutboundTunnels),
m_IsActive (true), m_CustomPeerSelector(nullptr)
{
if (m_NumInboundTunnels > TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY)
if (m_NumInboundTunnels > TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY)
m_NumInboundTunnels = TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY;
if (m_NumOutboundTunnels > TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY)
m_NumOutboundTunnels = TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY;
if (m_NumOutboundTunnels > TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY)
m_NumOutboundTunnels = TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY;
m_NextManageTime = i2p::util::GetSecondsSinceEpoch () + rand () % TUNNEL_POOL_MANAGE_INTERVAL;
}
@ -114,7 +114,7 @@ namespace tunnel
{
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
if (createdTunnel->IsRecreated ())
{
{
// find and mark old tunnel as expired
createdTunnel->SetRecreated (false);
for (auto& it: m_InboundTunnels)
@ -122,8 +122,8 @@ namespace tunnel
{
it->SetState (eTunnelStateExpiring);
break;
}
}
}
}
m_InboundTunnels.insert (createdTunnel);
}
if (m_LocalDestination)
@ -179,10 +179,10 @@ namespace tunnel
if (it->IsSlow () && !slowTunnel)
slowTunnel = it;
else
{
{
v.push_back (it);
i++;
}
}
}
}
if (slowTunnel && (int)v.size () < (num/2+1))
@ -205,7 +205,7 @@ namespace tunnel
}
template<class TTunnels>
typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels,
typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels,
typename TTunnels::value_type excluded, i2p::data::RouterInfo::CompatibleTransports compatible) const
{
if (tunnels.empty ()) return nullptr;
@ -216,8 +216,8 @@ namespace tunnel
{
if (it->IsEstablished () && it != excluded && (compatible & it->GetFarEndTransports ()))
{
if (it->IsSlow () || (HasLatencyRequirement() && it->LatencyIsKnown() &&
!it->LatencyFitsRange(m_MinLatency, m_MaxLatency)))
if (it->IsSlow () || (HasLatencyRequirement() && it->LatencyIsKnown() &&
!it->LatencyFitsRange(m_MinLatency, m_MaxLatency)))
{
i++; skipped = true;
continue;
@ -227,7 +227,7 @@ namespace tunnel
}
if (i > ind && tunnel) break;
}
if (!tunnel && skipped)
if (!tunnel && skipped)
{
ind = rand () % (tunnels.size ()/2 + 1), i = 0;
for (const auto& it: tunnels)
@ -284,12 +284,12 @@ namespace tunnel
if (!num && !m_OutboundTunnels.empty () && m_NumOutboundHops > 0)
{
for (auto it: m_OutboundTunnels)
{
{
CreatePairedInboundTunnel (it);
num++;
if (num >= m_NumInboundTunnels) break;
}
}
}
}
for (int i = num; i < m_NumInboundTunnels; i++)
CreateInboundTunnel ();
@ -371,13 +371,13 @@ namespace tunnel
void TunnelPool::ManageTunnels (uint64_t ts)
{
if (ts > m_NextManageTime)
{
{
CreateTunnels ();
TestTunnels ();
m_NextManageTime = ts + TUNNEL_POOL_MANAGE_INTERVAL + (rand () % TUNNEL_POOL_MANAGE_INTERVAL)/2;
}
}
m_NextManageTime = ts + TUNNEL_POOL_MANAGE_INTERVAL + (rand () % TUNNEL_POOL_MANAGE_INTERVAL)/2;
}
}
void TunnelPool::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
{
if (m_LocalDestination)
@ -412,19 +412,19 @@ namespace tunnel
uint64_t latency = dlt / 2;
// restore from test failed state if any
if (test.first)
{
{
if (test.first->GetState () == eTunnelStateTestFailed)
test.first->SetState (eTunnelStateEstablished);
// update latency
test.first->AddLatencySample(latency);
}
}
if (test.second)
{
{
if (test.second->GetState () == eTunnelStateTestFailed)
test.second->SetState (eTunnelStateEstablished);
// update latency
test.second->AddLatencySample(latency);
}
}
}
else
{
@ -438,8 +438,8 @@ namespace tunnel
bool TunnelPool::IsExploratory () const
{
return i2p::tunnel::tunnels.GetExploratoryPool () == shared_from_this ();
}
}
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop, bool reverse) const
{
auto hop = IsExploratory () ? i2p::data::netdb.GetRandomRouter (prevHop, reverse):
@ -467,7 +467,7 @@ namespace tunnel
(inbound && i2p::transport::transports.GetNumPeers () > 25))
{
auto r = i2p::transport::transports.GetRandomPeer ();
if (r && r->IsECIES () && !r->GetProfile ()->IsBad () &&
if (r && r->IsECIES () && !r->GetProfile ()->IsBad () &&
(numHops > 1 || (r->IsV4 () && (!inbound || r->IsReachable ())))) // first inbound must be reachable
{
prevHop = r;
@ -480,11 +480,11 @@ namespace tunnel
{
auto hop = nextHop (prevHop, inbound);
if (!hop && !i) // if no suitable peer found for first hop, try already connected
{
{
LogPrint (eLogInfo, "Tunnels: Can't select first hop for a tunnel. Trying already connected");
hop = i2p::transport::transports.GetRandomPeer ();
if (hop && !hop->IsECIES ()) hop = nullptr;
}
}
if (!hop)
{
LogPrint (eLogError, "Tunnels: Can't select next hop for ", prevHop->GetIdentHashBase64 ());
@ -495,7 +495,7 @@ namespace tunnel
{
auto hop1 = nextHop (prevHop, true);
if (hop1) hop = hop1;
}
}
prevHop = hop;
path.Add (hop);
}
@ -523,25 +523,25 @@ namespace tunnel
{
int numHops = isInbound ? m_NumInboundHops : m_NumOutboundHops;
if (numHops > (int)m_ExplicitPeers->size ()) numHops = m_ExplicitPeers->size ();
if (!numHops) return false;
if (!numHops) return false;
for (int i = 0; i < numHops; i++)
{
auto& ident = (*m_ExplicitPeers)[i];
auto r = i2p::data::netdb.FindRouter (ident);
if (r)
{
if (r->IsECIES ())
{
{
if (r->IsECIES ())
{
path.Add (r);
if (i == numHops - 1)
path.farEndTransports = r->GetCompatibleTransports (isInbound);
}
}
else
{
{
LogPrint (eLogError, "Tunnels: ElGamal router ", ident.ToBase64 (), " is not supported");
return false;
}
}
return false;
}
}
else
{
LogPrint (eLogInfo, "Tunnels: Can't find router for ", ident.ToBase64 ());
@ -612,14 +612,14 @@ namespace tunnel
{
LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no inbound tunnels found");
return;
}
}
if (m_LocalDestination && !m_LocalDestination->SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD))
path.isShort = false; // because can't handle ECIES encrypted reply
std::shared_ptr<TunnelConfig> config;
if (m_NumOutboundHops > 0)
config = std::make_shared<TunnelConfig>(path.peers, inboundTunnel->GetNextTunnelID (),
config = std::make_shared<TunnelConfig>(path.peers, inboundTunnel->GetNextTunnelID (),
inboundTunnel->GetNextIdentHash (), path.isShort, path.farEndTransports);
std::shared_ptr<OutboundTunnel> tunnel;
@ -628,8 +628,8 @@ namespace tunnel
// TODO: implement it better
tunnel = tunnels.CreateOutboundTunnel (config, inboundTunnel->GetTunnelPool ());
tunnel->SetTunnelPool (shared_from_this ());
}
else
}
else
tunnel = tunnels.CreateOutboundTunnel (config, shared_from_this ());
if (tunnel && tunnel->IsEstablished ()) // zero hops
TunnelCreated (tunnel);
@ -654,7 +654,7 @@ namespace tunnel
std::shared_ptr<TunnelConfig> config;
if (m_NumOutboundHops > 0 && tunnel->GetPeers().size())
{
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), inboundTunnel->GetNextTunnelID (),
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), inboundTunnel->GetNextTunnelID (),
inboundTunnel->GetNextIdentHash (), inboundTunnel->IsShortBuildMessage (), tunnel->GetFarEndTransports ());
}
if (!m_NumOutboundHops || config)
@ -673,7 +673,7 @@ namespace tunnel
LogPrint (eLogDebug, "Tunnels: Creating paired inbound tunnel...");
auto tunnel = tunnels.CreateInboundTunnel (
m_NumOutboundHops > 0 ? std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers (),
outboundTunnel->IsShortBuildMessage ()) : nullptr,
outboundTunnel->IsShortBuildMessage ()) : nullptr,
shared_from_this (), outboundTunnel);
if (tunnel->IsEstablished ()) // zero hops
TunnelCreated (tunnel);