Skip to content

Commit

Permalink
show tunlel creation success ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Feb 28, 2015
1 parent 3977cec commit 6f9d8ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ namespace util
default: s << "Unknown";
}
s << "<br>";
s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>";
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br><br>";
s << "<b>Our external address:</b>" << "<br>" ;
for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
Expand Down
7 changes: 6 additions & 1 deletion Tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ namespace tunnel

Tunnels tunnels;

Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr)
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr),
m_NumSuccesiveTunnelCreations (0), m_NumFailedTunnelCreations (0)
{
}

Expand Down Expand Up @@ -488,20 +489,24 @@ namespace tunnel
{
LogPrint ("Pending tunnel build request ", it->first, " timeout. Deleted");
it = pendingTunnels.erase (it);
m_NumFailedTunnelCreations++;
}
else
it++;
break;
case eTunnelStateBuildFailed:
LogPrint ("Pending tunnel build request ", it->first, " failed. Deleted");
it = pendingTunnels.erase (it);
m_NumFailedTunnelCreations++;
break;
case eTunnelStateBuildReplyReceived:
// intermediate state, will be either established of build failed
it++;
break;
default:
// success
it = pendingTunnels.erase (it);
m_NumSuccesiveTunnelCreations++;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,21 @@ namespace tunnel
std::shared_ptr<TunnelPool> m_ExploratoryPool;
i2p::util::Queue<I2NPMessage> m_Queue;

// some stats
int m_NumSuccesiveTunnelCreations, m_NumFailedTunnelCreations;

public:

// for HTTP only
const decltype(m_OutboundTunnels)& GetOutboundTunnels () const { return m_OutboundTunnels; };
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
int GetQueueSize () { return m_Queue.GetSize (); };
int GetTunnelCreationSuccessRate () const // in percents
{
int totalNum = m_NumSuccesiveTunnelCreations + m_NumFailedTunnelCreations;
return totalNum ? m_NumSuccesiveTunnelCreations*100/totalNum : 0;
}
};

extern Tunnels tunnels;
Expand Down

0 comments on commit 6f9d8ed

Please sign in to comment.