Browse Source

use m_ReachableTransports bitmask

pull/1664/head
orignal 3 years ago
parent
commit
a6af4908d5
  1. 2
      libi2pd/RouterContext.cpp
  2. 31
      libi2pd/RouterInfo.cpp

2
libi2pd/RouterContext.cpp

@ -489,6 +489,7 @@ namespace i2p @@ -489,6 +489,7 @@ namespace i2p
if (ntcp2)
PublishNTCP2Address (port, false, v4, v6, false);
// update
m_RouterInfo.UpdateSupportedTransports ();
UpdateRouterInfo ();
}
@ -528,6 +529,7 @@ namespace i2p @@ -528,6 +529,7 @@ namespace i2p
}
}
// update
m_RouterInfo.UpdateSupportedTransports ();
UpdateRouterInfo ();
}

31
libi2pd/RouterInfo.cpp

@ -971,10 +971,10 @@ namespace data @@ -971,10 +971,10 @@ namespace data
{
if (!IsV6 ())
{
m_SupportedTransports |= eSSUV6 | eNTCP2V6;
uint8_t addressCaps = AddressCaps::eV6;
if (IsV4 ()) addressCaps |= AddressCaps::eV4;
SetUnreachableAddressesTransportCaps (addressCaps);
UpdateSupportedTransports ();
}
}
@ -982,10 +982,10 @@ namespace data @@ -982,10 +982,10 @@ namespace data
{
if (!IsV4 ())
{
m_SupportedTransports |= eSSUV4 | eNTCP2V4;
uint8_t addressCaps = AddressCaps::eV4;
if (IsV6 ()) addressCaps |= AddressCaps::eV6;
SetUnreachableAddressesTransportCaps (addressCaps);
UpdateSupportedTransports ();
}
}
@ -994,7 +994,6 @@ namespace data @@ -994,7 +994,6 @@ namespace data
{
if (IsV6 ())
{
m_SupportedTransports &= ~(eSSUV6 | eNTCP2V6);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
auto addr = *it;
@ -1011,6 +1010,7 @@ namespace data @@ -1011,6 +1010,7 @@ namespace data
else
++it;
}
UpdateSupportedTransports ();
}
}
@ -1018,7 +1018,6 @@ namespace data @@ -1018,7 +1018,6 @@ namespace data
{
if (IsV4 ())
{
m_SupportedTransports &= ~(eSSUV4 | eNTCP2V4);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
auto addr = *it;
@ -1035,13 +1034,17 @@ namespace data @@ -1035,13 +1034,17 @@ namespace data
else
++it;
}
UpdateSupportedTransports ();
}
}
void RouterInfo::EnableMesh ()
{
if (!IsMesh ())
{
m_SupportedTransports |= eNTCP2V6Mesh;
m_ReachableTransports |= eNTCP2V6Mesh;
}
}
void RouterInfo::DisableMesh ()
@ -1049,6 +1052,7 @@ namespace data @@ -1049,6 +1052,7 @@ namespace data
if (IsMesh ())
{
m_SupportedTransports &= ~eNTCP2V6Mesh;
m_ReachableTransports &= ~eNTCP2V6Mesh;
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
auto addr = *it;
@ -1177,24 +1181,7 @@ namespace data @@ -1177,24 +1181,7 @@ namespace data
bool RouterInfo::IsReachableFrom (const RouterInfo& other) const
{
auto commonTransports = m_SupportedTransports & other.m_SupportedTransports;
if (!commonTransports) return false;
if (commonTransports & eNTCP2V6Mesh) return true;
return (bool)GetAddress (
[commonTransports](std::shared_ptr<const RouterInfo::Address> address)->bool
{
if (address->IsPublishedNTCP2 ())
{
if ((commonTransports & eNTCP2V4) && address->IsV4 ()) return true;
if ((commonTransports & eNTCP2V6) && address->IsV6 ()) return true;
}
else if (address->IsReachableSSU ())
{
if ((commonTransports & eSSUV4) && address->IsV4 ()) return true;
if ((commonTransports & eSSUV6) && address->IsV6 ()) return true;
}
return false;
});
return m_ReachableTransports & other.m_SupportedTransports;
}
void RouterInfo::SetUnreachableAddressesTransportCaps (uint8_t transports)

Loading…
Cancel
Save