\r\n";
for (auto & it : i2p::tunnel::tunnels.GetOutboundTunnels ()) {
s << "
";
- it->Print(s);
- if(it->LatencyIsKnown())
+ s << it->GetTunnelID () << ":me ⇒";
+ // for each tunnel hop if not zero-hop
+ if (it->GetNumHops ())
+ {
+ it->VisitTunnelHops(
+ [&s](std::shared_ptr hopIdent)
+ {
+ s << " " << i2p::data::GetIdentHashAbbreviation (hopIdent->GetIdentHash ()) << " ⇒";
+ }
+ );
+ }
+ if (it->LatencyIsKnown())
s << " ( " << it->GetMeanLatency() << tr("ms") << " )";
ShowTunnelDetails(s, it->GetState (), (it->GetTunnelPool () == ExplPool), it->GetNumSentBytes ());
s << "
\r\n";
@@ -714,7 +755,7 @@ namespace http {
void ShowTransitTunnels (std::stringstream& s)
{
- if(i2p::tunnel::tunnels.CountTransitTunnels())
+ if (i2p::tunnel::tunnels.CountTransitTunnels())
{
s << "
\r\n";
for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ())
@@ -848,7 +889,7 @@ namespace http {
return;
}
- if(sam->GetSessions ().size ())
+ if (sam->GetSessions ().size ())
{
s << "
" << tr("SAM sessions") << ":\r\n
\r\n";
for (auto& it: sam->GetSessions ())
@@ -1065,6 +1106,7 @@ namespace http {
SendReply(res, content);
return;
}
+
bool strictheaders;
i2p::config::GetOption("http.strictheaders", strictheaders);
if (strictheaders)
@@ -1087,6 +1129,7 @@ namespace http {
return;
}
}
+
// HTML head start
ShowPageHead (s);
if (req.uri.find("page=") != std::string::npos) {
@@ -1207,7 +1250,7 @@ namespace http {
else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL)
{
i2p::context.SetAcceptsTunnels (true);
-#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
+#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
Daemon.gracefulShutdownInterval = 0;
#elif defined(WIN32_APP)
i2p::win32::StopGracefulShutdown ();
@@ -1239,7 +1282,7 @@ namespace http {
{
if (dest)
{
- if(dest->DeleteStream (streamID))
+ if (dest->DeleteStream (streamID))
s << "" << tr("SUCCESS") << ": " << tr("Stream closed") << "
\r\n
\r\n";
else
s << "" << tr("ERROR") << ": " << tr("Stream not found or already was closed") << "
\r\n
\r\n";
@@ -1445,7 +1488,7 @@ namespace http {
CreateConnection(newSocket);
else
{
- if(newSocket) newSocket->close();
+ if (newSocket) newSocket->close();
LogPrint(eLogError, "HTTP Server: Error handling accept: ", ecode.message());
}
Accept ();
diff --git a/libi2pd/Tunnel.cpp b/libi2pd/Tunnel.cpp
index 725ff7c9..f5812a70 100644
--- a/libi2pd/Tunnel.cpp
+++ b/libi2pd/Tunnel.cpp
@@ -235,15 +235,11 @@ namespace tunnel
m_State = state;
}
-
- void Tunnel::PrintHops (std::stringstream& s) const
+ void Tunnel::VisitTunnelHops(TunnelHopVisitor v)
{
- // hops are in inverted order, we must print in direct order
+ // hops are in inverted order, we must return in direct order
for (auto it = m_Hops.rbegin (); it != m_Hops.rend (); it++)
- {
- s << " ⇒ ";
- s << i2p::data::GetIdentHashAbbreviation ((*it).ident->GetIdentHash ());
- }
+ v((*it).ident);
}
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr&& msg)
@@ -254,12 +250,6 @@ namespace tunnel
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
}
- void InboundTunnel::Print (std::stringstream& s) const
- {
- PrintHops (s);
- s << " ⇒ " << GetTunnelID () << ":me";
- }
-
ZeroHopsInboundTunnel::ZeroHopsInboundTunnel ():
InboundTunnel (std::make_shared ()),
m_NumReceivedBytes (0)
@@ -276,11 +266,6 @@ namespace tunnel
}
}
- void ZeroHopsInboundTunnel::Print (std::stringstream& s) const
- {
- s << " ⇒ " << GetTunnelID () << ":me";
- }
-
void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr msg)
{
TunnelMessageBlock block;
@@ -315,13 +300,6 @@ namespace tunnel
LogPrint (eLogError, "Tunnel: Incoming message for outbound tunnel ", GetTunnelID ());
}
- void OutboundTunnel::Print (std::stringstream& s) const
- {
- s << GetTunnelID () << ":me";
- PrintHops (s);
- s << " ⇒ ";
- }
-
ZeroHopsOutboundTunnel::ZeroHopsOutboundTunnel ():
OutboundTunnel (std::make_shared ()),
m_NumSentBytes (0)
@@ -351,11 +329,6 @@ namespace tunnel
}
}
- void ZeroHopsOutboundTunnel::Print (std::stringstream& s) const
- {
- s << GetTunnelID () << ":me ⇒ ";
- }
-
Tunnels tunnels;
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr),
diff --git a/libi2pd/Tunnel.h b/libi2pd/Tunnel.h
index 2414aff9..bc95601e 100644
--- a/libi2pd/Tunnel.h
+++ b/libi2pd/Tunnel.h
@@ -44,6 +44,9 @@ namespace tunnel
const size_t I2NP_TUNNEL_MESSAGE_SIZE = TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + 34; // reserved for alignment and NTCP 16 + 6 + 12
const size_t I2NP_TUNNEL_ENPOINT_MESSAGE_SIZE = 2*TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE + 28; // reserved for alignment and NTCP 16 + 6 + 6
+ /** function for visiting a hops stored in a tunnel */
+ typedef std::function)> TunnelHopVisitor;
+
enum TunnelState
{
eTunnelStatePending,
@@ -91,8 +94,6 @@ namespace tunnel
bool HandleTunnelBuildResponse (uint8_t * msg, size_t len);
- virtual void Print (std::stringstream&) const {};
-
// implements TunnelBase
void SendTunnelDataMsg (std::shared_ptr msg);
void EncryptTunnelMsg (std::shared_ptr in, std::shared_ptr out);
@@ -107,9 +108,8 @@ namespace tunnel
bool LatencyIsKnown() const { return m_Latency > 0; }
bool IsSlow () const { return LatencyIsKnown() && (int)m_Latency > HIGH_LATENCY_PER_HOP*GetNumHops (); }
- protected:
-
- void PrintHops (std::stringstream& s) const;
+ /** visit all hops we currently store */
+ void VisitTunnelHops(TunnelHopVisitor v);
private:
@@ -134,7 +134,6 @@ namespace tunnel
virtual void SendTunnelDataMsg (const std::vector& msgs); // multiple messages
const i2p::data::IdentHash& GetEndpointIdentHash () const { return m_EndpointIdentHash; };
virtual size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
- void Print (std::stringstream& s) const;
// implements TunnelBase
void HandleTunnelDataMsg (std::shared_ptr&& tunnelMsg);
@@ -155,7 +154,6 @@ namespace tunnel
InboundTunnel (std::shared_ptr config): Tunnel (config), m_Endpoint (true) {};
void HandleTunnelDataMsg (std::shared_ptr&& msg);
virtual size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };
- void Print (std::stringstream& s) const;
bool IsInbound() const { return true; }
// override TunnelBase
@@ -172,7 +170,6 @@ namespace tunnel
ZeroHopsInboundTunnel ();
void SendTunnelDataMsg (std::shared_ptr msg);
- void Print (std::stringstream& s) const;
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };
private:
@@ -186,7 +183,6 @@ namespace tunnel
ZeroHopsOutboundTunnel ();
void SendTunnelDataMsg (const std::vector& msgs);
- void Print (std::stringstream& s) const;
size_t GetNumSentBytes () const { return m_NumSentBytes; };
private: