Browse Source

use only SSU2 for network status

pull/1811/head
orignal 2 years ago
parent
commit
ccfeca728e
  1. 122
      libi2pd/RouterContext.cpp
  2. 5
      libi2pd/RouterContext.h
  3. 7
      libi2pd/SSU2.cpp
  4. 4
      libi2pd/SSU2Session.cpp
  5. 4
      libi2pd/Transports.cpp

122
libi2pd/RouterContext.cpp

@ -63,7 +63,6 @@ namespace i2p @@ -63,7 +63,6 @@ namespace i2p
if (!port) port = SelectRandomPort ();
bool ipv4; i2p::config::GetOption("ipv4", ipv4);
bool ipv6; i2p::config::GetOption("ipv6", ipv6);
bool ssu; i2p::config::GetOption("ssu", ssu);
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2);
bool ygg; i2p::config::GetOption("meshnets.yggdrasil", ygg);
@ -109,17 +108,12 @@ namespace i2p @@ -109,17 +108,12 @@ namespace i2p
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv);
}
}
if (ssu)
{
routerInfo.AddSSUAddress (host.c_str(), port, nullptr);
caps |= i2p::data::RouterInfo::eReachable; // R
}
if (ssu2)
{
if (ssu2Published)
{
uint16_t ssu2Port; i2p::config::GetOption ("ssu2.port", ssu2Port);
if (!ssu2Port) ssu2Port = ssu ? (port + 1) : port;
if (!ssu2Port) ssu2Port = port;
routerInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, boost::asio::ip::address_v4::from_string (host), ssu2Port);
}
else
@ -158,17 +152,12 @@ namespace i2p @@ -158,17 +152,12 @@ namespace i2p
addressCaps |= i2p::data::RouterInfo::AddressCaps::eV6;
}
}
if (ssu)
{
routerInfo.AddSSUAddress (host.c_str(), port, nullptr);
caps |= i2p::data::RouterInfo::eReachable; // R
}
if (ssu2)
{
if (ssu2Published)
{
uint16_t ssu2Port; i2p::config::GetOption ("ssu2.port", ssu2Port);
if (!ssu2Port) ssu2Port = ssu ? (port + 1) : port;
if (!ssu2Port) ssu2Port = port;
routerInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, boost::asio::ip::address_v6::from_string (host), ssu2Port);
}
else
@ -236,13 +225,6 @@ namespace i2p @@ -236,13 +225,6 @@ namespace i2p
fk.write ((char *)m_SSU2Keys.get (), sizeof (SSU2PrivateKeys));
}
bool RouterContext::IsSSU2Only () const
{
auto transports = m_RouterInfo.GetCompatibleTransports (false);
return (transports & (i2p::data::RouterInfo::eSSU2V4 | i2p::data::RouterInfo::eSSU2V6)) &&
!(transports & (i2p::data::RouterInfo::eSSUV4 | i2p::data::RouterInfo::eSSUV6));
}
void RouterContext::SetStatus (RouterStatus status)
{
if (status != m_Status)
@ -263,12 +245,6 @@ namespace i2p @@ -263,12 +245,6 @@ namespace i2p
}
}
void RouterContext::SetStatusSSU2 (RouterStatus status)
{
if (IsSSU2Only ())
SetStatus (status);
}
void RouterContext::SetStatusV6 (RouterStatus status)
{
if (status != m_StatusV6)
@ -289,18 +265,12 @@ namespace i2p @@ -289,18 +265,12 @@ namespace i2p
}
}
void RouterContext::SetStatusV6SSU2 (RouterStatus status)
{
if (IsSSU2Only ())
SetStatusV6 (status);
}
void RouterContext::UpdatePort (int port)
{
bool updated = false;
for (auto& address : m_RouterInfo.GetAddresses ())
{
if (address->port != port && (address->transportStyle == i2p::data::RouterInfo::eTransportSSU || IsSSU2Only ()))
if (address->port != port && address->transportStyle == i2p::data::RouterInfo::eTransportSSU2)
{
address->port = port;
updated = true;
@ -476,8 +446,6 @@ namespace i2p @@ -476,8 +446,6 @@ namespace i2p
mtu = maxMTU;
LogPrint(eLogWarning, "Router: MTU dropped to upper limit of ", maxMTU, " bytes");
}
if (mtu && !address->IsSSU2 ()) // SSU1
mtu = (mtu >> 4) << 4; // round to multiple of 16
address->ssu->mtu = mtu;
updated = true;
}
@ -488,23 +456,8 @@ namespace i2p @@ -488,23 +456,8 @@ namespace i2p
UpdateRouterInfo ();
}
bool RouterContext::AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer)
{
bool ret = m_RouterInfo.AddIntroducer (introducer);
if (ret)
UpdateRouterInfo ();
return ret;
}
void RouterContext::RemoveIntroducer (const boost::asio::ip::udp::endpoint& e)
{
if (m_RouterInfo.RemoveIntroducer (e))
UpdateRouterInfo ();
}
bool RouterContext::AddSSU2Introducer (const i2p::data::RouterInfo::Introducer& introducer, bool v4)
{
if (!IsSSU2Only ()) return false;
bool ret = m_RouterInfo.AddSSU2Introducer (introducer, v4);
if (ret)
UpdateRouterInfo ();
@ -513,7 +466,6 @@ namespace i2p @@ -513,7 +466,6 @@ namespace i2p
void RouterContext::RemoveSSU2Introducer (const i2p::data::IdentHash& h, bool v4)
{
if (!IsSSU2Only ()) return;
if (m_RouterInfo.RemoveSSU2Introducer (h, v4))
UpdateRouterInfo ();
}
@ -669,12 +621,6 @@ namespace i2p @@ -669,12 +621,6 @@ namespace i2p
m_RouterInfo.UpdateSupportedTransports ();
}
void RouterContext::SetUnreachableSSU2 (bool v4, bool v6)
{
if (IsSSU2Only ())
SetUnreachable (v4, v6);
}
void RouterContext::SetUnreachable (bool v4, bool v6)
{
if (v4 || (v6 && !SupportsV4 ()))
@ -691,8 +637,7 @@ namespace i2p @@ -691,8 +637,7 @@ namespace i2p
// delete previous introducers
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses)
if (addr->ssu && (!addr->IsSSU2 () || IsSSU2Only ()) &&
((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ())))
if (addr->ssu && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ())))
{
addr->published = false;
addr->caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer
@ -722,19 +667,15 @@ namespace i2p @@ -722,19 +667,15 @@ namespace i2p
}
uint16_t port = 0;
// delete previous introducers
bool isSSU2Published = IsSSU2Only (); // TODO
if (isSSU2Published)
i2p::config::GetOption ("ssu2.published", isSSU2Published);
bool isSSU2Published; i2p::config::GetOption ("ssu2.published", isSSU2Published);
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses)
if (addr->ssu && (!addr->IsSSU2 () || isSSU2Published) &&
((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ())))
if (addr->ssu && isSSU2Published && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ())))
{
addr->published = true;
addr->caps |= i2p::data::RouterInfo::eSSUIntroducer;
addr->ssu->introducers.clear ();
if (addr->port && (!addr->IsSSU2 () || IsSSU2Only ()))
port = addr->port;
if (addr->port) port = addr->port;
}
// publish NTCP2
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
@ -758,7 +699,7 @@ namespace i2p @@ -758,7 +699,7 @@ namespace i2p
if (supportsV6)
{
// insert v6 addresses if necessary
bool foundSSU = false, foundNTCP2 = false, foundSSU2 = false;
bool foundNTCP2 = false, foundSSU2 = false;
uint16_t port = 0;
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr: addresses)
@ -767,9 +708,6 @@ namespace i2p @@ -767,9 +708,6 @@ namespace i2p
{
switch (addr->transportStyle)
{
case i2p::data::RouterInfo::eTransportSSU:
foundSSU = true;
break;
case i2p::data::RouterInfo::eTransportNTCP:
foundNTCP2 = true;
break;
@ -786,13 +724,6 @@ namespace i2p @@ -786,13 +724,6 @@ namespace i2p
i2p::config::GetOption("port", port);
if (!port) port = SelectRandomPort ();
}
// SSU
bool ssu; i2p::config::GetOption("ssu", ssu);
if (!foundSSU && ssu)
{
std::string host = "::1"; // TODO: read host
m_RouterInfo.AddSSUAddress (host.c_str (), port, nullptr);
}
// NTCP2
if (!foundNTCP2)
{
@ -825,7 +756,7 @@ namespace i2p @@ -825,7 +756,7 @@ namespace i2p
if (ssu2Published)
{
uint16_t ssu2Port; i2p::config::GetOption ("ssu2.port", ssu2Port);
if (!ssu2Port) ssu2Port = ssu ? (port + 1) : port;
if (!ssu2Port) ssu2Port = port;
m_RouterInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, boost::asio::ip::address::from_string ("::1"), ssu2Port);
}
else
@ -847,7 +778,7 @@ namespace i2p @@ -847,7 +778,7 @@ namespace i2p
// update
if (supportsV4)
{
bool foundSSU = false, foundNTCP2 = false, foundSSU2 = false;
bool foundNTCP2 = false, foundSSU2 = false;
std::string host = "127.0.0.1";
uint16_t port = 0;
auto& addresses = m_RouterInfo.GetAddresses ();
@ -857,9 +788,6 @@ namespace i2p @@ -857,9 +788,6 @@ namespace i2p
{
switch (addr->transportStyle)
{
case i2p::data::RouterInfo::eTransportSSU:
foundSSU = true;
break;
case i2p::data::RouterInfo::eTransportNTCP:
foundNTCP2 = true;
break;
@ -876,11 +804,6 @@ namespace i2p @@ -876,11 +804,6 @@ namespace i2p
i2p::config::GetOption("port", port);
if (!port) port = SelectRandomPort ();
}
// SSU
bool ssu; i2p::config::GetOption("ssu", ssu);
if (!foundSSU && ssu)
m_RouterInfo.AddSSUAddress (host.c_str (), port, nullptr);
// NTCP2
if (!foundNTCP2)
{
@ -908,7 +831,7 @@ namespace i2p @@ -908,7 +831,7 @@ namespace i2p
if (ssu2Published)
{
uint16_t ssu2Port; i2p::config::GetOption ("ssu2.port", ssu2Port);
if (!ssu2Port) ssu2Port = ssu ? (port + 1) : port;
if (!ssu2Port) ssu2Port = port;
m_RouterInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, boost::asio::ip::address::from_string ("127.0.0.1"), ssu2Port);
}
else
@ -956,35 +879,12 @@ namespace i2p @@ -956,35 +879,12 @@ namespace i2p
for (auto& addr: addresses)
{
if (addr->ssu && ((v4 && addr->IsV4 ()) || (!v4 && addr->IsV6 ())))
{
if (!addr->IsSSU2 ()) // SSU1
{
// round to multiple of 16
if (v4)
{
if (mtu > 1484) mtu = 1484;
else
{
mtu -= 12;
mtu = (mtu >> 4) << 4;
mtu += 12;
}
}
else
{
if (mtu > 1488) mtu = 1488;
else
mtu = (mtu >> 4) << 4;
}
}
if (mtu)
{
addr->ssu->mtu = mtu;
LogPrint (eLogDebug, "Router: MTU for ", v4 ? "ipv4" : "ipv6", " address ", addr->host.to_string(), " is set to ", mtu);
}
}
}
}
void RouterContext::UpdateNTCP2V6Address (const boost::asio::ip::address& host)
{

5
libi2pd/RouterContext.h

@ -102,12 +102,10 @@ namespace garlic @@ -102,12 +102,10 @@ namespace garlic
uint64_t GetTransitBandwidthLimit () const { return (m_BandwidthLimit*m_ShareRatio)/100LL; };
RouterStatus GetStatus () const { return m_Status; };
void SetStatus (RouterStatus status);
void SetStatusSSU2 (RouterStatus status);
RouterError GetError () const { return m_Error; };
void SetError (RouterError error) { m_Error = error; };
RouterStatus GetStatusV6 () const { return m_StatusV6; };
void SetStatusV6 (RouterStatus status);
void SetStatusV6SSU2 (RouterStatus status);
RouterError GetErrorV6 () const { return m_ErrorV6; };
void SetErrorV6 (RouterError error) { m_ErrorV6 = error; };
int GetNetID () const { return m_NetID; };
@ -123,14 +121,11 @@ namespace garlic @@ -123,14 +121,11 @@ namespace garlic
void UpdateSSU2Address (bool enable);
void RemoveNTCPAddress (bool v4only = true); // delete NTCP address for older routers. TODO: remove later
void RemoveSSUAddress (); // delete SSU address for older routers
bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer);
void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e);
bool AddSSU2Introducer (const i2p::data::RouterInfo::Introducer& introducer, bool v4);
void RemoveSSU2Introducer (const i2p::data::IdentHash& h, bool v4);
void ClearSSU2Introducers (bool v4);
bool IsUnreachable () const;
void SetUnreachable (bool v4, bool v6);
void SetUnreachableSSU2 (bool v4, bool v6);
void SetReachable (bool v4, bool v6);
bool IsFloodfill () const { return m_IsFloodfill; };
void SetFloodfill (bool floodfill);

7
libi2pd/SSU2.cpp

@ -68,9 +68,8 @@ namespace transport @@ -68,9 +68,8 @@ namespace transport
if (ssu2Port) port = ssu2Port;
else
{
bool ssu; i2p::config::GetOption("ssu", ssu);
uint16_t p; i2p::config::GetOption ("port", p);
if (p) port = ssu ? (p + 1) : p;
if (p) port = p;
}
}
if (port)
@ -1068,7 +1067,7 @@ namespace transport @@ -1068,7 +1067,7 @@ namespace transport
// we are firewalled
auto addr = i2p::context.GetRouterInfo ().GetSSU2V4Address ();
if (addr && addr->ssu && addr->ssu->introducers.empty ())
i2p::context.SetUnreachableSSU2 (true, false); // v4
i2p::context.SetUnreachable (true, false); // v4
UpdateIntroducers (true);
ScheduleIntroducersUpdateTimer ();
@ -1091,7 +1090,7 @@ namespace transport @@ -1091,7 +1090,7 @@ namespace transport
// we are firewalled
auto addr = i2p::context.GetRouterInfo ().GetSSU2V6Address ();
if (addr && addr->ssu && addr->ssu->introducers.empty ())
i2p::context.SetUnreachableSSU2 (false, true); // v6
i2p::context.SetUnreachable (false, true); // v6
UpdateIntroducers (false);
ScheduleIntroducersUpdateTimerV6 ();

4
libi2pd/SSU2Session.cpp

@ -2266,9 +2266,9 @@ namespace transport @@ -2266,9 +2266,9 @@ namespace transport
if (m_Address)
{
if (m_Address->IsV4 ())
i2p::context.SetStatusSSU2 (status);
i2p::context.SetStatus (status);
else if (m_Address->IsV6 ())
i2p::context.SetStatusV6SSU2 (status);
i2p::context.SetStatusV6 (status);
}
}

4
libi2pd/Transports.cpp

@ -616,7 +616,7 @@ namespace transport @@ -616,7 +616,7 @@ namespace transport
if (router)
{
if (i2p::context.GetStatus () != eRouterStatusTesting)
i2p::context.SetStatusSSU2 (eRouterStatusTesting);
i2p::context.SetStatus (eRouterStatusTesting);
m_SSU2Server->StartPeerTest (router, true);
excluded.insert (router->GetIdentHash ());
}
@ -635,7 +635,7 @@ namespace transport @@ -635,7 +635,7 @@ namespace transport
if (router)
{
if (i2p::context.GetStatusV6 () != eRouterStatusTesting)
i2p::context.SetStatusV6SSU2 (eRouterStatusTesting);
i2p::context.SetStatusV6 (eRouterStatusTesting);
m_SSU2Server->StartPeerTest (router, false);
excluded.insert (router->GetIdentHash ());
}

Loading…
Cancel
Save