Browse Source

published field for SSU addresses

pull/1656/head
orignal 4 years ago
parent
commit
5c9b478e46
  1. 6
      libi2pd/RouterContext.cpp
  2. 16
      libi2pd/RouterInfo.cpp
  3. 4
      libi2pd/RouterInfo.h

6
libi2pd/RouterContext.cpp

@ -250,7 +250,7 @@ namespace i2p @@ -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 @@ -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 @@ -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 @@ -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;

16
libi2pd/RouterInfo.cpp

@ -260,7 +260,7 @@ namespace data @@ -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 @@ -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 @@ -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 @@ -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;
@ -573,10 +575,15 @@ namespace data @@ -573,10 +575,15 @@ namespace data
caps += CAPS_FLAG_V4;
}
else if (address.host.is_v6 ())
{
if (address.published)
{
isPublished = true;
if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER;
}
else
caps += CAPS_FLAG_V6;
}
else
{
if (address.IsV4 ()) caps += CAPS_FLAG_V4;
@ -807,6 +814,7 @@ namespace data @@ -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 @@ -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));

4
libi2pd/RouterInfo.h

@ -115,7 +115,6 @@ namespace data @@ -115,7 +115,6 @@ namespace data
{
Tag<32> staticKey;
Tag<16> iv;
bool isPublished = false;
};
struct Address
@ -125,6 +124,7 @@ namespace data @@ -125,6 +124,7 @@ namespace data
int port;
uint64_t date;
uint8_t cost, caps;
bool published = false;
std::unique_ptr<SSUExt> ssu; // not null for SSU
std::unique_ptr<NTCP2Ext> ntcp2; // not null for NTCP2
@ -146,7 +146,7 @@ namespace data @@ -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 (); };

Loading…
Cancel
Save