Browse Source

Merge pull request #1957 from Vort/peer_test

Separate test status from network status
pull/1958/head
orignal 1 year ago committed by GitHub
parent
commit
e170c39dfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      Win32/Win32App.cpp
  2. 9
      daemon/HTTPServer.cpp
  3. 31
      libi2pd/RouterContext.cpp
  4. 14
      libi2pd/RouterContext.h
  5. 4
      libi2pd/SSU2.cpp
  6. 41
      libi2pd/SSU2Session.cpp
  7. 2
      libi2pd/SSU2Session.h
  8. 12
      libi2pd/Transports.cpp

9
Win32/Win32App.cpp

@ -145,18 +145,19 @@ namespace win32
s << bytes << " Bytes\n"; s << bytes << " Bytes\n";
} }
static void ShowNetworkStatus (std::stringstream& s, RouterStatus status) static void ShowNetworkStatus (std::stringstream& s, RouterStatus status, bool testing)
{ {
switch (status) switch (status)
{ {
case eRouterStatusOK: s << "OK"; break; case eRouterStatusOK: s << "OK"; break;
case eRouterStatusTesting: s << "Test"; break;
case eRouterStatusFirewalled: s << "FW"; break; case eRouterStatusFirewalled: s << "FW"; break;
case eRouterStatusUnknown: s << "Unk"; break; case eRouterStatusUnknown: s << "Unk"; break;
case eRouterStatusProxy: s << "Proxy"; break; case eRouterStatusProxy: s << "Proxy"; break;
case eRouterStatusMesh: s << "Mesh"; break; case eRouterStatusMesh: s << "Mesh"; break;
default: s << "Unk"; default: s << "Unk";
}; };
if (testing)
s << " (Test)";
if (i2p::context.GetError () != eRouterErrorNone) if (i2p::context.GetError () != eRouterErrorNone)
{ {
switch (i2p::context.GetError ()) switch (i2p::context.GetError ())
@ -179,11 +180,11 @@ namespace win32
{ {
s << "\n"; s << "\n";
s << "Status: "; s << "Status: ";
ShowNetworkStatus (s, i2p::context.GetStatus ()); ShowNetworkStatus (s, i2p::context.GetStatus (), i2p::context.GetTesting ());
if (i2p::context.SupportsV6 ()) if (i2p::context.SupportsV6 ())
{ {
s << " / "; s << " / ";
ShowNetworkStatus (s, i2p::context.GetStatusV6 ()); ShowNetworkStatus (s, i2p::context.GetStatusV6 (), i2p::context.GetTestingV6 ());
} }
s << "; "; s << "; ";
s << "Success Rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() << "%\n"; s << "Success Rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() << "%\n";

9
daemon/HTTPServer.cpp

@ -222,18 +222,19 @@ namespace http {
s << "<b>" << tr("ERROR") << ":</b>&nbsp;" << string << "<br>\r\n"; s << "<b>" << tr("ERROR") << ":</b>&nbsp;" << string << "<br>\r\n";
} }
static void ShowNetworkStatus (std::stringstream& s, RouterStatus status, RouterError error) static void ShowNetworkStatus (std::stringstream& s, RouterStatus status, bool testing, RouterError error)
{ {
switch (status) switch (status)
{ {
case eRouterStatusOK: s << tr("OK"); break; case eRouterStatusOK: s << tr("OK"); break;
case eRouterStatusTesting: s << tr("Testing"); break;
case eRouterStatusFirewalled: s << tr("Firewalled"); break; case eRouterStatusFirewalled: s << tr("Firewalled"); break;
case eRouterStatusUnknown: s << tr("Unknown"); break; case eRouterStatusUnknown: s << tr("Unknown"); break;
case eRouterStatusProxy: s << tr("Proxy"); break; case eRouterStatusProxy: s << tr("Proxy"); break;
case eRouterStatusMesh: s << tr("Mesh"); break; case eRouterStatusMesh: s << tr("Mesh"); break;
default: s << tr("Unknown"); default: s << tr("Unknown");
} }
if (testing)
s << " (" << tr("Testing") << ")";
if (error != eRouterErrorNone) if (error != eRouterErrorNone)
{ {
switch (error) switch (error)
@ -264,12 +265,12 @@ namespace http {
ShowUptime(s, i2p::context.GetUptime ()); ShowUptime(s, i2p::context.GetUptime ());
s << "<br>\r\n"; s << "<br>\r\n";
s << "<b>" << tr("Network status") << ":</b> "; s << "<b>" << tr("Network status") << ":</b> ";
ShowNetworkStatus (s, i2p::context.GetStatus (), i2p::context.GetError ()); ShowNetworkStatus (s, i2p::context.GetStatus (), i2p::context.GetTesting(), i2p::context.GetError ());
s << "<br>\r\n"; s << "<br>\r\n";
if (i2p::context.SupportsV6 ()) if (i2p::context.SupportsV6 ())
{ {
s << "<b>" << tr("Network status v6") << ":</b> "; s << "<b>" << tr("Network status v6") << ":</b> ";
ShowNetworkStatus (s, i2p::context.GetStatusV6 (), i2p::context.GetErrorV6 ()); ShowNetworkStatus (s, i2p::context.GetStatusV6 (), i2p::context.GetTestingV6(), i2p::context.GetErrorV6 ());
s << "<br>\r\n"; s << "<br>\r\n";
} }
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY)) #if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))

31
libi2pd/RouterContext.cpp

@ -31,7 +31,8 @@ namespace i2p
RouterContext::RouterContext (): RouterContext::RouterContext ():
m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false), m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown), m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown),
m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone), m_NetID (I2PD_NET_ID), m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone),
m_Testing (false), m_TestingV6 (false), m_NetID (I2PD_NET_ID),
m_PublishReplyToken (0), m_IsHiddenMode (false) m_PublishReplyToken (0), m_IsHiddenMode (false)
{ {
} }
@ -277,8 +278,29 @@ namespace i2p
fk.write ((char *)m_SSU2Keys.get (), sizeof (SSU2PrivateKeys)); fk.write ((char *)m_SSU2Keys.get (), sizeof (SSU2PrivateKeys));
} }
void RouterContext::SetTesting (bool testing)
{
if (testing != m_Testing)
{
m_Testing = testing;
if (m_Testing)
m_Error = eRouterErrorNone;
}
}
void RouterContext::SetTestingV6 (bool testing)
{
if (testing != m_TestingV6)
{
m_TestingV6 = testing;
if (m_TestingV6)
m_ErrorV6 = eRouterErrorNone;
}
}
void RouterContext::SetStatus (RouterStatus status) void RouterContext::SetStatus (RouterStatus status)
{ {
SetTesting (false);
if (status != m_Status) if (status != m_Status)
{ {
m_Status = status; m_Status = status;
@ -290,9 +312,6 @@ namespace i2p
case eRouterStatusFirewalled: case eRouterStatusFirewalled:
SetUnreachable (true, false); // ipv4 SetUnreachable (true, false); // ipv4
break; break;
case eRouterStatusTesting:
m_Error = eRouterErrorNone;
break;
default: default:
; ;
} }
@ -301,6 +320,7 @@ namespace i2p
void RouterContext::SetStatusV6 (RouterStatus status) void RouterContext::SetStatusV6 (RouterStatus status)
{ {
SetTestingV6 (false);
if (status != m_StatusV6) if (status != m_StatusV6)
{ {
m_StatusV6 = status; m_StatusV6 = status;
@ -312,9 +332,6 @@ namespace i2p
case eRouterStatusFirewalled: case eRouterStatusFirewalled:
SetUnreachable (false, true); // ipv6 SetUnreachable (false, true); // ipv6
break; break;
case eRouterStatusTesting:
m_ErrorV6 = eRouterErrorNone;
break;
default: default:
; ;
} }

14
libi2pd/RouterContext.h

@ -42,11 +42,10 @@ namespace garlic
enum RouterStatus enum RouterStatus
{ {
eRouterStatusOK = 0, eRouterStatusOK = 0,
eRouterStatusTesting = 1, eRouterStatusFirewalled = 1,
eRouterStatusFirewalled = 2, eRouterStatusUnknown = 2,
eRouterStatusUnknown = 3, eRouterStatusProxy = 3,
eRouterStatusProxy = 4, eRouterStatusMesh = 4
eRouterStatusMesh = 5
}; };
enum RouterError enum RouterError
@ -121,10 +120,14 @@ namespace garlic
uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; }; uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
uint64_t GetBandwidthLimit () const { return m_BandwidthLimit; }; uint64_t GetBandwidthLimit () const { return m_BandwidthLimit; };
uint64_t GetTransitBandwidthLimit () const { return (m_BandwidthLimit*m_ShareRatio)/100LL; }; uint64_t GetTransitBandwidthLimit () const { return (m_BandwidthLimit*m_ShareRatio)/100LL; };
bool GetTesting () const { return m_Testing; };
void SetTesting (bool testing);
RouterStatus GetStatus () const { return m_Status; }; RouterStatus GetStatus () const { return m_Status; };
void SetStatus (RouterStatus status); void SetStatus (RouterStatus status);
RouterError GetError () const { return m_Error; }; RouterError GetError () const { return m_Error; };
void SetError (RouterError error) { m_Error = error; }; void SetError (RouterError error) { m_Error = error; };
bool GetTestingV6 () const { return m_TestingV6; };
void SetTestingV6 (bool testing);
RouterStatus GetStatusV6 () const { return m_StatusV6; }; RouterStatus GetStatusV6 () const { return m_StatusV6; };
void SetStatusV6 (RouterStatus status); void SetStatusV6 (RouterStatus status);
RouterError GetErrorV6 () const { return m_ErrorV6; }; RouterError GetErrorV6 () const { return m_ErrorV6; };
@ -231,6 +234,7 @@ namespace garlic
int m_ShareRatio; int m_ShareRatio;
RouterStatus m_Status, m_StatusV6; RouterStatus m_Status, m_StatusV6;
RouterError m_Error, m_ErrorV6; RouterError m_Error, m_ErrorV6;
bool m_Testing, m_TestingV6;
int m_NetID; int m_NetID;
std::unique_ptr<NTCP2PrivateKeys> m_NTCP2Keys; std::unique_ptr<NTCP2PrivateKeys> m_NTCP2Keys;
std::unique_ptr<SSU2PrivateKeys> m_SSU2Keys; std::unique_ptr<SSU2PrivateKeys> m_SSU2Keys;

4
libi2pd/SSU2.cpp

@ -1140,7 +1140,7 @@ namespace transport
// timeout expired // timeout expired
if (v4) if (v4)
{ {
if (i2p::context.GetStatus () == eRouterStatusTesting) if (i2p::context.GetTesting ())
{ {
// we still don't know if we need introducers // we still don't know if we need introducers
ScheduleIntroducersUpdateTimer (); ScheduleIntroducersUpdateTimer ();
@ -1163,7 +1163,7 @@ namespace transport
} }
else else
{ {
if (i2p::context.GetStatusV6 () == eRouterStatusTesting) if (i2p::context.GetTestingV6 ())
{ {
// we still don't know if we need introducers // we still don't know if we need introducers
ScheduleIntroducersUpdateTimerV6 (); ScheduleIntroducersUpdateTimerV6 ();

41
libi2pd/SSU2Session.cpp

@ -1651,8 +1651,8 @@ namespace transport
break; break;
case eSSU2SessionStateSessionCreatedReceived: case eSSU2SessionStateSessionCreatedReceived:
case eSSU2SessionStateTokenReceived: case eSSU2SessionStateTokenReceived:
if ((m_RemoteEndpoint.address ().is_v4 () && i2p::context.GetStatus () == eRouterStatusTesting) || if ((m_RemoteEndpoint.address ().is_v4 () && i2p::context.GetTesting ()) ||
(m_RemoteEndpoint.address ().is_v6 () && i2p::context.GetStatusV6 () == eRouterStatusTesting)) (m_RemoteEndpoint.address ().is_v6 () && i2p::context.GetTestingV6 ()))
{ {
if (m_Server.IsSyncClockFromPeers ()) if (m_Server.IsSyncClockFromPeers ())
{ {
@ -1750,14 +1750,14 @@ namespace transport
LogPrint (eLogInfo, "SSU2: Our port ", ep.port (), " received from ", m_RemoteEndpoint, " is different from ", m_Server.GetPort (isV4)); LogPrint (eLogInfo, "SSU2: Our port ", ep.port (), " received from ", m_RemoteEndpoint, " is different from ", m_Server.GetPort (isV4));
if (isV4) if (isV4)
{ {
if (i2p::context.GetStatus () == eRouterStatusTesting) if (i2p::context.GetTesting ())
i2p::context.SetError (eRouterErrorSymmetricNAT); i2p::context.SetError (eRouterErrorSymmetricNAT);
else if (m_State == eSSU2SessionStatePeerTest) else if (m_State == eSSU2SessionStatePeerTest)
i2p::context.SetError (eRouterErrorFullConeNAT); i2p::context.SetError (eRouterErrorFullConeNAT);
} }
else else
{ {
if (i2p::context.GetStatusV6 () == eRouterStatusTesting) if (i2p::context.GetTestingV6 ())
i2p::context.SetErrorV6 (eRouterErrorSymmetricNAT); i2p::context.SetErrorV6 (eRouterErrorSymmetricNAT);
else if (m_State == eSSU2SessionStatePeerTest) else if (m_State == eSSU2SessionStatePeerTest)
i2p::context.SetErrorV6 (eRouterErrorFullConeNAT); i2p::context.SetErrorV6 (eRouterErrorFullConeNAT);
@ -2230,7 +2230,7 @@ namespace transport
if (buf[1] == eSSU2PeerTestCodeAccept) if (buf[1] == eSSU2PeerTestCodeAccept)
{ {
if (GetRouterStatus () == eRouterStatusUnknown) if (GetRouterStatus () == eRouterStatusUnknown)
SetRouterStatus (eRouterStatusTesting); SetTestingState (true);
auto r = i2p::data::netdb.FindRouter (buf + 3); // find Charlie auto r = i2p::data::netdb.FindRouter (buf + 3); // find Charlie
if (r && it->second.first) if (r && it->second.first)
{ {
@ -2256,7 +2256,10 @@ namespace transport
} }
else else
{ {
if (GetRouterStatus () == eRouterStatusTesting) if (GetTestingState ())
{
SetTestingState (false);
if (GetRouterStatus () != eRouterStatusFirewalled)
{ {
SetRouterStatus (eRouterStatusFirewalled); SetRouterStatus (eRouterStatusFirewalled);
if (m_Address->IsV4 ()) if (m_Address->IsV4 ())
@ -2265,6 +2268,7 @@ namespace transport
m_Server.RescheduleIntroducersUpdateTimerV6 (); m_Server.RescheduleIntroducersUpdateTimerV6 ();
} }
} }
}
LogPrint (eLogDebug, "SSU2: Peer test 4 received from ", i2p::data::GetIdentHashAbbreviation (GetRemoteIdentity ()->GetIdentHash ()), LogPrint (eLogDebug, "SSU2: Peer test 4 received from ", i2p::data::GetIdentHashAbbreviation (GetRemoteIdentity ()->GetIdentHash ()),
" with information about ", i2p::data::GetIdentHashAbbreviation (i2p::data::IdentHash (buf + 3))); " with information about ", i2p::data::GetIdentHashAbbreviation (i2p::data::IdentHash (buf + 3)));
} }
@ -2291,7 +2295,7 @@ namespace transport
{ {
LogPrint (eLogInfo, "SSU2: Peer test 4 error code ", (int)buf[1], " from ", LogPrint (eLogInfo, "SSU2: Peer test 4 error code ", (int)buf[1], " from ",
i2p::data::GetIdentHashAbbreviation (buf[1] < 64 ? GetRemoteIdentity ()->GetIdentHash () : i2p::data::IdentHash (buf + 3))); i2p::data::GetIdentHashAbbreviation (buf[1] < 64 ? GetRemoteIdentity ()->GetIdentHash () : i2p::data::IdentHash (buf + 3)));
if (GetRouterStatus () == eRouterStatusTesting) if (GetTestingState ())
SetRouterStatus (eRouterStatusUnknown); SetRouterStatus (eRouterStatusUnknown);
it->second.first->Done (); it->second.first->Done ();
} }
@ -2445,6 +2449,29 @@ namespace transport
} }
} }
bool SSU2Session::GetTestingState () const
{
if (m_Address)
{
if (m_Address->IsV4 ())
return i2p::context.GetTesting ();
if (m_Address->IsV6 ())
return i2p::context.GetTestingV6 ();
}
return false;
}
void SSU2Session::SetTestingState (bool testing) const
{
if (m_Address)
{
if (m_Address->IsV4 ())
i2p::context.SetTesting (testing);
else if (m_Address->IsV6 ())
i2p::context.SetTestingV6 (testing);
}
}
size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep) size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep)
{ {
if (len < 9) return 0; if (len < 9) return 0;

2
libi2pd/SSU2Session.h

@ -308,6 +308,8 @@ namespace transport
void AdjustMaxPayloadSize (); void AdjustMaxPayloadSize ();
RouterStatus GetRouterStatus () const; RouterStatus GetRouterStatus () const;
void SetRouterStatus (RouterStatus status) const; void SetRouterStatus (RouterStatus status) const;
bool GetTestingState () const;
void SetTestingState(bool testing) const;
std::shared_ptr<const i2p::data::RouterInfo> ExtractRouterInfo (const uint8_t * buf, size_t size); std::shared_ptr<const i2p::data::RouterInfo> ExtractRouterInfo (const uint8_t * buf, size_t size);
void CreateNonce (uint64_t seqn, uint8_t * nonce); void CreateNonce (uint64_t seqn, uint8_t * nonce);
bool UpdateReceivePacketNum (uint32_t packetNum); // for Ack, returns false if duplicate bool UpdateReceivePacketNum (uint32_t packetNum); // for Ack, returns false if duplicate

12
libi2pd/Transports.cpp

@ -650,8 +650,8 @@ namespace transport
auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (true, excluded); // v4 auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (true, excluded); // v4
if (router) if (router)
{ {
if (i2p::context.GetStatus () != eRouterStatusTesting) if (!i2p::context.GetTesting ())
i2p::context.SetStatus (eRouterStatusTesting); i2p::context.SetTesting (true);
m_SSU2Server->StartPeerTest (router, true); m_SSU2Server->StartPeerTest (router, true);
excluded.insert (router->GetIdentHash ()); excluded.insert (router->GetIdentHash ());
} }
@ -669,8 +669,8 @@ namespace transport
auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (false, excluded); // v6 auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (false, excluded); // v6
if (router) if (router)
{ {
if (i2p::context.GetStatusV6 () != eRouterStatusTesting) if (!i2p::context.GetTestingV6 ())
i2p::context.SetStatusV6 (eRouterStatusTesting); i2p::context.SetTestingV6 (true);
m_SSU2Server->StartPeerTest (router, false); m_SSU2Server->StartPeerTest (router, false);
excluded.insert (router->GetIdentHash ()); excluded.insert (router->GetIdentHash ());
} }
@ -832,8 +832,8 @@ namespace transport
++it; ++it;
} }
} }
bool ipv4Testing = i2p::context.GetStatus () == eRouterStatusTesting; bool ipv4Testing = i2p::context.GetTesting ();
bool ipv6Testing = i2p::context.GetStatusV6 () == eRouterStatusTesting; bool ipv6Testing = i2p::context.GetTestingV6 ();
// if still testing, repeat peer test // if still testing, repeat peer test
if (ipv4Testing || ipv6Testing) if (ipv4Testing || ipv6Testing)
PeerTest (ipv4Testing, ipv6Testing); PeerTest (ipv4Testing, ipv6Testing);

Loading…
Cancel
Save