diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index a1ce6838..ee895e32 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -84,6 +84,11 @@ namespace i2p routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ()); routerInfo.AddNTCPAddress (host.c_str(), port); } + if (ntcp2) + { + if (!m_NTCP2Keys) NewNTCP2Keys (); + routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv); + } routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC @@ -92,12 +97,6 @@ namespace i2p routerInfo.CreateBuffer (m_Keys); m_RouterInfo.SetRouterIdentity (GetIdentity ()); m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); - - if (ntcp2) // TODO: should update routerInfo, but we ignore upublished NTCP2 addresses for now - { - if (!m_NTCP2Keys) NewNTCP2Keys (); - UpdateNTCP2Address (true); - } } void RouterContext::UpdateRouterInfo () diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index 21f7132f..95e88963 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -176,13 +176,13 @@ namespace data auto address = std::make_shared
(); s.read ((char *)&address->cost, sizeof (address->cost)); s.read ((char *)&address->date, sizeof (address->date)); - bool isNtcp2 = false; + bool isNTCP2Only = false; char transportStyle[6]; auto transportStyleLen = ReadString (transportStyle, 6, s) - 1; if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2 { address->transportStyle = eTransportNTCP; - if (transportStyleLen > 4 || transportStyle[4] == '2') isNtcp2= true; + if (transportStyleLen > 4 && transportStyle[4] == '2') isNTCP2Only= true; } else if (!strcmp (transportStyle, "SSU")) { @@ -293,7 +293,8 @@ namespace data if (!s) return; } if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented - if (supportedTransports && (!isNtcp2 || address->IsPublishedNTCP2 ())) // we ignore unpublished NTCP2 only addresses + if (isNTCP2Only && address->ntcp2) address->ntcp2->isNTCP2Only = true; + if (supportedTransports) { addresses->push_back(address); m_SupportedTransports |= supportedTransports; @@ -705,6 +706,7 @@ namespace data addr->cost = 14; addr->date = 0; addr->ntcp2.reset (new NTCP2Ext ()); + addr->ntcp2->isNTCP2Only = true; // NTCP2 only address memcpy (addr->ntcp2->staticKey, staticKey, 32); memcpy (addr->ntcp2->iv, iv, 16); m_Addresses->push_back(std::move(addr)); @@ -863,7 +865,7 @@ namespace data return GetAddress ( [v4only](std::shared_ptr