Browse Source

eliminate cost field

pull/1656/head
orignal 4 years ago
parent
commit
277cef5ec4
  1. 3
      libi2pd/RouterContext.cpp
  2. 15
      libi2pd/RouterInfo.cpp
  3. 2
      libi2pd/RouterInfo.h

3
libi2pd/RouterContext.cpp

@ -269,7 +269,6 @@ namespace i2p @@ -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 @@ -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 @@ -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 ();

15
libi2pd/RouterInfo.cpp

@ -197,7 +197,8 @@ namespace data @@ -197,7 +197,8 @@ namespace data
{
uint8_t supportedTransports = 0;
auto address = std::make_shared<Address>();
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 @@ -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 @@ -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 @@ -834,8 +840,7 @@ namespace data
auto addr = std::make_shared<Address>();
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 ());

2
libi2pd/RouterInfo.h

@ -123,7 +123,7 @@ namespace data @@ -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<SSUExt> ssu; // not null for SSU
std::unique_ptr<NTCP2Ext> ntcp2; // not null for NTCP2

Loading…
Cancel
Save