Browse Source

set correct 4 and 6 caps for unreachable addresses

pull/1641/head
orignal 4 years ago
parent
commit
97f315d488
  1. 17
      libi2pd/RouterContext.cpp
  2. 34
      libi2pd/RouterInfo.cpp
  3. 1
      libi2pd/RouterInfo.h

17
libi2pd/RouterContext.cpp

@ -92,7 +92,7 @@ namespace i2p
if (!ntcp2proxy.empty ()) ntcp2Published = false; if (!ntcp2proxy.empty ()) ntcp2Published = false;
} }
} }
uint8_t caps = 0; uint8_t caps = 0, addressCaps = 0;
if (ipv4) if (ipv4)
{ {
std::string host = "127.0.0.1"; std::string host = "127.0.0.1";
@ -109,7 +109,10 @@ namespace i2p
if (ntcp2Published) if (ntcp2Published)
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address_v4::from_string (host), port); routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address_v4::from_string (host), port);
else // add non-published NTCP2 address else // add non-published NTCP2 address
{
addressCaps = i2p::data::RouterInfo::AddressCaps::eV4;
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv); routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv);
}
} }
if (ssu) if (ssu)
{ {
@ -138,8 +141,12 @@ namespace i2p
ntcp2Host = host; ntcp2Host = host;
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address_v6::from_string (ntcp2Host), port); routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address_v6::from_string (ntcp2Host), port);
} }
else if (!ipv4) // no other ntcp2 addresses yet else
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv); {
if (!ipv4) // no other ntcp2 addresses yet
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv);
addressCaps |= i2p::data::RouterInfo::AddressCaps::eV6;
}
} }
if (ssu) if (ssu)
{ {
@ -154,6 +161,8 @@ namespace i2p
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, yggaddr, port); routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, yggaddr, port);
} }
if (addressCaps)
routerInfo.SetUnreachableAddressesTransportCaps (addressCaps);
routerInfo.SetCaps (caps); // caps + L routerInfo.SetCaps (caps); // caps + L
routerInfo.SetProperty ("netId", std::to_string (m_NetID)); routerInfo.SetProperty ("netId", std::to_string (m_NetID));
routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.SetProperty ("router.version", I2P_VERSION);
@ -494,7 +503,6 @@ namespace i2p
{ {
if (supportsV6) if (supportsV6)
{ {
m_RouterInfo.EnableV6 ();
// insert v6 addresses if necessary // insert v6 addresses if necessary
bool foundSSU = false, foundNTCP2 = false; bool foundSSU = false, foundNTCP2 = false;
uint16_t port = 0; uint16_t port = 0;
@ -538,6 +546,7 @@ namespace i2p
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address::from_string (ntcp2Host), ntcp2Port); m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address::from_string (ntcp2Host), ntcp2Port);
} }
} }
m_RouterInfo.EnableV6 ();
} }
else else
m_RouterInfo.DisableV6 (); m_RouterInfo.DisableV6 ();

34
libi2pd/RouterInfo.cpp

@ -546,10 +546,14 @@ namespace data
WriteString ("caps", properties); WriteString ("caps", properties);
properties << '='; properties << '=';
std::string caps; std::string caps;
if (address.IsPeerTesting ()) caps += CAPS_FLAG_SSU_TESTING;
if (address.host.is_v4 ()) if (address.host.is_v4 ())
{ {
if (IsReachable ()) if (IsReachable ())
{
isPublished = true; isPublished = true;
if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER;
}
else else
caps += CAPS_FLAG_V4; caps += CAPS_FLAG_V4;
} }
@ -561,8 +565,6 @@ namespace data
if (address.caps & AddressCaps::eV6) caps += CAPS_FLAG_V6; if (address.caps & AddressCaps::eV6) caps += CAPS_FLAG_V6;
if (caps.empty ()) caps += CAPS_FLAG_V4; if (caps.empty ()) caps += CAPS_FLAG_V4;
} }
if (address.IsPeerTesting ()) caps += CAPS_FLAG_SSU_TESTING;
if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER;
WriteString (caps, properties); WriteString (caps, properties);
properties << ';'; properties << ';';
} }
@ -799,9 +801,6 @@ namespace data
if (*it == *addr) return; if (*it == *addr) return;
m_SupportedTransports |= addr->host.is_v6 () ? eSSUV6 : eSSUV4; m_SupportedTransports |= addr->host.is_v6 () ? eSSUV6 : eSSUV4;
m_Addresses->push_back(std::move(addr)); m_Addresses->push_back(std::move(addr));
m_Caps |= eSSUTesting;
m_Caps |= eSSUIntroducer;
} }
void RouterInfo::AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv, const boost::asio::ip::address& host, int port) void RouterInfo::AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv, const boost::asio::ip::address& host, int port)
@ -927,13 +926,23 @@ namespace data
void RouterInfo::EnableV6 () void RouterInfo::EnableV6 ()
{ {
if (!IsV6 ()) if (!IsV6 ())
{
m_SupportedTransports |= eSSUV6 | eNTCP2V6; m_SupportedTransports |= eSSUV6 | eNTCP2V6;
uint8_t addressCaps = AddressCaps::eV6;
if (IsV4 ()) addressCaps |= AddressCaps::eV4;
SetUnreachableAddressesTransportCaps (addressCaps);
}
} }
void RouterInfo::EnableV4 () void RouterInfo::EnableV4 ()
{ {
if (!IsV4 ()) if (!IsV4 ())
{
m_SupportedTransports |= eSSUV4 | eNTCP2V4; m_SupportedTransports |= eSSUV4 | eNTCP2V4;
uint8_t addressCaps = AddressCaps::eV4;
if (IsV6 ()) addressCaps |= AddressCaps::eV6;
SetUnreachableAddressesTransportCaps (addressCaps);
}
} }
@ -945,6 +954,7 @@ namespace data
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();) for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{ {
auto addr = *it; auto addr = *it;
addr->caps &= ~AddressCaps::eV6;
if (addr->host.is_v6 ()) if (addr->host.is_v6 ())
it = m_Addresses->erase (it); it = m_Addresses->erase (it);
else else
@ -961,6 +971,7 @@ namespace data
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();) for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{ {
auto addr = *it; auto addr = *it;
addr->caps &= ~AddressCaps::eV4;
if (addr->host.is_v4 ()) if (addr->host.is_v4 ())
it = m_Addresses->erase (it); it = m_Addresses->erase (it);
else else
@ -1126,5 +1137,18 @@ namespace data
return false; return false;
}); });
} }
void RouterInfo::SetUnreachableAddressesTransportCaps (uint8_t transports)
{
for (auto& addr: *m_Addresses)
{
// TODO: implement SSU
if (addr->transportStyle == eTransportNTCP && (!addr->IsPublishedNTCP2 () || addr->port))
{
addr->caps &= ~(eV4 | eV6);
addr->caps |= transports;
}
}
}
} }
} }

1
libi2pd/RouterInfo.h

@ -182,6 +182,7 @@ namespace data
void DeleteProperty (const std::string& key); // called from RouterContext only void DeleteProperty (const std::string& key); // called from RouterContext only
std::string GetProperty (const std::string& key) const; // called from RouterContext only std::string GetProperty (const std::string& key) const; // called from RouterContext only
void ClearProperties () { m_Properties.clear (); }; void ClearProperties () { m_Properties.clear (); };
void SetUnreachableAddressesTransportCaps (uint8_t transports); // bitmask of AddressCaps
bool IsFloodfill () const { return m_Caps & Caps::eFloodfill; }; bool IsFloodfill () const { return m_Caps & Caps::eFloodfill; };
bool IsReachable () const { return m_Caps & Caps::eReachable; }; bool IsReachable () const { return m_Caps & Caps::eReachable; };
bool IsSSU (bool v4only = true) const; bool IsSSU (bool v4only = true) const;

Loading…
Cancel
Save