mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
select router with ipv4 for endpoint
This commit is contained in:
parent
5022a9c610
commit
17c4038c60
|
@ -59,7 +59,7 @@ namespace data
|
||||||
{
|
{
|
||||||
Reseed ();
|
Reseed ();
|
||||||
}
|
}
|
||||||
else if (!GetRandomRouter (i2p::context.GetSharedRouterInfo (), false))
|
else if (!GetRandomRouter (i2p::context.GetSharedRouterInfo (), false, false))
|
||||||
Reseed (); // we don't have a router we can connect to. Trying to reseed
|
Reseed (); // we don't have a router we can connect to. Trying to reseed
|
||||||
|
|
||||||
auto it = m_RouterInfos.find (i2p::context.GetIdentHash ());
|
auto it = m_RouterInfos.find (i2p::context.GetIdentHash ());
|
||||||
|
@ -1199,15 +1199,17 @@ namespace data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse) const
|
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith,
|
||||||
|
bool reverse, bool endpoint) const
|
||||||
{
|
{
|
||||||
return GetRandomRouter (
|
return GetRandomRouter (
|
||||||
[compatibleWith, reverse](std::shared_ptr<const RouterInfo> router)->bool
|
[compatibleWith, reverse, endpoint](std::shared_ptr<const RouterInfo> router)->bool
|
||||||
{
|
{
|
||||||
return !router->IsHidden () && router != compatibleWith &&
|
return !router->IsHidden () && router != compatibleWith &&
|
||||||
(reverse ? compatibleWith->IsReachableFrom (*router) :
|
(reverse ? compatibleWith->IsReachableFrom (*router) :
|
||||||
router->IsReachableFrom (*compatibleWith)) &&
|
router->IsReachableFrom (*compatibleWith)) &&
|
||||||
router->IsECIES () && !router->IsHighCongestion (false);
|
router->IsECIES () && !router->IsHighCongestion (false) &&
|
||||||
|
(!endpoint || (router->IsV4 () && (!reverse || router->IsPublished (true)))); // endpoint must be ipv4 and published if inbound(reverse)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1231,17 +1233,20 @@ namespace data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> NetDb::GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse) const
|
std::shared_ptr<const RouterInfo> NetDb::GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith,
|
||||||
|
bool reverse, bool endpoint) const
|
||||||
{
|
{
|
||||||
return GetRandomRouter (
|
return GetRandomRouter (
|
||||||
[compatibleWith, reverse](std::shared_ptr<const RouterInfo> router)->bool
|
[compatibleWith, reverse, endpoint](std::shared_ptr<const RouterInfo> router)->bool
|
||||||
{
|
{
|
||||||
return !router->IsHidden () && router != compatibleWith &&
|
return !router->IsHidden () && router != compatibleWith &&
|
||||||
(reverse ? compatibleWith->IsReachableFrom (*router) :
|
(reverse ? compatibleWith->IsReachableFrom (*router) :
|
||||||
router->IsReachableFrom (*compatibleWith)) &&
|
router->IsReachableFrom (*compatibleWith)) &&
|
||||||
(router->GetCaps () & RouterInfo::eHighBandwidth) &&
|
(router->GetCaps () & RouterInfo::eHighBandwidth) &&
|
||||||
router->GetVersion () >= NETDB_MIN_HIGHBANDWIDTH_VERSION &&
|
router->GetVersion () >= NETDB_MIN_HIGHBANDWIDTH_VERSION &&
|
||||||
router->IsECIES () && !router->IsHighCongestion (true);
|
router->IsECIES () && !router->IsHighCongestion (true) &&
|
||||||
|
(!endpoint || (router->IsV4 () && (!reverse || router->IsPublished (true)))); // endpoint must be ipv4 and published if inbound(reverse)
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,8 @@ namespace data
|
||||||
void HandleNTCP2RouterInfoMsg (std::shared_ptr<const I2NPMessage> m);
|
void HandleNTCP2RouterInfoMsg (std::shared_ptr<const I2NPMessage> m);
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> GetRandomRouter () const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter () const;
|
||||||
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse) const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse, bool endpoint) const;
|
||||||
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse) const;
|
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse, bool endpoint) const;
|
||||||
std::shared_ptr<const RouterInfo> GetRandomSSU2PeerTestRouter (bool v4, const std::set<IdentHash>& excluded) const;
|
std::shared_ptr<const RouterInfo> GetRandomSSU2PeerTestRouter (bool v4, const std::set<IdentHash>& excluded) const;
|
||||||
std::shared_ptr<const RouterInfo> GetRandomSSU2Introducer (bool v4, const std::set<IdentHash>& excluded) const;
|
std::shared_ptr<const RouterInfo> GetRandomSSU2Introducer (bool v4, const std::set<IdentHash>& excluded) const;
|
||||||
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||||||
|
|
|
@ -709,7 +709,7 @@ namespace tunnel
|
||||||
auto inboundTunnel = GetNextInboundTunnel ();
|
auto inboundTunnel = GetNextInboundTunnel ();
|
||||||
auto router = i2p::transport::transports.RoutesRestricted() ?
|
auto router = i2p::transport::transports.RoutesRestricted() ?
|
||||||
i2p::transport::transports.GetRestrictedPeer() :
|
i2p::transport::transports.GetRestrictedPeer() :
|
||||||
i2p::data::netdb.GetRandomRouter (i2p::context.GetSharedRouterInfo (), false); // reachable by us
|
i2p::data::netdb.GetRandomRouter (i2p::context.GetSharedRouterInfo (), false, true); // reachable by us
|
||||||
if (!inboundTunnel || !router) return;
|
if (!inboundTunnel || !router) return;
|
||||||
LogPrint (eLogDebug, "Tunnel: Creating one hop outbound tunnel");
|
LogPrint (eLogDebug, "Tunnel: Creating one hop outbound tunnel");
|
||||||
CreateTunnel<OutboundTunnel> (
|
CreateTunnel<OutboundTunnel> (
|
||||||
|
@ -781,7 +781,7 @@ namespace tunnel
|
||||||
auto router = i2p::transport::transports.RoutesRestricted() ?
|
auto router = i2p::transport::transports.RoutesRestricted() ?
|
||||||
i2p::transport::transports.GetRestrictedPeer() :
|
i2p::transport::transports.GetRestrictedPeer() :
|
||||||
// should be reachable by us because we send build request directly
|
// should be reachable by us because we send build request directly
|
||||||
i2p::data::netdb.GetRandomRouter (i2p::context.GetSharedRouterInfo (), false);
|
i2p::data::netdb.GetRandomRouter (i2p::context.GetSharedRouterInfo (), false, true);
|
||||||
if (!router) {
|
if (!router) {
|
||||||
LogPrint (eLogWarning, "Tunnel: Can't find any router, skip creating tunnel");
|
LogPrint (eLogWarning, "Tunnel: Can't find any router, skip creating tunnel");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -470,13 +470,14 @@ namespace tunnel
|
||||||
return i2p::tunnel::tunnels.GetExploratoryPool () == shared_from_this ();
|
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
|
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop,
|
||||||
|
bool reverse, bool endpoint) const
|
||||||
{
|
{
|
||||||
auto hop = IsExploratory () ? i2p::data::netdb.GetRandomRouter (prevHop, reverse):
|
auto hop = IsExploratory () ? i2p::data::netdb.GetRandomRouter (prevHop, reverse, endpoint):
|
||||||
i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop, reverse);
|
i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop, reverse, endpoint);
|
||||||
|
|
||||||
if (!hop || hop->GetProfile ()->IsBad ())
|
if (!hop || hop->GetProfile ()->IsBad ())
|
||||||
hop = i2p::data::netdb.GetRandomRouter (prevHop, reverse);
|
hop = i2p::data::netdb.GetRandomRouter (prevHop, reverse, endpoint);
|
||||||
return hop;
|
return hop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +509,7 @@ namespace tunnel
|
||||||
|
|
||||||
for(int i = start; i < numHops; i++ )
|
for(int i = start; i < numHops; i++ )
|
||||||
{
|
{
|
||||||
auto hop = nextHop (prevHop, inbound);
|
auto hop = nextHop (prevHop, inbound, i == numHops - 1);
|
||||||
if (!hop && !i) // if no suitable peer found for first hop, try already connected
|
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");
|
LogPrint (eLogInfo, "Tunnels: Can't select first hop for a tunnel. Trying already connected");
|
||||||
|
@ -520,11 +521,6 @@ namespace tunnel
|
||||||
LogPrint (eLogError, "Tunnels: Can't select next hop for ", prevHop->GetIdentHashBase64 ());
|
LogPrint (eLogError, "Tunnels: Can't select next hop for ", prevHop->GetIdentHashBase64 ());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((i == numHops - 1) && (!hop->IsV4 () || (inbound && !hop->IsPublished (true)))) // IBGW is not published ipv4
|
|
||||||
{
|
|
||||||
auto hop1 = nextHop (prevHop, inbound);
|
|
||||||
if (hop1) hop = hop1;
|
|
||||||
}
|
|
||||||
prevHop = hop;
|
prevHop = hop;
|
||||||
path.Add (hop);
|
path.Add (hop);
|
||||||
}
|
}
|
||||||
|
@ -566,7 +562,8 @@ namespace tunnel
|
||||||
if (m_CustomPeerSelector)
|
if (m_CustomPeerSelector)
|
||||||
return m_CustomPeerSelector->SelectPeers(path, numHops, isInbound);
|
return m_CustomPeerSelector->SelectPeers(path, numHops, isInbound);
|
||||||
}
|
}
|
||||||
return StandardSelectPeers(path, numHops, isInbound, std::bind(&TunnelPool::SelectNextHop, this, std::placeholders::_1, std::placeholders::_2));
|
return StandardSelectPeers(path, numHops, isInbound, std::bind(&TunnelPool::SelectNextHop, this,
|
||||||
|
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TunnelPool::SelectExplicitPeers (Path& path, bool isInbound)
|
bool TunnelPool::SelectExplicitPeers (Path& path, bool isInbound)
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace tunnel
|
||||||
|
|
||||||
class TunnelPool: public std::enable_shared_from_this<TunnelPool> // per local destination
|
class TunnelPool: public std::enable_shared_from_this<TunnelPool> // per local destination
|
||||||
{
|
{
|
||||||
typedef std::function<std::shared_ptr<const i2p::data::RouterInfo>(std::shared_ptr<const i2p::data::RouterInfo>, bool)> SelectHopFunc;
|
typedef std::function<std::shared_ptr<const i2p::data::RouterInfo>(std::shared_ptr<const i2p::data::RouterInfo>, bool, bool)> SelectHopFunc;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TunnelPool (int numInboundHops, int numOutboundHops, int numInboundTunnels,
|
TunnelPool (int numInboundHops, int numOutboundHops, int numInboundTunnels,
|
||||||
|
@ -112,7 +112,7 @@ namespace tunnel
|
||||||
std::shared_ptr<OutboundTunnel> GetLowestLatencyOutboundTunnel(std::shared_ptr<OutboundTunnel> exclude = nullptr) const;
|
std::shared_ptr<OutboundTunnel> GetLowestLatencyOutboundTunnel(std::shared_ptr<OutboundTunnel> exclude = nullptr) const;
|
||||||
|
|
||||||
// for overriding tunnel peer selection
|
// for overriding tunnel peer selection
|
||||||
std::shared_ptr<const i2p::data::RouterInfo> SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop, bool reverse) const;
|
std::shared_ptr<const i2p::data::RouterInfo> SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop, bool reverse, bool endpoint) const;
|
||||||
bool StandardSelectPeers(Path & path, int numHops, bool inbound, SelectHopFunc nextHop);
|
bool StandardSelectPeers(Path & path, int numHops, bool inbound, SelectHopFunc nextHop);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -73,7 +73,8 @@ namespace client
|
||||||
{
|
{
|
||||||
auto pool = GetTunnelPool();
|
auto pool = GetTunnelPool();
|
||||||
if(!pool || !pool->StandardSelectPeers(path, hops, inbound,
|
if(!pool || !pool->StandardSelectPeers(path, hops, inbound,
|
||||||
std::bind(&i2p::tunnel::TunnelPool::SelectNextHop, pool, std::placeholders::_1, std::placeholders::_2)))
|
std::bind(&i2p::tunnel::TunnelPool::SelectNextHop, pool, std::placeholders::_1,
|
||||||
|
std::placeholders::_2, std::placeholders::_3)))
|
||||||
return false;
|
return false;
|
||||||
// more here for outbound tunnels
|
// more here for outbound tunnels
|
||||||
if(!inbound && m_RemoteLeaseSet)
|
if(!inbound && m_RemoteLeaseSet)
|
||||||
|
|
Loading…
Reference in a new issue