mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:54:01 +01:00
pick compatible tunnels
This commit is contained in:
parent
8f0978cfd6
commit
f8c390cdd3
|
@ -562,7 +562,6 @@ namespace client
|
||||||
m_ExcludedFloodfills.clear ();
|
m_ExcludedFloodfills.clear ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_ExcludedFloodfills.insert (floodfill->GetIdentHash ());
|
|
||||||
auto outbound = m_Pool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false));
|
auto outbound = m_Pool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false));
|
||||||
if (!outbound)
|
if (!outbound)
|
||||||
{
|
{
|
||||||
|
@ -575,6 +574,7 @@ namespace client
|
||||||
LogPrint (eLogError, "Destination: Can't publish LeaseSet. No inbound tunnels");
|
LogPrint (eLogError, "Destination: Can't publish LeaseSet. No inbound tunnels");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_ExcludedFloodfills.insert (floodfill->GetIdentHash ());
|
||||||
LogPrint (eLogDebug, "Destination: Publish LeaseSet of ", GetIdentHash ().ToBase32 ());
|
LogPrint (eLogDebug, "Destination: Publish LeaseSet of ", GetIdentHash ().ToBase32 ());
|
||||||
RAND_bytes ((uint8_t *)&m_PublishReplyToken, 4);
|
RAND_bytes ((uint8_t *)&m_PublishReplyToken, 4);
|
||||||
auto msg = WrapMessageForRouter (floodfill, i2p::CreateDatabaseStoreMsg (leaseSet, m_PublishReplyToken, inbound));
|
auto msg = WrapMessageForRouter (floodfill, i2p::CreateDatabaseStoreMsg (leaseSet, m_PublishReplyToken, inbound));
|
||||||
|
|
|
@ -681,8 +681,8 @@ namespace data
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
||||||
auto outbound = pool ? pool->GetNextOutboundTunnel () : nullptr;
|
auto outbound = pool ? pool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false)) : nullptr;
|
||||||
auto inbound = pool ? pool->GetNextInboundTunnel () : nullptr;
|
auto inbound = pool ? pool->GetNextInboundTunnel (nullptr, floodfill->GetCompatibleTransports (true)) : nullptr;
|
||||||
if (outbound && inbound)
|
if (outbound && inbound)
|
||||||
outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0, dest->CreateRequestMessage (floodfill, inbound));
|
outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0, dest->CreateRequestMessage (floodfill, inbound));
|
||||||
else
|
else
|
||||||
|
@ -1129,8 +1129,8 @@ namespace data
|
||||||
{
|
{
|
||||||
// otherwise through exploratory
|
// otherwise through exploratory
|
||||||
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
||||||
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr;
|
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false)) : nullptr;
|
||||||
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr;
|
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel (nullptr, floodfill->GetCompatibleTransports (true)) : nullptr;
|
||||||
if (inbound && outbound)
|
if (inbound && outbound)
|
||||||
outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0,
|
outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0,
|
||||||
CreateDatabaseStoreMsg (i2p::context.GetSharedRouterInfo (), replyToken, inbound));
|
CreateDatabaseStoreMsg (i2p::context.GetSharedRouterInfo (), replyToken, inbound));
|
||||||
|
|
|
@ -498,9 +498,8 @@ namespace tunnel
|
||||||
}
|
}
|
||||||
prevHop = hop;
|
prevHop = hop;
|
||||||
path.Add (hop);
|
path.Add (hop);
|
||||||
if (i == numHops - 1)
|
|
||||||
path.farEndTransports = hop->GetCompatibleTransports (inbound);
|
|
||||||
}
|
}
|
||||||
|
path.farEndTransports = prevHop->GetCompatibleTransports (inbound); // last hop
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,13 +554,13 @@ namespace tunnel
|
||||||
|
|
||||||
void TunnelPool::CreateInboundTunnel ()
|
void TunnelPool::CreateInboundTunnel ()
|
||||||
{
|
{
|
||||||
auto outboundTunnel = GetNextOutboundTunnel ();
|
|
||||||
if (!outboundTunnel)
|
|
||||||
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
|
||||||
LogPrint (eLogDebug, "Tunnels: Creating destination inbound tunnel...");
|
LogPrint (eLogDebug, "Tunnels: Creating destination inbound tunnel...");
|
||||||
Path path;
|
Path path;
|
||||||
if (SelectPeers (path, true))
|
if (SelectPeers (path, true))
|
||||||
{
|
{
|
||||||
|
auto outboundTunnel = GetNextOutboundTunnel (nullptr, path.farEndTransports);
|
||||||
|
if (!outboundTunnel)
|
||||||
|
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
||||||
std::shared_ptr<TunnelConfig> config;
|
std::shared_ptr<TunnelConfig> config;
|
||||||
if (m_NumInboundHops > 0)
|
if (m_NumInboundHops > 0)
|
||||||
{
|
{
|
||||||
|
@ -583,7 +582,7 @@ namespace tunnel
|
||||||
CreateInboundTunnel ();
|
CreateInboundTunnel ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto outboundTunnel = GetNextOutboundTunnel ();
|
auto outboundTunnel = GetNextOutboundTunnel (nullptr, tunnel->GetFarEndTransports ());
|
||||||
if (!outboundTunnel)
|
if (!outboundTunnel)
|
||||||
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
||||||
LogPrint (eLogDebug, "Tunnels: Re-creating destination inbound tunnel...");
|
LogPrint (eLogDebug, "Tunnels: Re-creating destination inbound tunnel...");
|
||||||
|
@ -604,40 +603,41 @@ namespace tunnel
|
||||||
|
|
||||||
void TunnelPool::CreateOutboundTunnel ()
|
void TunnelPool::CreateOutboundTunnel ()
|
||||||
{
|
{
|
||||||
auto inboundTunnel = GetNextInboundTunnel ();
|
LogPrint (eLogDebug, "Tunnels: Creating destination outbound tunnel...");
|
||||||
if (!inboundTunnel)
|
Path path;
|
||||||
inboundTunnel = tunnels.GetNextInboundTunnel ();
|
if (SelectPeers (path, false))
|
||||||
if (inboundTunnel)
|
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "Tunnels: Creating destination outbound tunnel...");
|
auto inboundTunnel = GetNextInboundTunnel (nullptr, path.farEndTransports);
|
||||||
Path path;
|
if (!inboundTunnel)
|
||||||
if (SelectPeers (path, false))
|
inboundTunnel = tunnels.GetNextInboundTunnel ();
|
||||||
|
if (!inboundTunnel)
|
||||||
{
|
{
|
||||||
if (m_LocalDestination && !m_LocalDestination->SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD))
|
LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no inbound tunnels found");
|
||||||
path.isShort = false; // because can't handle ECIES encrypted reply
|
return;
|
||||||
|
}
|
||||||
std::shared_ptr<TunnelConfig> config;
|
|
||||||
if (m_NumOutboundHops > 0)
|
if (m_LocalDestination && !m_LocalDestination->SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD))
|
||||||
config = std::make_shared<TunnelConfig>(path.peers, inboundTunnel->GetNextTunnelID (),
|
path.isShort = false; // because can't handle ECIES encrypted reply
|
||||||
inboundTunnel->GetNextIdentHash (), path.isShort, path.farEndTransports);
|
|
||||||
|
std::shared_ptr<TunnelConfig> config;
|
||||||
|
if (m_NumOutboundHops > 0)
|
||||||
|
config = std::make_shared<TunnelConfig>(path.peers, inboundTunnel->GetNextTunnelID (),
|
||||||
|
inboundTunnel->GetNextIdentHash (), path.isShort, path.farEndTransports);
|
||||||
|
|
||||||
std::shared_ptr<OutboundTunnel> tunnel;
|
std::shared_ptr<OutboundTunnel> tunnel;
|
||||||
if (path.isShort)
|
if (path.isShort)
|
||||||
{
|
{
|
||||||
// TODO: implement it better
|
// TODO: implement it better
|
||||||
tunnel = tunnels.CreateOutboundTunnel (config, inboundTunnel->GetTunnelPool ());
|
tunnel = tunnels.CreateOutboundTunnel (config, inboundTunnel->GetTunnelPool ());
|
||||||
tunnel->SetTunnelPool (shared_from_this ());
|
tunnel->SetTunnelPool (shared_from_this ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tunnel = tunnels.CreateOutboundTunnel (config, shared_from_this ());
|
tunnel = tunnels.CreateOutboundTunnel (config, shared_from_this ());
|
||||||
if (tunnel && tunnel->IsEstablished ()) // zero hops
|
if (tunnel && tunnel->IsEstablished ()) // zero hops
|
||||||
TunnelCreated (tunnel);
|
TunnelCreated (tunnel);
|
||||||
}
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no peers available");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no inbound tunnels found");
|
LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no peers available");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TunnelPool::RecreateOutboundTunnel (std::shared_ptr<OutboundTunnel> tunnel)
|
void TunnelPool::RecreateOutboundTunnel (std::shared_ptr<OutboundTunnel> tunnel)
|
||||||
|
@ -647,7 +647,7 @@ namespace tunnel
|
||||||
CreateOutboundTunnel ();
|
CreateOutboundTunnel ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto inboundTunnel = GetNextInboundTunnel ();
|
auto inboundTunnel = GetNextInboundTunnel (nullptr, tunnel->GetFarEndTransports ());
|
||||||
if (!inboundTunnel)
|
if (!inboundTunnel)
|
||||||
inboundTunnel = tunnels.GetNextInboundTunnel ();
|
inboundTunnel = tunnels.GetNextInboundTunnel ();
|
||||||
if (inboundTunnel)
|
if (inboundTunnel)
|
||||||
|
|
Loading…
Reference in a new issue