Browse Source

update ipv6 addresses from SSU rather than NTCP or NTCP2

pull/1359/head
orignal 5 years ago
parent
commit
8e3d16e9fb
  1. 2
      libi2pd/NTCP2.cpp
  2. 2
      libi2pd/NTCPSession.cpp
  3. 137
      libi2pd/RouterContext.cpp
  4. 3
      libi2pd/RouterContext.h
  5. 2
      libi2pd/RouterInfo.cpp

2
libi2pd/NTCP2.cpp

@ -1304,8 +1304,6 @@ namespace transport
else else
{ {
LogPrint (eLogDebug, "NTCP2: Connected to ", conn->GetSocket ().remote_endpoint ()); 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 (); conn->ClientLogin ();
} }
} }

2
libi2pd/NTCPSession.cpp

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

137
libi2pd/RouterContext.cpp

@ -238,6 +238,20 @@ namespace i2p
if (address->host != host && address->IsCompatible (host)) if (address->host != host && address->IsCompatible (host))
{ {
address->host = host; address->host = host;
if (host.is_v6 () && address->transportStyle == i2p::data::RouterInfo::eTransportSSU)
{
// update MTU
auto mtu = i2p::util::net::GetMTU (host);
if (mtu)
{
LogPrint (eLogDebug, "Router: Our v6 MTU=", mtu);
if (mtu > 1472) { // TODO: magic constant
mtu = 1472;
LogPrint(eLogWarning, "Router: MTU dropped to upper limit of 1472 bytes");
}
if (address->ssu) address->ssu->mtu = mtu;
}
}
updated = true; updated = true;
} }
} }
@ -444,65 +458,83 @@ namespace i2p
void RouterContext::SetSupportsV6 (bool supportsV6) void RouterContext::SetSupportsV6 (bool supportsV6)
{ {
if (supportsV6) if (supportsV6)
m_RouterInfo.EnableV6 ();
else
m_RouterInfo.DisableV6 ();
UpdateRouterInfo ();
}
void RouterContext::SetSupportsV4 (bool supportsV4)
{
if (supportsV4)
m_RouterInfo.EnableV4 ();
else
m_RouterInfo.DisableV4 ();
UpdateRouterInfo ();
}
void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host)
{ {
bool updated = false, found = false; m_RouterInfo.EnableV6 ();
int port = 0; // insert v6 addresses if necessary
bool foundSSU = false, foundNTCP = false, foundNTCP2 = false;
uint16_t port = 0;
auto& addresses = m_RouterInfo.GetAddresses (); auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr: addresses) for (auto& addr: addresses)
{ {
if (addr->host.is_v6 () && addr->transportStyle == i2p::data::RouterInfo::eTransportNTCP) if (addr->host.is_v6 ())
{ {
if (addr->host != host) if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU)
foundSSU = true;
else if (addr->IsNTCP2 ())
{ {
addr->host = host; if (addr->IsPublishedNTCP2 ()) foundNTCP2 = true;
updated = true;
}
found = true;
} }
else else
foundNTCP = true;
}
port = addr->port; port = addr->port;
} }
if (!found) if (!port) i2p::config::GetOption("port", port);
// SSU
if (!foundSSU)
{ {
// create new address bool ssu; i2p::config::GetOption("ssu", ssu);
m_RouterInfo.AddNTCPAddress (host.to_string ().c_str (), port); if (ssu)
auto mtu = i2p::util::net::GetMTU (host);
if (mtu)
{ {
LogPrint (eLogDebug, "Router: Our v6 MTU=", mtu); std::string host = "::1"; // TODO: read host
if (mtu > 1472) { // TODO: magic constant m_RouterInfo.AddSSUAddress (host.c_str (), port, GetIdentHash ());
mtu = 1472;
LogPrint(eLogWarning, "Router: MTU dropped to upper limit of 1472 bytes");
} }
} }
m_RouterInfo.AddSSUAddress (host.to_string ().c_str (), port, GetIdentHash (), mtu ? mtu : 1472); // TODO // NTCP2
updated = true; if (!foundNTCP2)
{
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
bool ntcp2Published; i2p::config::GetOption("ntcp2.published", ntcp2Published);
if (ntcp2 && ntcp2Published)
{
std::string ntcp2Host;
if (!i2p::config::IsDefault ("ntcp2.addressv6"))
i2p::config::GetOption ("ntcp2.addressv6", ntcp2Host);
else
ntcp2Host = "::1";
uint16_t ntcp2Port; i2p::config::GetOption ("ntcp2.port", ntcp2Port);
if (!ntcp2Port) ntcp2Port = port;
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, boost::asio::ip::address::from_string (ntcp2Host), ntcp2Port);
} }
if (updated) }
// NTCP
if (!foundNTCP)
{
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
if (ntcp)
{
std::string host = "::1";
m_RouterInfo.AddNTCPAddress (host.c_str (), port);
}
}
}
else
m_RouterInfo.DisableV6 ();
UpdateRouterInfo ();
}
void RouterContext::SetSupportsV4 (bool supportsV4)
{
if (supportsV4)
m_RouterInfo.EnableV4 ();
else
m_RouterInfo.DisableV4 ();
UpdateRouterInfo (); UpdateRouterInfo ();
} }
void RouterContext::UpdateNTCP2V6Address (const boost::asio::ip::address& host) void RouterContext::UpdateNTCP2V6Address (const boost::asio::ip::address& host)
{ {
bool updated = false, found = false; bool updated = false;
int port = 0;
auto& addresses = m_RouterInfo.GetAddresses (); auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr: addresses) for (auto& addr: addresses)
{ {
@ -515,38 +547,11 @@ namespace i2p
addr->host = host; addr->host = host;
updated = true; updated = true;
} }
found = true;
break; break;
} }
else
port = addr->port; // NTCP2 v4
} }
} }
if (!found && port) // we have found NTCP2 v4 but not v6
{
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, host, port);
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
bool ssu; i2p::config::GetOption("ssu", ssu);
if (!ntcp && ssu)
{
// we must publish SSU address
auto mtu = i2p::util::net::GetMTU (host);
if (mtu)
{
LogPrint (eLogDebug, "Router: Our v6 MTU=", mtu);
if (mtu > 1472) // TODO: magic constant
{
mtu = 1472;
LogPrint(eLogWarning, "Router: MTU dropped to upper limit of 1472 bytes");
}
}
else
mtu = 1472;
m_RouterInfo.AddSSUAddress (host.to_string ().c_str (), port, GetIdentHash (), mtu);
}
updated = true;
}
if (updated) if (updated)
UpdateRouterInfo (); UpdateRouterInfo ();
} }

3
libi2pd/RouterContext.h

@ -101,8 +101,7 @@ namespace i2p
void SetSupportsV6 (bool supportsV6); void SetSupportsV6 (bool supportsV6);
void SetSupportsV4 (bool supportsV4); 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 Daemon. TODO: remove
void UpdateNTCP2V6Address (const boost::asio::ip::address& host); // called from NTCP2 session
void UpdateStats (); void UpdateStats ();
void UpdateTimestamp (uint64_t ts); // in seconds, called from NetDb before publishing void UpdateTimestamp (uint64_t ts); // in seconds, called from NetDb before publishing
void CleanupDestination (); // garlic destination void CleanupDestination (); // garlic destination

2
libi2pd/RouterInfo.cpp

@ -824,7 +824,7 @@ namespace data
bool RouterInfo::IsV6 () const bool RouterInfo::IsV6 () const
{ {
return m_SupportedTransports & (eNTCPV6 | eSSUV6); return m_SupportedTransports & (eNTCPV6 | eSSUV6 | eNTCP2V6);
} }
bool RouterInfo::IsV4 () const bool RouterInfo::IsV4 () const

Loading…
Cancel
Save