Browse Source

publish NTCP2 ipv6 address if applicable

pull/1234/head
orignal 6 years ago
parent
commit
8753186a0d
  1. 2
      libi2pd/NTCP2.cpp
  2. 35
      libi2pd/RouterContext.cpp
  3. 1
      libi2pd/RouterContext.h

2
libi2pd/NTCP2.cpp

@ -1179,6 +1179,8 @@ namespace transport @@ -1179,6 +1179,8 @@ namespace transport
else
{
LogPrint (eLogDebug, "NTCP2: Connected to ", conn->GetSocket ().remote_endpoint ());
if (conn->GetSocket ().local_endpoint ().protocol () == boost::asio::ip::tcp::v6()) // ipv6
context.UpdateNTCP2V6Address (conn->GetSocket ().local_endpoint ().address ());
conn->ClientLogin ();
}
}

35
libi2pd/RouterContext.cpp

@ -453,6 +453,41 @@ namespace i2p @@ -453,6 +453,41 @@ namespace i2p
UpdateRouterInfo ();
}
void RouterContext::UpdateNTCP2V6Address (const boost::asio::ip::address& host)
{
bool updated = false;
int port = 0;
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr: addresses)
{
if (addr->IsPublishedNTCP2 ())
{
if (addr->host.is_v6 ())
{
if (addr->host != host)
{
addr->host = host;
updated = true;
break;
}
}
else
port = addr->port; // NTCP2 v4
}
}
if (!updated)
{
if (port) // we have found NTCP2 v4 but not v6
{
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv);
PublishNTCP2Address (port, true);
}
}
else
UpdateRouterInfo ();
}
void RouterContext::UpdateStats ()
{
if (m_IsFloodfill)

1
libi2pd/RouterContext.h

@ -100,6 +100,7 @@ namespace i2p @@ -100,6 +100,7 @@ namespace i2p
void SetSupportsV4 (bool supportsV4);
void UpdateNTCPV6Address (const boost::asio::ip::address& host); // called from NTCP session
void UpdateNTCP2V6Address (const boost::asio::ip::address& host); // called from NTCP2 session
void UpdateStats ();
void CleanupDestination (); // garlic destination

Loading…
Cancel
Save