diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index 1c8914e5..0cc91a95 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -225,6 +225,13 @@ 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) @@ -245,6 +252,12 @@ namespace i2p } } + void RouterContext::SetStatusSSU2 (RouterStatus status) + { + if (IsSSU2Only ()) + SetStatus (status); + } + void RouterContext::SetStatusV6 (RouterStatus status) { if (status != m_StatusV6) @@ -264,6 +277,12 @@ namespace i2p } } + void RouterContext::SetStatusV6SSU2 (RouterStatus status) + { + if (IsSSU2Only ()) + SetStatusV6 (status); + } + void RouterContext::UpdatePort (int port) { bool updated = false; @@ -568,7 +587,8 @@ namespace i2p // delete previous introducers auto& addresses = m_RouterInfo.GetAddresses (); for (auto& addr : addresses) - if (addr->ssu && !addr->IsSSU2 () && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ()))) + if (addr->ssu && (!addr->IsSSU2 () || IsSSU2Only ()) && + ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ()))) { addr->published = false; addr->caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer @@ -598,9 +618,13 @@ namespace i2p } uint16_t port = 0; // delete previous introducers + bool isSSU2Published = IsSSU2Only (); // TODO + if (isSSU2Published) + i2p::config::GetOption ("ssu2.published", isSSU2Published); auto& addresses = m_RouterInfo.GetAddresses (); for (auto& addr : addresses) - if (addr->ssu && !addr->IsSSU2 () && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ()))) + if (addr->ssu && (!addr->IsSSU2 () || isSSU2Published) && + ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ()))) { addr->published = true; addr->caps |= i2p::data::RouterInfo::eSSUIntroducer; diff --git a/libi2pd/RouterContext.h b/libi2pd/RouterContext.h index eb5db38f..7a878c7d 100644 --- a/libi2pd/RouterContext.h +++ b/libi2pd/RouterContext.h @@ -103,10 +103,12 @@ 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_Status = eRouterStatusError; m_Error = error; }; RouterStatus GetStatusV6 () const { return m_StatusV6; }; void SetStatusV6 (RouterStatus status); + void SetStatusV6SSU2 (RouterStatus status); int GetNetID () const { return m_NetID; }; void SetNetID (int netID) { m_NetID = netID; }; bool DecryptTunnelBuildRecord (const uint8_t * encrypted, uint8_t * data); @@ -173,6 +175,7 @@ namespace garlic void UpdateRouterInfo (); void NewNTCP2Keys (); void NewSSU2Keys (); + bool IsSSU2Only () const; // SSU2 and no SSU bool Load (); void SaveKeys (); diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 7bbee4c4..401c6768 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -1691,6 +1691,13 @@ namespace transport it->second.first->m_State = eSSU2SessionStatePeerTest; it->second.first->SendPeerTest (6, buf + offset, len - offset, addr->i); } + else + { + if (m_Address->IsV4 () && i2p::context.GetStatus () == eRouterStatusTesting) + i2p::context.SetStatusSSU2 (eRouterStatusFirewalled); + if (m_Address->IsV6 () && i2p::context.GetStatusV6 () == eRouterStatusTesting) + i2p::context.SetStatusV6SSU2 (eRouterStatusFirewalled); + } } else { @@ -1737,6 +1744,10 @@ namespace transport break; case 7: // Alice from Charlie 2 m_Server.RemoveSession (htobe64 (((uint64_t)nonce << 32) | nonce)); + if (m_Address->IsV6 ()) + i2p::context.SetStatusV6 (eRouterStatusOK); // set status OK for ipv6 even if from SSU2 + else + i2p::context.SetStatusSSU2 (eRouterStatusOK); break; default: LogPrint (eLogWarning, "SSU2: PeerTest unexpected msg num ", buf[0]);