diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index e1e19604..a75b0201 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -250,7 +250,7 @@ namespace i2p bool updated = false; for (auto& address : m_RouterInfo.GetAddresses ()) { - if (address->IsNTCP2 () && (address->port != port || address->ntcp2->isPublished != publish)) + if (address->IsNTCP2 () && (address->port != port || address->published != publish)) { bool isAddr = v4 && address->IsV4 (); if (!isAddr && (v6 || ygg)) @@ -270,7 +270,7 @@ namespace i2p } if (port) address->port = port; address->cost = publish ? i2p::data::COST_NTCP2_PUBLISHED : i2p::data::COST_NTCP2_NON_PUBLISHED; - address->ntcp2->isPublished = publish; + address->published = publish; address->ntcp2->iv = m_NTCP2Keys->iv; updated = true; } @@ -483,6 +483,7 @@ namespace i2p if (addr->ssu && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ()))) { addr->cost = i2p::data::COST_SSU_THROUGH_INTRODUCERS; + addr->published = false; addr->caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer addr->ssu->introducers.clear (); port = addr->port; @@ -514,6 +515,7 @@ namespace i2p if (addr->ssu && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ()))) { addr->cost = i2p::data::COST_SSU_DIRECT; + addr->published = true; addr->caps |= i2p::data::RouterInfo::eSSUIntroducer; addr->ssu->introducers.clear (); port = addr->port; diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index ad57f685..9d4826dc 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -260,7 +260,7 @@ namespace data else if (!strcmp (key, "i")) // ntcp2 iv { Base64ToByteStream (value, strlen (value), address->ntcp2->iv, 16); - address->ntcp2->isPublished = true; // presence if "i" means "published" + address->published = true; // presence if "i" means "published" } else if (key[0] == 'i') { @@ -308,7 +308,7 @@ namespace data else supportedTransports |= eNTCP2V4; } - else if (!address->ntcp2->isPublished) + else if (!address->published) { if (address->caps) { @@ -348,6 +348,8 @@ namespace data } if (!numValid) address->ssu->introducers.resize (0); } + else if (isHost && address->port) + address->published = true; } } if (supportedTransports) @@ -564,7 +566,7 @@ namespace data if (address.IsPeerTesting ()) caps += CAPS_FLAG_SSU_TESTING; if (address.host.is_v4 ()) { - if (IsReachable ()) + if (address.published) { isPublished = true; if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER; @@ -574,8 +576,13 @@ namespace data } else if (address.host.is_v6 ()) { - isPublished = true; - if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER; + if (address.published) + { + isPublished = true; + if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER; + } + else + caps += CAPS_FLAG_V6; } else { @@ -807,6 +814,7 @@ namespace data addr->port = port; addr->transportStyle = eTransportSSU; addr->cost = COST_SSU_DIRECT; // NTCP2 should have priority over SSU + addr->published = true; addr->caps = i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer; // BC; addr->date = 0; addr->ssu.reset (new SSUExt ()); @@ -831,7 +839,7 @@ namespace data addr->caps = 0; addr->date = 0; addr->ntcp2.reset (new NTCP2Ext ()); - if (port) addr->ntcp2->isPublished = true; + if (port) addr->published = true; memcpy (addr->ntcp2->staticKey, staticKey, 32); memcpy (addr->ntcp2->iv, iv, 16); m_Addresses->push_back(std::move(addr)); diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index 336d7741..284d9301 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -115,7 +115,6 @@ namespace data { Tag<32> staticKey; Tag<16> iv; - bool isPublished = false; }; struct Address @@ -125,6 +124,7 @@ namespace data int port; uint64_t date; uint8_t cost, caps; + bool published = false; std::unique_ptr ssu; // not null for SSU std::unique_ptr ntcp2; // not null for NTCP2 @@ -146,7 +146,7 @@ namespace data } bool IsNTCP2 () const { return (bool)ntcp2; }; - bool IsPublishedNTCP2 () const { return IsNTCP2 () && ntcp2->isPublished; }; + bool IsPublishedNTCP2 () const { return IsNTCP2 () && published; }; bool IsReachableSSU () const { return (bool)ssu && (!host.is_unspecified () || !ssu->introducers.empty ()); }; bool UsesIntroducer () const { return (bool)ssu && !ssu->introducers.empty (); };