Browse Source

rename and refactor

pull/1865/head
weko 2 years ago
parent
commit
7df2ed6114
  1. 8
      daemon/HTTPServer.cpp
  2. 2
      libi2pd/Config.cpp
  3. 5
      libi2pd/Tunnel.cpp
  4. 16
      libi2pd/Tunnel.h

8
daemon/HTTPServer.cpp

@ -289,10 +289,10 @@ namespace http {
if (family.length () > 0) if (family.length () > 0)
s << "<b>"<< tr("Family") << ":</b> " << family << "<br>\r\n"; s << "<b>"<< tr("Family") << ":</b> " << family << "<br>\r\n";
s << "<b>" << tr("Tunnel creation success rate") << ":</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>\r\n"; s << "<b>" << tr("Tunnel creation success rate") << ":</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>\r\n";
bool isOldTCSR; bool isTotalTCSR;
i2p::config::GetOption("http.old_tcsr", isOldTCSR); i2p::config::GetOption("http.showTotalTCSR", isTotalTCSR);
if (isOldTCSR) { if (isTotalTCSR) {
s << "<b>" << tr("Tunnel creation success rate (old algorithm)") << ":</b> " << i2p::tunnel::tunnels.OldGetTunnelCreationSuccessRate() << "%<br/>\r\n"; s << "<b>" << tr("Total tunnel creation success rate") << ":</b> " << i2p::tunnel::tunnels.GetTotalTunnelCreationSuccessRate() << "%<br/>\r\n";
} }
s << "<b>" << tr("Received") << ":</b> "; s << "<b>" << tr("Received") << ":</b> ";
ShowTraffic (s, i2p::transport::transports.GetTotalReceivedBytes ()); ShowTraffic (s, i2p::transport::transports.GetTotalReceivedBytes ());

2
libi2pd/Config.cpp

@ -95,7 +95,7 @@ namespace config {
("http.hostname", value<std::string>()->default_value("localhost"), "Expected hostname for WebUI") ("http.hostname", value<std::string>()->default_value("localhost"), "Expected hostname for WebUI")
("http.webroot", value<std::string>()->default_value("/"), "WebUI root path (default: / )") ("http.webroot", value<std::string>()->default_value("/"), "WebUI root path (default: / )")
("http.lang", value<std::string>()->default_value("english"), "WebUI language (default: english )") ("http.lang", value<std::string>()->default_value("english"), "WebUI language (default: english )")
("http.old_tcsr", value<bool>()->default_value(false), "Show TCSR with old algorithm (default: false)") ("http.showTotalTCSR", value<bool>()->default_value(false), "Show additional value with total TCSR since router's start (default: false)")
; ;
options_description httpproxy("HTTP Proxy options"); options_description httpproxy("HTTP Proxy options");

5
libi2pd/Tunnel.cpp

@ -333,7 +333,7 @@ namespace tunnel
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr), Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr),
m_TunnelCreationSuccessRate (TCSR_START_VALUE), m_TunnelCreationAttemptsNum(0), m_TunnelCreationSuccessRate (TCSR_START_VALUE), m_TunnelCreationAttemptsNum(0),
m_OldNumSuccesiveTunnelCreations (0), m_OldNumFailedTunnelCreations (0) { m_TotalNumSuccesiveTunnelCreations (0), m_TotalNumFailedTunnelCreations (0) { // for normal avarage
} }
Tunnels::~Tunnels () Tunnels::~Tunnels ()
@ -635,7 +635,6 @@ namespace tunnel
// delete // delete
it = pendingTunnels.erase (it); it = pendingTunnels.erase (it);
FailedTunnelCreation(); FailedTunnelCreation();
m_OldNumFailedTunnelCreations++;
} }
else else
++it; ++it;
@ -644,7 +643,6 @@ namespace tunnel
LogPrint (eLogDebug, "Tunnel: Pending build request ", it->first, " failed, deleted"); LogPrint (eLogDebug, "Tunnel: Pending build request ", it->first, " failed, deleted");
it = pendingTunnels.erase (it); it = pendingTunnels.erase (it);
FailedTunnelCreation(); FailedTunnelCreation();
m_OldNumFailedTunnelCreations++;
break; break;
case eTunnelStateBuildReplyReceived: case eTunnelStateBuildReplyReceived:
// intermediate state, will be either established of build failed // intermediate state, will be either established of build failed
@ -654,7 +652,6 @@ namespace tunnel
// success // success
it = pendingTunnels.erase (it); it = pendingTunnels.erase (it);
SuccesiveTunnelCreation(); SuccesiveTunnelCreation();
m_OldNumSuccesiveTunnelCreations++;
} }
} }
} }

16
libi2pd/Tunnel.h

@ -269,17 +269,21 @@ namespace tunnel
i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue; i2p::util::Queue<std::shared_ptr<I2NPMessage> > m_Queue;
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_ENPOINT_MESSAGE_SIZE> > m_I2NPTunnelEndpointMessagesMemoryPool; i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_ENPOINT_MESSAGE_SIZE> > m_I2NPTunnelEndpointMessagesMemoryPool;
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_MESSAGE_SIZE> > m_I2NPTunnelMessagesMemoryPool; i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_TUNNEL_MESSAGE_SIZE> > m_I2NPTunnelMessagesMemoryPool;
// some old stats // count of tunnels for total TCSR algorithm
int m_OldNumSuccesiveTunnelCreations, m_OldNumFailedTunnelCreations; int m_TotalNumSuccesiveTunnelCreations, m_TotalNumFailedTunnelCreations;
// Calculating of tunnel creation success rate // Calculating of tunnel creation success rate
// A modified version of the EWMA algorithm, where alpha is increased at the beginning to accelerate similarity
void SuccesiveTunnelCreation() { void SuccesiveTunnelCreation() {
// total TCSR
m_TotalNumSuccesiveTunnelCreations++;
// A modified version of the EWMA algorithm, where alpha is increased at the beginning to accelerate similarity
double alpha = TCSR_SMOOTHING_CONSTANT + (1 - TCSR_SMOOTHING_CONSTANT)/++m_TunnelCreationAttemptsNum; double alpha = TCSR_SMOOTHING_CONSTANT + (1 - TCSR_SMOOTHING_CONSTANT)/++m_TunnelCreationAttemptsNum;
m_TunnelCreationSuccessRate = alpha * 1 + (1 - alpha) * m_TunnelCreationSuccessRate; m_TunnelCreationSuccessRate = alpha * 1 + (1 - alpha) * m_TunnelCreationSuccessRate;
}; };
void FailedTunnelCreation() { void FailedTunnelCreation() {
m_TotalNumFailedTunnelCreations++;
double alpha = TCSR_SMOOTHING_CONSTANT + (1 - TCSR_SMOOTHING_CONSTANT)/++m_TunnelCreationAttemptsNum; double alpha = TCSR_SMOOTHING_CONSTANT + (1 - TCSR_SMOOTHING_CONSTANT)/++m_TunnelCreationAttemptsNum;
m_TunnelCreationSuccessRate = alpha * 0 + (1 - alpha) * m_TunnelCreationSuccessRate; m_TunnelCreationSuccessRate = alpha * 0 + (1 - alpha) * m_TunnelCreationSuccessRate;
}; };
@ -299,10 +303,10 @@ namespace tunnel
int GetQueueSize () { return m_Queue.GetSize (); }; int GetQueueSize () { return m_Queue.GetSize (); };
int GetTunnelCreationSuccessRate () const { return std::round(m_TunnelCreationSuccessRate * 100); } // in percents int GetTunnelCreationSuccessRate () const { return std::round(m_TunnelCreationSuccessRate * 100); } // in percents
int OldGetTunnelCreationSuccessRate () const // in percents int GetTotalTunnelCreationSuccessRate () const // in percents
{ {
int totalNum = m_OldNumSuccesiveTunnelCreations + m_OldNumFailedTunnelCreations; int totalNum = m_TotalNumSuccesiveTunnelCreations + m_TotalNumFailedTunnelCreations;
return totalNum ? m_OldNumSuccesiveTunnelCreations*100/totalNum : 0; return totalNum ? m_TotalNumSuccesiveTunnelCreations*100/totalNum : 0;
} }
}; };

Loading…
Cancel
Save