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. 51
      libi2pd/SSU2Session.cpp
  7. 2
      libi2pd/SSU2Session.h
  8. 12
      libi2pd/Transports.cpp

9
Win32/Win32App.cpp

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

9
daemon/HTTPServer.cpp

@ -222,18 +222,19 @@ namespace http { @@ -222,18 +222,19 @@ namespace http {
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)
{
case eRouterStatusOK: s << tr("OK"); break;
case eRouterStatusTesting: s << tr("Testing"); break;
case eRouterStatusFirewalled: s << tr("Firewalled"); break;
case eRouterStatusUnknown: s << tr("Unknown"); break;
case eRouterStatusProxy: s << tr("Proxy"); break;
case eRouterStatusMesh: s << tr("Mesh"); break;
default: s << tr("Unknown");
}
if (testing)
s << " (" << tr("Testing") << ")";
if (error != eRouterErrorNone)
{
switch (error)
@ -264,12 +265,12 @@ namespace http { @@ -264,12 +265,12 @@ namespace http {
ShowUptime(s, i2p::context.GetUptime ());
s << "<br>\r\n";
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";
if (i2p::context.SupportsV6 ())
{
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";
}
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))

31
libi2pd/RouterContext.cpp

@ -31,7 +31,8 @@ namespace i2p @@ -31,7 +31,8 @@ namespace i2p
RouterContext::RouterContext ():
m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
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)
{
}
@ -277,8 +278,29 @@ namespace i2p @@ -277,8 +278,29 @@ namespace i2p
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)
{
SetTesting (false);
if (status != m_Status)
{
m_Status = status;
@ -290,9 +312,6 @@ namespace i2p @@ -290,9 +312,6 @@ namespace i2p
case eRouterStatusFirewalled:
SetUnreachable (true, false); // ipv4
break;
case eRouterStatusTesting:
m_Error = eRouterErrorNone;
break;
default:
;
}
@ -301,6 +320,7 @@ namespace i2p @@ -301,6 +320,7 @@ namespace i2p
void RouterContext::SetStatusV6 (RouterStatus status)
{
SetTestingV6 (false);
if (status != m_StatusV6)
{
m_StatusV6 = status;
@ -312,9 +332,6 @@ namespace i2p @@ -312,9 +332,6 @@ namespace i2p
case eRouterStatusFirewalled:
SetUnreachable (false, true); // ipv6
break;
case eRouterStatusTesting:
m_ErrorV6 = eRouterErrorNone;
break;
default:
;
}

14
libi2pd/RouterContext.h

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

4
libi2pd/SSU2.cpp

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

51
libi2pd/SSU2Session.cpp

@ -1651,8 +1651,8 @@ namespace transport @@ -1651,8 +1651,8 @@ namespace transport
break;
case eSSU2SessionStateSessionCreatedReceived:
case eSSU2SessionStateTokenReceived:
if ((m_RemoteEndpoint.address ().is_v4 () && i2p::context.GetStatus () == eRouterStatusTesting) ||
(m_RemoteEndpoint.address ().is_v6 () && i2p::context.GetStatusV6 () == eRouterStatusTesting))
if ((m_RemoteEndpoint.address ().is_v4 () && i2p::context.GetTesting ()) ||
(m_RemoteEndpoint.address ().is_v6 () && i2p::context.GetTestingV6 ()))
{
if (m_Server.IsSyncClockFromPeers ())
{
@ -1750,14 +1750,14 @@ namespace transport @@ -1750,14 +1750,14 @@ namespace transport
LogPrint (eLogInfo, "SSU2: Our port ", ep.port (), " received from ", m_RemoteEndpoint, " is different from ", m_Server.GetPort (isV4));
if (isV4)
{
if (i2p::context.GetStatus () == eRouterStatusTesting)
if (i2p::context.GetTesting ())
i2p::context.SetError (eRouterErrorSymmetricNAT);
else if (m_State == eSSU2SessionStatePeerTest)
i2p::context.SetError (eRouterErrorFullConeNAT);
}
else
{
if (i2p::context.GetStatusV6 () == eRouterStatusTesting)
if (i2p::context.GetTestingV6 ())
i2p::context.SetErrorV6 (eRouterErrorSymmetricNAT);
else if (m_State == eSSU2SessionStatePeerTest)
i2p::context.SetErrorV6 (eRouterErrorFullConeNAT);
@ -2230,7 +2230,7 @@ namespace transport @@ -2230,7 +2230,7 @@ namespace transport
if (buf[1] == eSSU2PeerTestCodeAccept)
{
if (GetRouterStatus () == eRouterStatusUnknown)
SetRouterStatus (eRouterStatusTesting);
SetTestingState (true);
auto r = i2p::data::netdb.FindRouter (buf + 3); // find Charlie
if (r && it->second.first)
{
@ -2256,13 +2256,17 @@ namespace transport @@ -2256,13 +2256,17 @@ namespace transport
}
else
{
if (GetRouterStatus () == eRouterStatusTesting)
if (GetTestingState ())
{
SetRouterStatus (eRouterStatusFirewalled);
if (m_Address->IsV4 ())
m_Server.RescheduleIntroducersUpdateTimer ();
else
m_Server.RescheduleIntroducersUpdateTimerV6 ();
SetTestingState (false);
if (GetRouterStatus () != eRouterStatusFirewalled)
{
SetRouterStatus (eRouterStatusFirewalled);
if (m_Address->IsV4 ())
m_Server.RescheduleIntroducersUpdateTimer ();
else
m_Server.RescheduleIntroducersUpdateTimerV6 ();
}
}
}
LogPrint (eLogDebug, "SSU2: Peer test 4 received from ", i2p::data::GetIdentHashAbbreviation (GetRemoteIdentity ()->GetIdentHash ()),
@ -2291,7 +2295,7 @@ namespace transport @@ -2291,7 +2295,7 @@ namespace transport
{
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)));
if (GetRouterStatus () == eRouterStatusTesting)
if (GetTestingState ())
SetRouterStatus (eRouterStatusUnknown);
it->second.first->Done ();
}
@ -2445,6 +2449,29 @@ namespace transport @@ -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)
{
if (len < 9) return 0;

2
libi2pd/SSU2Session.h

@ -308,6 +308,8 @@ namespace transport @@ -308,6 +308,8 @@ namespace transport
void AdjustMaxPayloadSize ();
RouterStatus GetRouterStatus () 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);
void CreateNonce (uint64_t seqn, uint8_t * nonce);
bool UpdateReceivePacketNum (uint32_t packetNum); // for Ack, returns false if duplicate

12
libi2pd/Transports.cpp

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

Loading…
Cancel
Save