mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-03-29 11:00:39 +00:00
exclude routers from the same subnet from next hop
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
* Copyright (c) 2013-2026, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -1163,6 +1163,7 @@ namespace data
|
|||||||
(reverse ? (compatibleWith->IsReachableFrom (*router) && router->GetCompatibleTransports (true)):
|
(reverse ? (compatibleWith->IsReachableFrom (*router) && router->GetCompatibleTransports (true)):
|
||||||
router->IsReachableFrom (*compatibleWith)) && !router->IsNAT2NATOnly (*compatibleWith) &&
|
router->IsReachableFrom (*compatibleWith)) && !router->IsNAT2NATOnly (*compatibleWith) &&
|
||||||
router->IsECIES () && !router->IsHighCongestion (clientTunnel) &&
|
router->IsECIES () && !router->IsHighCongestion (clientTunnel) &&
|
||||||
|
!router->IsSameSubnet (*compatibleWith) &&
|
||||||
(!checkIsReal || router->GetProfile ()->IsReal ()) &&
|
(!checkIsReal || router->GetProfile ()->IsReal ()) &&
|
||||||
(!endpoint || (router->IsV4 () && (!reverse || router->IsPublished (true)))); // endpoint must be ipv4 and published if inbound(reverse)
|
(!endpoint || (router->IsV4 () && (!reverse || router->IsPublished (true)))); // endpoint must be ipv4 and published if inbound(reverse)
|
||||||
});
|
});
|
||||||
@@ -1202,6 +1203,7 @@ namespace data
|
|||||||
(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) &&
|
||||||
|
!router->IsSameSubnet (*compatibleWith) &&
|
||||||
(!checkIsReal || router->GetProfile ()->IsReal ()) &&
|
(!checkIsReal || router->GetProfile ()->IsReal ()) &&
|
||||||
(!endpoint || (router->IsV4 () && (!reverse || router->IsPublished (true)))); // endpoint must be ipv4 and published if inbound(reverse)
|
(!endpoint || (router->IsV4 () && (!reverse || router->IsPublished (true)))); // endpoint must be ipv4 and published if inbound(reverse)
|
||||||
|
|
||||||
|
|||||||
@@ -971,15 +971,9 @@ namespace data
|
|||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetAddress (Filter filter) const
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetAddress (Filter filter) const
|
||||||
{
|
{
|
||||||
// TODO: make it more generic using comparator
|
auto addresses = GetAddresses ();
|
||||||
#ifdef __cpp_lib_atomic_shared_ptr
|
|
||||||
AddressesPtr addresses = m_Addresses;
|
|
||||||
#else
|
|
||||||
auto addresses = boost::atomic_load (&m_Addresses);
|
|
||||||
#endif
|
|
||||||
for (const auto& address : *addresses)
|
for (const auto& address : *addresses)
|
||||||
if (address && filter (address)) return address;
|
if (address && filter (address)) return address;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1211,6 +1205,21 @@ namespace data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RouterInfo::IsSameSubnet (const RouterInfo& other) const
|
||||||
|
{
|
||||||
|
auto transports = m_SupportedTransports & other.m_SupportedTransports;
|
||||||
|
if (!transports) return false;
|
||||||
|
auto addresses1 = GetAddresses (), addresses2 = other.GetAddresses ();;
|
||||||
|
for (int i = 0; i < eNumTransports; i++)
|
||||||
|
if (i != eNTCP2V6MeshIdx && (transports & (1 << i)))
|
||||||
|
{
|
||||||
|
auto addr1 = (*addresses1)[i], addr2 = (*addresses2)[i];
|
||||||
|
if (addr1 && addr2 && !addr1->host.is_unspecified () && !addr2->host.is_unspecified ())
|
||||||
|
return addr1->IsSameSubnet (*addr2); // first adddess with IPs
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalRouterInfo::CreateBuffer (const PrivateKeys& privateKeys)
|
void LocalRouterInfo::CreateBuffer (const PrivateKeys& privateKeys)
|
||||||
{
|
{
|
||||||
RefreshTimestamp ();
|
RefreshTimestamp ();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
* Copyright (c) 2013-2026, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -186,6 +186,14 @@ namespace data
|
|||||||
|
|
||||||
bool IsV4 () const { return (caps & AddressCaps::eV4) || (host.is_v4 () && !host.is_unspecified ()); };
|
bool IsV4 () const { return (caps & AddressCaps::eV4) || (host.is_v4 () && !host.is_unspecified ()); };
|
||||||
bool IsV6 () const { return (caps & AddressCaps::eV6) || (host.is_v6 () && !host.is_unspecified ()); };
|
bool IsV6 () const { return (caps & AddressCaps::eV6) || (host.is_v6 () && !host.is_unspecified ()); };
|
||||||
|
|
||||||
|
bool IsSameSubnet (const Address& other)
|
||||||
|
{
|
||||||
|
if (host.is_unspecified () || other.host.is_unspecified ()) return false;
|
||||||
|
if (host.is_v4 () && other.host.is_v4 ()) return !std::memcmp (host.to_v4 ().to_bytes ().data (), other.host.to_v4 ().to_bytes ().data (), 3); // /24
|
||||||
|
if (host.is_v6 () && other.host.is_v6 ()) return !std::memcmp (host.to_v6 ().to_bytes ().data (), other.host.to_v6 ().to_bytes ().data (), 7); // /56
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Buffer: public std::array<uint8_t, MAX_RI_BUFFER_SIZE>
|
class Buffer: public std::array<uint8_t, MAX_RI_BUFFER_SIZE>
|
||||||
@@ -263,6 +271,7 @@ namespace data
|
|||||||
void EnableMesh ();
|
void EnableMesh ();
|
||||||
void DisableMesh ();
|
void DisableMesh ();
|
||||||
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
|
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
|
||||||
|
bool IsSameSubnet (const RouterInfo& other) const;
|
||||||
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
||||||
bool IsReachableBy (CompatibleTransports transports) const { return m_ReachableTransports & transports; };
|
bool IsReachableBy (CompatibleTransports transports) const { return m_ReachableTransports & transports; };
|
||||||
CompatibleTransports GetCompatibleTransports (bool incoming) const { return incoming ? m_ReachableTransports : m_SupportedTransports; };
|
CompatibleTransports GetCompatibleTransports (bool incoming) const { return incoming ? m_ReachableTransports : m_SupportedTransports; };
|
||||||
|
|||||||
Reference in New Issue
Block a user