diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index a75b0201..54843073 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -269,7 +269,6 @@ namespace i2p if (port == 9150) port = 9151; // Tor browser } if (port) address->port = port; - address->cost = publish ? i2p::data::COST_NTCP2_PUBLISHED : i2p::data::COST_NTCP2_NON_PUBLISHED; address->published = publish; address->ntcp2->iv = m_NTCP2Keys->iv; updated = true; @@ -482,7 +481,6 @@ namespace i2p for (auto& addr : addresses) 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 (); @@ -514,7 +512,6 @@ namespace i2p for (auto& addr : addresses) 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 (); diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index 9d4826dc..e9f27d96 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -197,7 +197,8 @@ namespace data { uint8_t supportedTransports = 0; auto address = std::make_shared
(); - s.read ((char *)&address->cost, sizeof (address->cost)); + uint8_t cost; // ignore + s.read ((char *)&cost, sizeof (cost)); s.read ((char *)&address->date, sizeof (address->date)); bool isHost = false, isIntroKey = false, isStaticKey = false; char transportStyle[6]; @@ -530,7 +531,13 @@ namespace data for (const auto& addr_ptr : *m_Addresses) { const Address& address = *addr_ptr; - s.write ((const char *)&address.cost, sizeof (address.cost)); + // calculate cost + uint8_t cost = 0x7f; + if (address.transportStyle == eTransportNTCP) + cost = address.published ? COST_NTCP2_PUBLISHED : COST_NTCP2_NON_PUBLISHED; + else if (address.transportStyle == eTransportSSU) + cost = address.published ? COST_SSU_DIRECT : COST_SSU_THROUGH_INTRODUCERS; + s.write ((const char *)&cost, sizeof (cost)); s.write ((const char *)&address.date, sizeof (address.date)); std::stringstream properties; bool isPublished = false; @@ -813,7 +820,6 @@ namespace data addr->host = boost::asio::ip::address::from_string (host); 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; @@ -834,8 +840,7 @@ namespace data auto addr = std::make_shared
(); addr->host = host; addr->port = port; - addr->transportStyle = eTransportNTCP; - addr->cost = port ? COST_NTCP2_PUBLISHED : COST_NTCP2_NON_PUBLISHED; // override from RouterContext::PublishNTCP2Address + addr->transportStyle = eTransportNTCP; addr->caps = 0; addr->date = 0; addr->ntcp2.reset (new NTCP2Ext ()); diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index 284d9301..bdb92b8a 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -123,7 +123,7 @@ namespace data boost::asio::ip::address host; int port; uint64_t date; - uint8_t cost, caps; + uint8_t caps; bool published = false; std::unique_ptr ssu; // not null for SSU std::unique_ptr ntcp2; // not null for NTCP2