From 2a4d78d9bfbded34ec3384541ec6f4d28a78ed08 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 16 Jan 2016 15:36:26 -0500 Subject: [PATCH 01/13] wordwrapping (by sha-db) --- HTTPServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index f19abff4..3a16ff6f 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -368,7 +368,7 @@ namespace util s << ".header {font-size: 2.5em; text-align: center; margin: 1.5em 0; color: #894C84;}"; s << ".wrapper {margin: 0 auto; padding: 1em; max-width: 48em;}"; s << ".left {float: left; position: absolute;}"; - s << ".right {font-size: 1em; margin-left: 13em; float: left; max-width: 34em; overflow: auto;}"; + s << ".right {font-size: 1em; margin-left: 13em; float: left; max-width: 34em; word-break: break-all;}"; s << ".established_tunnel {color: #56b734;}"; s << ".expiring_tunnel {color: #d3ae3f;}"; s << ".failed_tunnel {color: #d33f3f;}"; From 0ca3fb5af05ebac35068111a0df37991b8eff9ea Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 16 Jan 2016 15:36:30 -0500 Subject: [PATCH 02/13] specify and check netId --- NetDb.cpp | 19 +++++++++++-------- RouterContext.cpp | 2 +- RouterInfo.cpp | 7 +++++++ version.h | 1 + 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index d0b6da26..b9d5a130 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -168,16 +168,19 @@ namespace data } else { - LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase32()); r = std::make_shared (buf, len); + if (!r->IsUnreachable ()) { - std::unique_lock l(m_RouterInfosMutex); - m_RouterInfos[r->GetIdentHash ()] = r; - } - if (r->IsFloodfill ()) - { - std::unique_lock l(m_FloodfillsMutex); - m_Floodfills.push_back (r); + LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase32()); + { + std::unique_lock l(m_RouterInfosMutex); + m_RouterInfos[r->GetIdentHash ()] = r; + } + if (r->IsFloodfill ()) + { + std::unique_lock l(m_FloodfillsMutex); + m_Floodfills.push_back (r); + } } } // take care about requested destination diff --git a/RouterContext.cpp b/RouterContext.cpp index 3117c85a..7d35ccf1 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -51,7 +51,7 @@ namespace i2p routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC routerInfo.SetProperty ("coreVersion", I2P_VERSION); - routerInfo.SetProperty ("netId", "2"); + routerInfo.SetProperty ("netId", std::to_string (I2PD_NET_ID)); routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.SetProperty ("stat_uptime", "90m"); routerInfo.CreateBuffer (m_Keys); diff --git a/RouterInfo.cpp b/RouterInfo.cpp index 53ab7aa3..8f2b7bfe 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -3,6 +3,7 @@ #include "I2PEndian.h" #include #include +#include "version.h" #include "Crypto.h" #include "Base.h" #include "Timestamp.h" @@ -243,6 +244,12 @@ namespace data // extract caps if (!strcmp (key, "caps")) ExtractCaps (value); + // check netId + if (!strcmp (key, "netId") && atoi (value) != I2PD_NET_ID) + { + LogPrint (eLogError, "Unexpected netid=", value); + m_IsUnreachable = true; + } } if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers)) diff --git a/version.h b/version.h index 8b93f1af..8fea069c 100644 --- a/version.h +++ b/version.h @@ -12,6 +12,7 @@ #define I2PD_VERSION_PATCH 0 #define I2PD_VERSION MAKE_VERSION(I2PD_VERSION_MAJOR, I2PD_VERSION_MINOR, I2PD_VERSION_MICRO) #define VERSION I2PD_VERSION +#define I2PD_NET_ID 2 #define I2P_VERSION_MAJOR 0 #define I2P_VERSION_MINOR 9 From b6dcb2f4c0f846ee5754627a5b6a2eddac964956 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 17 Jan 2016 11:10:56 -0500 Subject: [PATCH 03/13] show streams as table (byt sha-db) --- HTTPServer.cpp | 208 ++++++++++++++++++++++++++++--------------------- Tunnel.cpp | 7 +- 2 files changed, 124 insertions(+), 91 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 3a16ff6f..bb3e2819 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -357,45 +357,47 @@ namespace util { std::stringstream s; // Html5 head start - s << "\n"; // TODO: Add support for locale. - s << ""; // TODO: Find something to parse html/template system. This is horrible. - s << ""; - s << "Purple I2P " << VERSION " Webconsole"; - s << ""; + s << "caption {font-size: 1.5em; text-align: center; color: #894C84;}"; + s << "table {width: 100%; border-collapse: collapse; text-align: center;}"; + s << "\r\n\r\n\r\n"; s << "
i2pd webconsole
"; s << "
"; - s << "
"; - s << "Main page

"; - s << "Local destinations
"; - s << "Tunnels
"; - s << "Transit tunnels
"; - s << "Transports

"; - s << "I2P tunnels
"; + s << "
\r\n"; + s << "Main page
\r\n
\r\n"; + s << "Local destinations
\r\n"; + s << "Tunnels
\r\n"; + s << "Transit tunnels
\r\n"; + s << "Transports
\r\n
\r\n"; + s << "I2P tunnels
\r\n"; if (i2p::client::context.GetSAMBridge ()) - s << "SAM sessions

"; + s << "SAM sessions
\r\n
\r\n"; if (i2p::context.AcceptsTunnels ()) - s << "Stop accepting tunnels

"; + s << "Stop accepting tunnels
\r\n
\r\n"; else - s << "Start accepting tunnels

"; - s << "Run peer test

"; + s << "Start accepting tunnels
\r\n
\r\n"; + s << "Run peer test
\r\n
\r\n"; s << "
"; if (address.length () > 1) HandleCommand (address.substr (2), s); else FillContent (s); - s << "
"; + s << "
\r\n\r\n"; SendReply (s.str ()); } @@ -403,7 +405,7 @@ namespace util { s << "Uptime: " << boost::posix_time::to_simple_string ( boost::posix_time::time_duration (boost::posix_time::seconds ( - i2p::context.GetUptime ()))) << "
"; + i2p::context.GetUptime ()))) << "
\r\n"; s << "Status: "; switch (i2p::context.GetStatus ()) { @@ -412,14 +414,14 @@ namespace util case eRouterStatusFirewalled: s << "Firewalled"; break; default: s << "Unknown"; } - s << "
"; - s << "Tunnel creation success rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%
"; + s << "
\r\n"; + s << "Tunnel creation success rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%
\r\n"; s << "Received: " << i2p::transport::transports.GetTotalReceivedBytes ()/1000 << "K"; - s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)
"; + s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)
\r\n"; s << "Sent: " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K"; - s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)
"; - s << "Data path: " << i2p::util::filesystem::GetDataDir().string() << "

"; - s << "Our external address:" << "
" ; + s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)
\r\n"; + s << "Data path: " << i2p::util::filesystem::GetDataDir().string() << "
\r\n
\r\n"; + s << "Our external address:" << "
\r\n" ; for (auto& address : i2p::context.GetRouterInfo().GetAddresses()) { switch (address.transportStyle) @@ -439,11 +441,11 @@ namespace util default: s << "Unknown  "; } - s << address.host.to_string() << ":" << address.port << "
"; + s << address.host.to_string() << ":" << address.port << "
\r\n"; } - s << "
Routers: " << i2p::data::netdb.GetNumRouters () << " "; + s << "
\r\nRouters: " << i2p::data::netdb.GetNumRouters () << " "; s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << " "; - s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "
"; + s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "
\r\n"; } void HTTPConnection::HandleCommand (const std::string& command, std::stringstream& s) @@ -486,30 +488,31 @@ namespace util void HTTPConnection::ShowLocalDestinations (std::stringstream& s) { - s << "Local Destinations:

"; + s << "Local Destinations:
\r\n
\r\n"; for (auto& it: i2p::client::context.GetDestinations ()) { auto ident = it.second->GetIdentHash ();; s << ""; - s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
" << std::endl; + s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
\r\n" << std::endl; } } void HTTPConnection::ShowLocalDestination (const std::string& b32, std::stringstream& s) { - s << "Local Destination:

"; + s << "Local Destination:
\r\n
\r\n"; i2p::data::IdentHash ident; ident.FromBase32 (b32); auto dest = i2p::client::context.FindLocalDestination (ident); if (dest) { - s << "Base64:
" << dest->GetIdentity ()->ToBase64 () << "

"; - s << "LeaseSets: " << dest->GetNumRemoteLeaseSets () << "
"; + s << "Base64:
\r\n
\r\n
\r\n"; + s << "LeaseSets: " << dest->GetNumRemoteLeaseSets () << "
\r\n"; auto pool = dest->GetTunnelPool (); if (pool) { - s << "Tunnels:
"; + s << "Tunnels:
\r\n"; for (auto it: pool->GetOutboundTunnels ()) { it->Print (s); @@ -518,7 +521,7 @@ namespace util s << " " << "Failed"; else if (state == i2p::tunnel::eTunnelStateExpiring) s << " " << "Exp"; - s << "
" << std::endl; + s << "
\r\n" << std::endl; } for (auto it: pool->GetInboundTunnels ()) { @@ -528,28 +531,56 @@ namespace util s << " " << "Failed"; else if (state == i2p::tunnel::eTunnelStateExpiring) s << " " << "Exp"; - s << "
" << std::endl; + s << "
\r\n" << std::endl; } } - s << "
Streams:
"; + // s << "
\r\nStreams:
\r\n"; + // for (auto it: dest->GetStreamingDestination ()->GetStreams ()) + // { + // s << it.first << "->" << i2p::client::context.GetAddressBook ().ToAddress(it.second->GetRemoteIdentity ()) << " "; + // s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; + // s << " [out:" << it.second->GetSendQueueSize () << "][in:" << it.second->GetReceiveQueueSize () << "]"; + // s << "[buf:" << it.second->GetSendBufferSize () << "]"; + // s << "[RTT:" << it.second->GetRTT () << "]"; + // s << "[Window:" << it.second->GetWindowSize () << "]"; + // s << "[Status:" << (int)it.second->GetStatus () << "]"; + // s << "
\r\n"<< std::endl; + // } + s << "
\r\n"; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + for (auto it: dest->GetStreamingDestination ()->GetStreams ()) { - s << it.first << "->" << i2p::client::context.GetAddressBook ().ToAddress(it.second->GetRemoteIdentity ()) << " "; - s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << " [out:" << it.second->GetSendQueueSize () << "][in:" << it.second->GetReceiveQueueSize () << "]"; - s << "[buf:" << it.second->GetSendBufferSize () << "]"; - s << "[RTT:" << it.second->GetRTT () << "]"; - s << "[Window:" << it.second->GetWindowSize () << "]"; - s << "[Status:" << (int)it.second->GetStatus () << "]"; - s << "
"<< std::endl; - } + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << ""; + s << "
\r\n" << std::endl; + } } } void HTTPConnection::ShowTunnels (std::stringstream& s) { - s << "Tunnels:

"; - s << "Queue size:" << i2p::tunnel::tunnels.GetQueueSize () << "
"; + s << "Tunnels:
\r\n
\r\n"; + s << "Queue size:" << i2p::tunnel::tunnels.GetQueueSize () << "
\r\n"; for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) { it->Print (s); @@ -558,7 +589,7 @@ namespace util s << " " << "Failed"; else if (state == i2p::tunnel::eTunnelStateExpiring) s << " " << "Exp"; - s << " " << (int)it->GetNumSentBytes () << "
"; + s << " " << (int)it->GetNumSentBytes () << "
\r\n"; s << std::endl; } @@ -570,78 +601,78 @@ namespace util s << " " << "Failed"; else if (state == i2p::tunnel::eTunnelStateExpiring) s << " " << "Exp"; - s << " " << (int)it.second->GetNumReceivedBytes () << "
"; + s << " " << (int)it.second->GetNumReceivedBytes () << "
\r\n"; s << std::endl; } } void HTTPConnection::ShowTransitTunnels (std::stringstream& s) { - s << "Transit tunnels:

"; + s << "Transit tunnels:
\r\n
\r\n"; for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) { if (dynamic_cast(it.second)) - s << it.second->GetTunnelID () << "-->"; + s << it.second->GetTunnelID () << " ⇒ "; else if (dynamic_cast(it.second)) - s << "-->" << it.second->GetTunnelID (); + s << " ⇒ " << it.second->GetTunnelID (); else - s << "-->" << it.second->GetTunnelID () << "-->"; - s << " " << it.second->GetNumTransmittedBytes () << "
"; + s << " ⇒ " << it.second->GetTunnelID () << " ⇒ "; + s << " " << it.second->GetNumTransmittedBytes () << "
\r\n"; } } void HTTPConnection::ShowTransports (std::stringstream& s) { - s << "Transports:

"; + s << "Transports:
\r\n
\r\n"; auto ntcpServer = i2p::transport::transports.GetNTCPServer (); if (ntcpServer) { - s << "NTCP
"; + s << "NTCP
\r\n"; for (auto it: ntcpServer->GetNTCPSessions ()) { if (it.second && it.second->IsEstablished ()) { // incoming connection doesn't have remote RI - if (it.second->IsOutgoing ()) s << "-->"; + if (it.second->IsOutgoing ()) s << " ⇒ "; s << i2p::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": " << it.second->GetSocket ().remote_endpoint().address ().to_string (); - if (!it.second->IsOutgoing ()) s << "-->"; + if (!it.second->IsOutgoing ()) s << " ⇒ "; s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << "
" << std::endl; + s << "
\r\n" << std::endl; } } } auto ssuServer = i2p::transport::transports.GetSSUServer (); if (ssuServer) { - s << "
SSU
"; + s << "
\r\nSSU
\r\n"; for (auto it: ssuServer->GetSessions ()) { auto endpoint = it.second->GetRemoteEndpoint (); - if (it.second->IsOutgoing ()) s << "-->"; + if (it.second->IsOutgoing ()) s << " ⇒ "; s << endpoint.address ().to_string () << ":" << endpoint.port (); - if (!it.second->IsOutgoing ()) s << "-->"; + if (!it.second->IsOutgoing ()) s << " ⇒ "; s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; if (it.second->GetRelayTag ()) s << " [itag:" << it.second->GetRelayTag () << "]"; - s << "
" << std::endl; + s << "
\r\n" << std::endl; } - s << "
SSU6
"; + s << "
\r\nSSU6
\r\n"; for (auto it: ssuServer->GetSessionsV6 ()) { auto endpoint = it.second->GetRemoteEndpoint (); - if (it.second->IsOutgoing ()) s << "-->"; + if (it.second->IsOutgoing ()) s << " ⇒ "; s << endpoint.address ().to_string () << ":" << endpoint.port (); - if (!it.second->IsOutgoing ()) s << "-->"; + if (!it.second->IsOutgoing ()) s << " ⇒ "; s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << "
" << std::endl; + s << "
\r\n" << std::endl; } } } void HTTPConnection::ShowSAMSessions (std::stringstream& s) { - s << "SAM Sessions:

"; + s << "SAM Sessions:
\r\n
\r\n"; auto sam = i2p::client::context.GetSAMBridge (); if (sam) { @@ -649,14 +680,14 @@ namespace util { s << ""; - s << it.first << "
" << std::endl; + s << it.first << "
\r\n" << std::endl; } } } void HTTPConnection::ShowSAMSession (const std::string& id, std::stringstream& s) { - s << "SAM Session:

"; + s << "SAM Session:
\r\n
\r\n"; auto sam = i2p::client::context.GetSAMBridge (); if (sam) { @@ -666,8 +697,8 @@ namespace util auto& ident = session->localDestination->GetIdentHash(); s << ""; - s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
" << std::endl; - s << "Streams:
"; + s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
\r\n" << std::endl; + s << "Streams:
\r\n"; for (auto it: session->sockets) { switch (it->GetSocketType ()) @@ -685,7 +716,7 @@ namespace util s << "unknown"; } s << " [" << it->GetSocket ().remote_endpoint() << "]"; - s << "
" << std::endl; + s << "
\r\n" << std::endl; } } } @@ -693,45 +724,45 @@ namespace util void HTTPConnection::ShowI2PTunnels (std::stringstream& s) { - s << "Client Tunnels:

"; + s << "Client Tunnels:
\r\n
\r\n"; for (auto& it: i2p::client::context.GetClientTunnels ()) { - s << it.second->GetName () << "<--"; + s << it.second->GetName () << " ⇐ "; auto& ident = it.second->GetLocalDestination ()->GetIdentHash(); s << ""; s << i2p::client::context.GetAddressBook ().ToAddress(ident); - s << "
"<< std::endl; + s << "
\r\n"<< std::endl; } - s << "
Server Tunnels:

"; + s << "
\r\nServer Tunnels:
\r\n
\r\n"; for (auto& it: i2p::client::context.GetServerTunnels ()) { - s << it.second->GetName () << "-->"; + s << it.second->GetName () << " ⇒ "; auto& ident = it.second->GetLocalDestination ()->GetIdentHash(); s << ""; s << i2p::client::context.GetAddressBook ().ToAddress(ident); - s << "
"<< std::endl; + s << "
\r\n"<< std::endl; } } void HTTPConnection::StopAcceptingTunnels (std::stringstream& s) { - s << "Stop Accepting Tunnels:

"; + s << "Stop Accepting Tunnels:
\r\n
\r\n"; i2p::context.SetAcceptsTunnels (false); s << "Accepting tunnels stopped" << std::endl; } void HTTPConnection::StartAcceptingTunnels (std::stringstream& s) { - s << "Start Accepting Tunnels:

"; + s << "Start Accepting Tunnels:
\r\n
\r\n"; i2p::context.SetAcceptsTunnels (true); s << "Accepting tunnels started" << std::endl; } void HTTPConnection::RunPeerTest (std::stringstream& s) { - s << "Run Peer Test:

"; + s << "Run Peer Test:
\r\n
\r\n"; i2p::transport::transports.PeerTest (); s << "Peer test is running" << std::endl; } @@ -749,7 +780,7 @@ namespace util if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination)) { LogPrint (eLogWarning, "HTTPServer: Unknown address ", address); - SendReply ("" + itoopieImage + "
Unknown address " + address + "", 404); + SendReply ("" + itoopieImage + "
\r\nUnknown address " + address + "", 404); return; } @@ -777,7 +808,7 @@ namespace util SendToDestination (leaseSet, port, buf, len); else // still no LeaseSet - SendReply (leaseSet ? "" + itoopieImage + "
Leases expired" : "" + itoopieImage + "LeaseSet not found", 504); + SendReply (leaseSet ? "" + itoopieImage + "
\r\nLeases expired" : "" + itoopieImage + "LeaseSet not found", 504); } } @@ -811,7 +842,7 @@ namespace util else { if (ecode == boost::asio::error::timed_out) - SendReply ("" + itoopieImage + "
Not responding", 504); + SendReply ("" + itoopieImage + "
\r\nNot responding", 504); else if (ecode != boost::asio::error::operation_aborted) Terminate (); } @@ -898,3 +929,4 @@ namespace util } + diff --git a/Tunnel.cpp b/Tunnel.cpp index 7a91adca..3391fbc8 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -186,7 +186,7 @@ namespace tunnel { for (auto& it: m_Hops) { - s << "-->"; + s << " ⇒ "; s << i2p::data::GetIdentHashAbbreviation (it->ident->GetIdentHash ()); } } @@ -203,7 +203,7 @@ namespace tunnel void InboundTunnel::Print (std::stringstream& s) const { PrintHops (s); - s << "-->" << GetTunnelID () << ":me"; + s << " ⇒ " << GetTunnelID () << ":me"; } void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr msg) @@ -245,7 +245,7 @@ namespace tunnel { s << GetTunnelID () << ":me"; PrintHops (s); - s << "-->"; + s << " ⇒ "; } Tunnels tunnels; @@ -787,3 +787,4 @@ namespace tunnel } } } + From c312dbaac1b88a2b2741226a64952210a89d52c6 Mon Sep 17 00:00:00 2001 From: zenjy Date: Sun, 17 Jan 2016 18:13:36 +0000 Subject: [PATCH 04/13] * Daemon.h: replace "#pragma once" with "#define" --- Daemon.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Daemon.h b/Daemon.h index 9af8c1bb..6252ffe4 100644 --- a/Daemon.h +++ b/Daemon.h @@ -1,4 +1,6 @@ -#pragma once +#ifndef DAEMON_H__ +#define DAEMON_H__ + #include #ifdef _WIN32 @@ -69,3 +71,5 @@ namespace i2p #endif } } + +#endif // DAEMON_H__ From 02b566055ebc8d2a45158cd0d2ed44b4805eed3a Mon Sep 17 00:00:00 2001 From: zenjy Date: Sun, 17 Jan 2016 18:18:21 +0000 Subject: [PATCH 05/13] * HTTPServer.cpp: add space after "Queue size:" --- HTTPServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index bb3e2819..699fbde4 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -580,7 +580,7 @@ namespace util void HTTPConnection::ShowTunnels (std::stringstream& s) { s << "Tunnels:
\r\n
\r\n"; - s << "Queue size:" << i2p::tunnel::tunnels.GetQueueSize () << "
\r\n"; + s << "Queue size: " << i2p::tunnel::tunnels.GetQueueSize () << "
\r\n"; for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) { it->Print (s); From efdea07b7bf367003e90ac85ddcebe170a24cf04 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 17 Jan 2016 18:03:40 -0500 Subject: [PATCH 06/13] change message expiration timeout to 8 secs (RTT) --- I2NPProtocol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 16d5e245..854f258c 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -38,7 +38,7 @@ namespace i2p SetTypeID (msgType); if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4); SetMsgID (replyMsgID); - SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000); // TODO: 5 secs is a magic number + SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000); // 8 secs means initial RTT UpdateSize (); UpdateChks (); } @@ -48,7 +48,7 @@ namespace i2p uint32_t msgID; RAND_bytes ((uint8_t *)&msgID, 4); SetMsgID (msgID); - SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000); + SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000); } std::shared_ptr CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID) From cd549937c5b337f49cfba56c2e7f4b54d0917bbd Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 17 Jan 2016 18:55:09 -0500 Subject: [PATCH 07/13] support multiple server tunnels with same destination and different ports --- ClientContext.cpp | 4 +++- ClientContext.h | 3 ++- HTTPServer.cpp | 1 + I2PTunnel.h | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index 791ab563..e93f9a4a 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -310,7 +310,9 @@ namespace client while (comma != std::string::npos); serverTunnel->SetAccessList (idents); } - if (m_ServerTunnels.insert (std::make_pair (localDestination->GetIdentHash (), std::unique_ptr(serverTunnel))).second) + if (m_ServerTunnels.insert (std::make_pair ( + std::make_tuple (localDestination->GetIdentHash (), inPort), + std::unique_ptr(serverTunnel))).second) serverTunnel->Start (); else LogPrint (eLogError, "Clients: I2P server tunnel for destination ", m_AddressBook.ToAddress(localDestination->GetIdentHash ()), " already exists"); diff --git a/ClientContext.h b/ClientContext.h index 1750f2b5..52f1ab5b 100644 --- a/ClientContext.h +++ b/ClientContext.h @@ -2,6 +2,7 @@ #define CLIENT_CONTEXT_H__ #include +#include #include #include #include "Destination.h" @@ -74,7 +75,7 @@ namespace client i2p::proxy::HTTPProxy * m_HttpProxy; i2p::proxy::SOCKSProxy * m_SocksProxy; std::map > m_ClientTunnels; // port->tunnel - std::map > m_ServerTunnels; // destination->tunnel + std::map, std::unique_ptr > m_ServerTunnels; // ->tunnel SAMBridge * m_SamBridge; BOBCommandChannel * m_BOBCommandChannel; diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 699fbde4..ab6e2631 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -742,6 +742,7 @@ namespace util s << ""; s << i2p::client::context.GetAddressBook ().ToAddress(ident); + s << ":" << it.second->GetLocalPort (); s << "
\r\n"<< std::endl; } } diff --git a/I2PTunnel.h b/I2PTunnel.h index 146466c5..7a172468 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -123,6 +123,7 @@ namespace client const std::string& GetAddress() const { return m_Address; } int GetPort () const { return m_Port; }; + uint16_t GetLocalPort () const { return m_PortDestination->GetLocalPort (); }; const boost::asio::ip::tcp::endpoint& GetEndpoint () const { return m_Endpoint; } const char* GetName() { return m_Name.c_str (); } From 05043f30dc18359ddc3abdd0140c54b3ccf87246 Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 18 Jan 2016 00:00:00 +0000 Subject: [PATCH 08/13] * tune logs --- AddressBook.cpp | 2 +- Daemon.cpp | 4 +-- HTTPServer.cpp | 2 +- Log.cpp | 2 +- NetDb.cpp | 16 +++++----- NetDbRequests.cpp | 8 ++--- SOCKS.cpp | 73 ++++++++++++++++++++++------------------------ SSUSession.cpp | 2 +- Tunnel.cpp | 30 +++++++++---------- TunnelEndpoint.cpp | 2 +- TunnelPool.cpp | 2 +- 11 files changed, 70 insertions(+), 73 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index 64f910e8..00b735ae 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -393,7 +393,7 @@ namespace client if (!s.length()) continue; // skip empty line m_Subscriptions.push_back (new AddressBookSubscription (*this, s)); } - LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions loaded"); + LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded"); } else LogPrint (eLogWarning, "Addresbook: subscriptions.txt not found"); diff --git a/Daemon.cpp b/Daemon.cpp index 0d2a52c4..48ef1e82 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -63,8 +63,8 @@ namespace i2p i2p::util::config::OptionParser(argc, argv); i2p::context.Init (); - LogPrint(eLogInfo, "\n\n\n\ni2pd v", VERSION, " starting\n"); - LogPrint(eLogDebug, "data directory: ", i2p::util::filesystem::GetDataDir().string()); + LogPrint(eLogInfo, "i2pd v", VERSION, " starting"); + LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string()); i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); isDaemon = i2p::util::config::GetArg("-daemon", 0); diff --git a/HTTPServer.cpp b/HTTPServer.cpp index ab6e2631..e4a75e1a 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -771,7 +771,7 @@ namespace util void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri) { std::string request = "GET " + uri + " HTTP/1.1\r\nHost:" + address + "\r\n\r\n"; - LogPrint(eLogDebug, "HTTPServer: client request: ", request); + LogPrint(eLogInfo, "HTTPServer: client request: ", request); SendToAddress (address, 80, request.c_str (), request.size ()); } diff --git a/Log.cpp b/Log.cpp index 4f31fb31..837abac8 100644 --- a/Log.cpp +++ b/Log.cpp @@ -65,7 +65,7 @@ void Log::SetLogLevel (const std::string& level) LogPrint(eLogError, "Log: Unknown loglevel: ", level); return; } - LogPrint(eLogInfo, "Log: min msg level set to ", level); + LogPrint(eLogInfo, "Log: min messages level set to ", level); } void Log::SetLogStream (std::ostream * logStream) diff --git a/NetDb.cpp b/NetDb.cpp index b9d5a130..0cbdce30 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -164,14 +164,14 @@ namespace data auto ts = r->GetTimestamp (); r->Update (buf, len); if (r->GetTimestamp () > ts) - LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase32()); + LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64()); } else { r = std::make_shared (buf, len); if (!r->IsUnreachable ()) { - LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase32()); + LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase64()); { std::unique_lock l(m_RouterInfosMutex); m_RouterInfos[r->GetIdentHash ()] = r; @@ -197,10 +197,10 @@ namespace data { it->second->Update (buf, len); if (it->second->IsValid ()) - LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase32()); + LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase64()); else { - LogPrint (eLogWarning, "NetDb: LeaseSet update failed: ", ident.ToBase32()); + LogPrint (eLogWarning, "NetDb: LeaseSet update failed: ", ident.ToBase64()); m_LeaseSets.erase (it); } } @@ -209,11 +209,11 @@ namespace data auto leaseSet = std::make_shared (buf, len); if (leaseSet->IsValid ()) { - LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase32()); + LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase64()); m_LeaseSets[ident] = leaseSet; } else - LogPrint (eLogError, "NetDb: new LeaseSet validation failed: ", ident.ToBase32()); + LogPrint (eLogError, "NetDb: new LeaseSet validation failed: ", ident.ToBase64()); } } } @@ -435,7 +435,7 @@ namespace data auto dest = m_Requests.CreateRequest (destination, false, requestComplete); // non-exploratory if (!dest) { - LogPrint (eLogWarning, "NetDb: destination ", destination.ToBase32(), " is requested already"); + LogPrint (eLogWarning, "NetDb: destination ", destination.ToBase64(), " is requested already"); return; } @@ -444,7 +444,7 @@ namespace data transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); else { - LogPrint (eLogError, "NetDb: ", destination.ToBase32(), " destination requested, but no floodfills found"); + LogPrint (eLogError, "NetDb: ", destination.ToBase64(), " destination requested, but no floodfills found"); m_Requests.RequestComplete (destination, nullptr); } } diff --git a/NetDbRequests.cpp b/NetDbRequests.cpp index a8ccf3f9..e1ea2872 100644 --- a/NetDbRequests.cpp +++ b/NetDbRequests.cpp @@ -122,15 +122,15 @@ namespace data else { done = true; - if (!inbound) LogPrint (eLogWarning, "No inbound tunnels"); - if (!outbound) LogPrint (eLogWarning, "No outbound tunnels"); - if (!nextFloodfill) LogPrint (eLogWarning, "No more floodfills"); + if (!inbound) LogPrint (eLogWarning, "NetDbReq: No inbound tunnels"); + if (!outbound) LogPrint (eLogWarning, "NetDbReq: No outbound tunnels"); + if (!nextFloodfill) LogPrint (eLogWarning, "NetDbReq: No more floodfills"); } } else { if (!dest->IsExploratory ()) - LogPrint (eLogWarning, dest->GetDestination ().ToBase64 (), " not found after 7 attempts"); + LogPrint (eLogWarning, "NetDbReq: ", dest->GetDestination ().ToBase64 (), " not found after 7 attempts"); done = true; } } diff --git a/SOCKS.cpp b/SOCKS.cpp index d82cd0f4..3a971a60 100644 --- a/SOCKS.cpp +++ b/SOCKS.cpp @@ -145,13 +145,14 @@ namespace proxy void SOCKSHandler::AsyncSockRead() { - LogPrint(eLogDebug,"--- SOCKS async sock read"); - if(m_sock) + LogPrint(eLogDebug, "SOCKS: async sock read"); + if (m_sock) { m_sock->async_receive(boost::asio::buffer(m_sock_buff, socks_buffer_size), std::bind(&SOCKSHandler::HandleSockRecv, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); - else - LogPrint(eLogError,"--- SOCKS no socket for read"); + } else { + LogPrint(eLogError,"SOCKS: no socket for read"); + } } void SOCKSHandler::Terminate() @@ -159,13 +160,13 @@ namespace proxy if (Kill()) return; if (m_sock) { - LogPrint(eLogDebug,"--- SOCKS close sock"); + LogPrint(eLogDebug, "SOCKS: closing socket"); m_sock->close(); m_sock = nullptr; } if (m_stream) { - LogPrint(eLogDebug,"--- SOCKS close stream"); + LogPrint(eLogDebug, "SOCKS: closing stream"); m_stream.reset (); } Done(shared_from_this()); @@ -216,14 +217,14 @@ namespace proxy boost::asio::const_buffers_1 response(m_response,2); if (m_authchosen == AUTH_UNACCEPTABLE) { - LogPrint(eLogWarning,"--- SOCKS5 authentication negotiation failed"); + LogPrint(eLogWarning, "SOCKS: v5 authentication negotiation failed"); boost::asio::async_write(*m_sock, response, std::bind(&SOCKSHandler::SentSocksFailed, shared_from_this(), std::placeholders::_1)); return false; } else { - LogPrint(eLogDebug,"--- SOCKS5 choosing authentication method: ", m_authchosen); + LogPrint(eLogDebug, "SOCKS: v5 choosing authentication method: ", m_authchosen); boost::asio::async_write(*m_sock, response, std::bind(&SOCKSHandler::SentSocksResponse, shared_from_this(), std::placeholders::_1)); return true; @@ -238,12 +239,12 @@ namespace proxy switch (m_socksv) { case SOCKS4: - LogPrint(eLogWarning,"--- SOCKS4 failed: ", error); + LogPrint(eLogWarning, "SOCKS: v4 request failed: ", error); if (error < SOCKS4_OK) error = SOCKS4_FAIL; //Transparently map SOCKS5 errors response = GenerateSOCKS4Response(error, m_4aip, m_port); break; case SOCKS5: - LogPrint(eLogWarning,"--- SOCKS5 failed: ", error); + LogPrint(eLogWarning, "SOCKS: v5 request failed: ", error); response = GenerateSOCKS5Response(error, m_addrtype, m_address, m_port); break; } @@ -258,11 +259,11 @@ namespace proxy switch (m_socksv) { case SOCKS4: - LogPrint(eLogInfo,"--- SOCKS4 connection success"); + LogPrint(eLogInfo, "SOCKS: v4 connection success"); response = GenerateSOCKS4Response(SOCKS4_OK, m_4aip, m_port); break; case SOCKS5: - LogPrint(eLogInfo,"--- SOCKS5 connection success"); + LogPrint(eLogInfo, "SOCKS: v5 connection success"); auto s = i2p::client::context.GetAddressBook().ToAddress(GetOwner()->GetLocalDestination()->GetIdentHash()); address ad; ad.dns.FromString(s); //HACK only 16 bits passed in port as SOCKS5 doesn't allow for more @@ -293,7 +294,7 @@ namespace proxy if ( m_cmd != CMD_CONNECT ) { //TODO: we need to support binds and other shit! - LogPrint(eLogError,"--- SOCKS unsupported command: ", m_cmd); + LogPrint(eLogError, "SOCKS: unsupported command: ", m_cmd); SocksRequestFailed(SOCKS5_CMD_UNSUP); return false; } @@ -303,10 +304,10 @@ namespace proxy switch (m_socksv) { case SOCKS5: - LogPrint(eLogError,"--- SOCKS5 unsupported address type: ", m_addrtype); + LogPrint(eLogError, "SOCKS: v5 unsupported address type: ", m_addrtype); break; case SOCKS4: - LogPrint(eLogError,"--- SOCKS4a rejected because it's actually SOCKS4"); + LogPrint(eLogError, "SOCKS: request with v4a rejected because it's actually SOCKS4"); break; } SocksRequestFailed(SOCKS5_ADDR_UNSUP); @@ -315,7 +316,7 @@ namespace proxy //TODO: we may want to support other domains if(m_addrtype == ADDR_DNS && m_address.dns.ToString().find(".i2p") == std::string::npos) { - LogPrint(eLogError,"--- SOCKS invalid hostname: ", m_address.dns.ToString()); + LogPrint(eLogError, "SOCKS: invalid hostname: ", m_address.dns.ToString()); SocksRequestFailed(SOCKS5_ADDR_UNSUP); return false; } @@ -340,7 +341,7 @@ namespace proxy EnterState(GET5_AUTHNUM); //Initialize the parser at the right position break; default: - LogPrint(eLogError,"--- SOCKS rejected invalid version: ", ((int)*sock_buff)); + LogPrint(eLogError, "SOCKS: rejected invalid version: ", ((int)*sock_buff)); Terminate(); return false; } @@ -367,7 +368,7 @@ namespace proxy case CMD_UDP: if (m_socksv == SOCKS5) break; default: - LogPrint(eLogError,"--- SOCKS invalid command: ", ((int)*sock_buff)); + LogPrint(eLogError, "SOCKS: invalid command: ", ((int)*sock_buff)); SocksRequestFailed(SOCKS5_GEN_FAIL); return false; } @@ -419,7 +420,7 @@ namespace proxy } if (m_address.dns.size >= max_socks_hostname_size) { - LogPrint(eLogError,"--- SOCKS4a destination is too large"); + LogPrint(eLogError, "SOCKS: v4a req failed: destination is too large"); SocksRequestFailed(SOCKS4_FAIL); return false; } @@ -428,7 +429,7 @@ namespace proxy case GET5_REQUESTV: if (*sock_buff != SOCKS5) { - LogPrint(eLogError,"--- SOCKS5 rejected unknown request version: ", ((int)*sock_buff)); + LogPrint(eLogError,"SOCKS: v5 rejected unknown request version: ", ((int)*sock_buff)); SocksRequestFailed(SOCKS5_GEN_FAIL); return false; } @@ -437,7 +438,7 @@ namespace proxy case GET5_GETRSV: if ( *sock_buff != 0 ) { - LogPrint(eLogError,"--- SOCKS5 unknown reserved field: ", ((int)*sock_buff)); + LogPrint(eLogError, "SOCKS: v5 unknown reserved field: ", ((int)*sock_buff)); SocksRequestFailed(SOCKS5_GEN_FAIL); return false; } @@ -450,7 +451,7 @@ namespace proxy case ADDR_IPV6: EnterState(GET5_IPV6); break; case ADDR_DNS : EnterState(GET5_HOST_SIZE); break; default: - LogPrint(eLogError,"--- SOCKS5 unknown address type: ", ((int)*sock_buff)); + LogPrint(eLogError, "SOCKS: v5 unknown address type: ", ((int)*sock_buff)); SocksRequestFailed(SOCKS5_GEN_FAIL); return false; } @@ -469,7 +470,7 @@ namespace proxy if (m_parseleft == 0) EnterState(GET_PORT); break; default: - LogPrint(eLogError,"--- SOCKS parse state?? ", m_state); + LogPrint(eLogError, "SOCKS: parse state?? ", m_state); Terminate(); return false; } @@ -487,11 +488,11 @@ namespace proxy void SOCKSHandler::HandleSockRecv(const boost::system::error_code & ecode, std::size_t len) { - LogPrint(eLogDebug,"--- SOCKS sock recv: ", len); + LogPrint(eLogDebug, "SOCKS: recieved ", len, " bytes"); if(ecode) { - LogPrint(eLogWarning," --- SOCKS sock recv got error: ", ecode); - Terminate(); + LogPrint(eLogWarning, "SOCKS: recv got error: ", ecode); + Terminate(); return; } @@ -499,7 +500,7 @@ namespace proxy { if (m_state == DONE) { - LogPrint(eLogInfo,"--- SOCKS requested ", m_address.dns.ToString(), ":" , m_port); + LogPrint(eLogInfo, "SOCKS: requested ", m_address.dns.ToString(), ":" , m_port); GetOwner()->CreateStream ( std::bind (&SOCKSHandler::HandleStreamRequestComplete, shared_from_this(), std::placeholders::_1), m_address.dns.ToString(), m_port); } @@ -510,13 +511,9 @@ namespace proxy void SOCKSHandler::SentSocksFailed(const boost::system::error_code & ecode) { - if (!ecode) - Terminate(); - else - { - LogPrint (eLogError,"--- SOCKS Closing socket after sending failure because: ", ecode.message ()); - Terminate(); - } + if (ecode) + LogPrint (eLogError, "SOCKS: closing socket after sending failure because: ", ecode.message ()); + Terminate(); } void SOCKSHandler::SentSocksDone(const boost::system::error_code & ecode) @@ -524,7 +521,7 @@ namespace proxy if (!ecode) { if (Kill()) return; - LogPrint (eLogInfo,"--- SOCKS New I2PTunnel connection"); + LogPrint (eLogInfo, "SOCKS: new I2PTunnel connection"); auto connection = std::make_shared(GetOwner(), m_sock, m_stream); GetOwner()->AddHandler (connection); connection->I2PConnect (m_remaining_data,m_remaining_data_len); @@ -532,7 +529,7 @@ namespace proxy } else { - LogPrint (eLogError,"--- SOCKS Closing socket after completion reply because: ", ecode.message ()); + LogPrint (eLogError, "SOCKS: closing socket after completion reply because: ", ecode.message ()); Terminate(); } } @@ -541,7 +538,7 @@ namespace proxy { if (ecode) { - LogPrint (eLogError,"--- SOCKS Closing socket after sending reply because: ", ecode.message ()); + LogPrint (eLogError, "SOCKS: closing socket after sending reply because: ", ecode.message ()); Terminate(); } } @@ -555,7 +552,7 @@ namespace proxy } else { - LogPrint (eLogError,"--- SOCKS Issue when creating the stream, check the previous warnings for more info."); + LogPrint (eLogError, "SOCKS: error when creating the stream, check the previous warnings for more info"); SocksRequestFailed(SOCKS5_HOST_UNREACH); } } diff --git a/SSUSession.cpp b/SSUSession.cpp index f5e1f6e6..68af81bb 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -853,7 +853,7 @@ namespace transport { if (ecode != boost::asio::error::operation_aborted) { - LogPrint (eLogInfo, "SSU: no activity for", SSU_TERMINATION_TIMEOUT, " seconds"); + LogPrint (eLogWarning, "SSU: no activity for ", SSU_TERMINATION_TIMEOUT, " seconds"); Failed (); } } diff --git a/Tunnel.cpp b/Tunnel.cpp index 3391fbc8..267485c8 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -163,7 +163,7 @@ namespace tunnel void Tunnel::SendTunnelDataMsg (std::shared_ptr msg) { - LogPrint (eLogInfo, "Tunnel: Can't send I2NP messages without delivery instructions"); + LogPrint (eLogWarning, "Tunnel: Can't send I2NP messages without delivery instructions"); } std::vector > Tunnel::GetPeers () const @@ -238,7 +238,7 @@ namespace tunnel void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr tunnelMsg) { - LogPrint (eLogError, "Incoming message for outbound tunnel ", GetTunnelID ()); + LogPrint (eLogError, "Tunnel: incoming message for outbound tunnel ", GetTunnelID ()); } void OutboundTunnel::Print (std::stringstream& s) const @@ -368,7 +368,7 @@ namespace tunnel std::unique_lock l(m_TransitTunnelsMutex); if (!m_TransitTunnels.insert (std::make_pair (tunnel->GetTunnelID (), tunnel)).second) { - LogPrint (eLogError, "Transit tunnel ", tunnel->GetTunnelID (), " already exists"); + LogPrint (eLogError, "Tunnel: transit tunnel with id ", tunnel->GetTunnelID (), " already exists"); delete tunnel; } } @@ -432,7 +432,7 @@ namespace tunnel HandleTunnelGatewayMsg (tunnel, msg); } else - LogPrint (eLogWarning, "Tunnel ", tunnelID, " not found"); + LogPrint (eLogWarning, "Tunnel: tunnel with id ", tunnelID, " not found"); break; } case eI2NPVariableTunnelBuild: @@ -442,7 +442,7 @@ namespace tunnel HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); break; default: - LogPrint (eLogError, "Tunnel: Unexpected messsage type ", (int)typeID); + LogPrint (eLogError, "Tunnel: unexpected messsage type ", (int) typeID); } msg = m_Queue.Get (); @@ -475,7 +475,7 @@ namespace tunnel { if (!tunnel) { - LogPrint (eLogError, "Missing tunnel for TunnelGateway"); + LogPrint (eLogError, "Tunnel: missing tunnel for gateway"); return; } const uint8_t * payload = msg->GetPayload (); @@ -484,7 +484,7 @@ namespace tunnel msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE; msg->len = msg->offset + len; auto typeID = msg->GetTypeID (); - LogPrint (eLogDebug, "TunnelGateway of ", (int)len, " bytes for tunnel ", tunnel->GetTunnelID (), ". Msg type ", (int)typeID); + LogPrint (eLogDebug, "Tunnel: gateway of ", (int) len, " bytes for tunnel ", tunnel->GetTunnelID (), ", msg type ", (int)typeID); if (IsRouterInfoMsg (msg) || typeID == eI2NPDatabaseSearchReply) // transit DatabaseStore my contain new/updated RI @@ -521,7 +521,7 @@ namespace tunnel case eTunnelStatePending: if (ts > tunnel->GetCreationTime () + TUNNEL_CREATION_TIMEOUT) { - LogPrint (eLogError, "Tunnel: Pending build request ", it->first, " timeout, deleted"); + LogPrint (eLogWarning, "Tunnel: pending build request ", it->first, " timeout, deleted"); // update stats auto config = tunnel->GetTunnelConfig (); if (config) @@ -546,7 +546,7 @@ namespace tunnel it++; break; case eTunnelStateBuildFailed: - LogPrint (eLogError, "Tunnel: Pending build request ", it->first, " failed, deleted"); + LogPrint (eLogError, "Tunnel: pending build request ", it->first, " failed, deleted"); it = pendingTunnels.erase (it); m_NumFailedTunnelCreations++; break; @@ -571,7 +571,7 @@ namespace tunnel auto tunnel = *it; if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { - LogPrint (eLogDebug, "Tunnel: ", tunnel->GetTunnelID (), " expired"); + LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired"); auto pool = tunnel->GetTunnelPool (); if (pool) pool->TunnelExpired (tunnel); @@ -602,7 +602,7 @@ namespace tunnel auto inboundTunnel = GetNextInboundTunnel (); auto router = i2p::data::netdb.GetRandomRouter (); if (!inboundTunnel || !router) return; - LogPrint (eLogDebug, "Creating one hop outbound tunnel"); + LogPrint (eLogDebug, "Tunnel: creating one hop outbound tunnel"); CreateTunnel ( std::make_shared (std::vector > { router->GetRouterIdentity () }, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()) @@ -619,7 +619,7 @@ namespace tunnel auto tunnel = it->second; if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { - LogPrint (eLogDebug, "Tunnel: ", tunnel->GetTunnelID (), " expired"); + LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired"); auto pool = tunnel->GetTunnelPool (); if (pool) pool->TunnelExpired (tunnel); @@ -647,7 +647,7 @@ namespace tunnel if (m_InboundTunnels.empty ()) { - LogPrint (eLogDebug, "Creating zero hops inbound tunnel..."); + LogPrint (eLogDebug, "Tunnel: Creating zero hops inbound tunnel"); CreateZeroHopsInboundTunnel (); if (!m_ExploratoryPool) { @@ -661,7 +661,7 @@ namespace tunnel { // trying to create one more inbound tunnel auto router = i2p::data::netdb.GetRandomRouter (); - LogPrint (eLogDebug, "Creating one hop inbound tunnel..."); + LogPrint (eLogDebug, "Tunnel: creating one hop inbound tunnel"); CreateTunnel ( std::make_shared (std::vector > { router->GetRouterIdentity () }) ); @@ -676,7 +676,7 @@ namespace tunnel if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { auto tmp = it->second; - LogPrint (eLogDebug, "Transit tunnel ", tmp->GetTunnelID (), " expired"); + LogPrint (eLogDebug, "Tunnel: Transit tunnel with id ", tmp->GetTunnelID (), " expired"); { std::unique_lock l(m_TransitTunnelsMutex); it = m_TransitTunnels.erase (it); diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 5225c8d8..024bb36d 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -226,7 +226,7 @@ namespace tunnel void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg) { auto typeID = msg.data->GetTypeID (); - LogPrint (eLogInfo, "TunnelMessage: handle fragment of ", msg.data->GetLength ()," bytes. Msg type ", (int)typeID); + LogPrint (eLogDebug, "TunnelMessage: handle fragment of ", msg.data->GetLength (), " bytes, msg type ", (int)typeID); switch (msg.deliveryType) { case eDeliveryTypeLocal: diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 3f92116d..72d6735a 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -203,7 +203,7 @@ namespace tunnel { for (auto it: m_Tests) { - LogPrint (eLogWarning, "Tunnels: test of ", (int)it.first, " failed"); + LogPrint (eLogWarning, "Tunnels: test of tunnel ", it.first, " failed"); // if test failed again with another tunnel we consider it failed if (it.second.first) { From 1d5194a13888d76e4bfa859e4b7ea5994a40d400 Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 18 Jan 2016 00:00:00 +0000 Subject: [PATCH 09/13] * drop mapMultiArgs : it's not used anywhere --- Daemon.cpp | 2 +- util.cpp | 7 +------ util.h | 4 +--- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 48ef1e82..d947bbb0 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -65,7 +65,7 @@ namespace i2p LogPrint(eLogInfo, "i2pd v", VERSION, " starting"); LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string()); - i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); + i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs); isDaemon = i2p::util::config::GetArg("-daemon", 0); isLogging = i2p::util::config::GetArg("-log", 1); diff --git a/util.cpp b/util.cpp index afb1d92b..850dfa89 100644 --- a/util.cpp +++ b/util.cpp @@ -70,12 +70,10 @@ namespace util namespace config { std::map mapArgs; - std::map > mapMultiArgs; void OptionParser(int argc, const char* const argv[]) { mapArgs.clear(); - mapMultiArgs.clear(); for (int i = 1; i < argc; i++) { std::string strKey (argv[i]); @@ -96,7 +94,6 @@ namespace config break; mapArgs[strKey] = strValue; - mapMultiArgs[strKey].push_back(strValue); } BOOST_FOREACH(PAIRTYPE(const std::string,std::string)& entry, mapArgs) @@ -196,8 +193,7 @@ namespace filesystem return pathTunnelsConfigFile; } - void ReadConfigFile(std::map& mapSettingsRet, - std::map >& mapMultiSettingsRet) + void ReadConfigFile(std::map& mapSettingsRet) { boost::filesystem::ifstream streamConfig(GetConfigFile()); if (!streamConfig.good()) @@ -214,7 +210,6 @@ namespace filesystem { mapSettingsRet[strKey] = it->value[0]; } - mapMultiSettingsRet[strKey].push_back(it->value[0]); } } diff --git a/util.h b/util.h index 8c72a97b..6478f894 100644 --- a/util.h +++ b/util.h @@ -17,7 +17,6 @@ namespace util namespace config { extern std::map mapArgs; - extern std::map > mapMultiArgs; void OptionParser(int argc, const char* const argv[]); int GetArg(const std::string& strArg, int nDefault); std::string GetArg(const std::string& strArg, const std::string& strDefault); @@ -34,8 +33,7 @@ namespace util boost::filesystem::path GetDefaultDataDir(); boost::filesystem::path GetConfigFile(); boost::filesystem::path GetTunnelsConfigFile(); - void ReadConfigFile(std::map& mapSettingsRet, - std::map >& mapMultiSettingsRet); + void ReadConfigFile(std::map& mapSettingsRet); boost::filesystem::path GetCertificatesDir(); } From 45d68d89a9e96e2353a2cf618097b4dc014f2f30 Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 18 Jan 2016 00:00:00 +0000 Subject: [PATCH 10/13] * clean outdated declaration --- util.h | 1 - 1 file changed, 1 deletion(-) diff --git a/util.h b/util.h index 6478f894..040b3a34 100644 --- a/util.h +++ b/util.h @@ -20,7 +20,6 @@ namespace util void OptionParser(int argc, const char* const argv[]); int GetArg(const std::string& strArg, int nDefault); std::string GetArg(const std::string& strArg, const std::string& strDefault); - const char* GetCharArg(const std::string& strArg, const std::string& nDefault); } namespace filesystem From 314e1e4bfedf3ad959650d1053bbcac8f72c634e Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 18 Jan 2016 00:00:00 +0000 Subject: [PATCH 11/13] * unwrap i2p::util::config::* calls in ClientContext.cpp --- ClientContext.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index e93f9a4a..4e189f26 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -45,31 +45,38 @@ namespace client LoadPrivateKeys (keys, proxyKeys); localDestination = CreateNewLocalDestination (keys, false); } - LogPrint(eLogInfo, "Clients: starting HTTP Proxy"); - m_HttpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyaddress", "127.0.0.1"), i2p::util::config::GetArg("-httpproxyport", 4446), localDestination); + std::string httpProxyAddr = i2p::util::config::GetArg("-httpproxyaddress", "127.0.0.1"); + uint16_t httpProxyPort = i2p::util::config::GetArg("-httpproxyport", 4446); + LogPrint(eLogInfo, "Clients: starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort); + m_HttpProxy = new i2p::proxy::HTTPProxy(httpProxyAddr, httpProxyPort, localDestination); m_HttpProxy->Start(); - LogPrint(eLogInfo, "Clients: starting SOCKS Proxy"); - m_SocksProxy = new i2p::proxy::SOCKSProxy(i2p::util::config::GetArg("-socksproxyaddress", "127.0.0.1"), i2p::util::config::GetArg("-socksproxyport", 4447), localDestination); + + std::string socksProxyAddr = i2p::util::config::GetArg("-socksproxyaddress", "127.0.0.1"); + uint16_t socksProxyPort = i2p::util::config::GetArg("-socksproxyport", 4447); + LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort); + m_SocksProxy = new i2p::proxy::SOCKSProxy(socksProxyAddr, socksProxyPort, localDestination); m_SocksProxy->Start(); // I2P tunnels ReadTunnels (); // SAM - int samPort = i2p::util::config::GetArg("-samport", 0); + std::string samAddr = i2p::util::config::GetArg("-samaddress", "127.0.0.1"); + uint16_t samPort = i2p::util::config::GetArg("-samport", 0); if (samPort) { - LogPrint(eLogInfo, "Clients: starting SAM bridge"); - m_SamBridge = new SAMBridge (i2p::util::config::GetArg("-samaddress", "127.0.0.1"), samPort); + LogPrint(eLogInfo, "Clients: starting SAM bridge at", samAddr, ":", samPort); + m_SamBridge = new SAMBridge (samAddr, samPort); m_SamBridge->Start (); } // BOB - int bobPort = i2p::util::config::GetArg("-bobport", 0); + std::string bobAddr = i2p::util::config::GetArg("-bobaddress", "127.0.0.1"); + uint16_t bobPort = i2p::util::config::GetArg("-bobport", 0); if (bobPort) { - LogPrint(eLogInfo, "Clients: starting BOB command channel"); - m_BOBCommandChannel = new BOBCommandChannel (i2p::util::config::GetArg("-bobaddress", "127.0.0.1"), bobPort); + LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort); + m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort); m_BOBCommandChannel->Start (); } From 6740ec464c1be90edbe942f34fa07e3e5d4b1068 Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 18 Jan 2016 00:00:00 +0000 Subject: [PATCH 12/13] * unwrap i2p::util::config::* calls in Daemon.cpp --- Daemon.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index d947bbb0..ca6681b4 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -120,8 +120,10 @@ namespace i2p g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info")); } - LogPrint(eLogInfo, "Daemon: staring HTTP Server"); - d.httpServer = std::unique_ptr(new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpaddress", "127.0.0.1"), i2p::util::config::GetArg("-httpport", 7070))); + std::string httpAddr = i2p::util::config::GetArg("-httpaddress", "127.0.0.1"); + uint16_t httpPort = i2p::util::config::GetArg("-httpport", 7070); + LogPrint(eLogInfo, "Daemon: staring HTTP Server at ", httpAddr, ":", httpPort); + d.httpServer = std::unique_ptr(new i2p::util::HTTPServer(httpAddr, httpPort)); d.httpServer->Start(); LogPrint(eLogInfo, "Daemon: starting NetDB"); @@ -140,12 +142,13 @@ namespace i2p LogPrint(eLogInfo, "Daemon: starting Client"); i2p::client::context.Start (); - // I2P Control - int i2pcontrolPort = i2p::util::config::GetArg("-i2pcontrolport", 0); - if (i2pcontrolPort) + // I2P Control Protocol + std::string i2pcpAddr = i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"); + uint16_t i2pcpPort = i2p::util::config::GetArg("-i2pcontrolport", 0); + if (i2pcpPort) { - LogPrint(eLogInfo, "Daemon: starting I2PControl"); - d.m_I2PControlService = std::unique_ptr(new i2p::client::I2PControlService (i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"), i2pcontrolPort)); + LogPrint(eLogInfo, "Daemon: starting I2PControl at ", i2pcpAddr, ":", i2pcpPort); + d.m_I2PControlService = std::unique_ptr(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort)); d.m_I2PControlService->Start (); } return true; From 7565843fbe746d8948d6e996b717e3f69fa53dfd Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 18 Jan 2016 00:00:00 +0000 Subject: [PATCH 13/13] * move ReadConfigFile() : i2p::filesystem -> i2p::config * don't export i2p::config::mapArgs outside namespace --- Daemon.cpp | 2 +- util.cpp | 40 ++++++++++++++++++++-------------------- util.h | 3 +-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index ca6681b4..1415435a 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -65,7 +65,7 @@ namespace i2p LogPrint(eLogInfo, "i2pd v", VERSION, " starting"); LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string()); - i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs); + i2p::util::config::ReadConfigFile(i2p::util::filesystem::GetConfigFile()); isDaemon = i2p::util::config::GetArg("-daemon", 0); isLogging = i2p::util::config::GetArg("-log", 1); diff --git a/util.cpp b/util.cpp index 850dfa89..cff2aa75 100644 --- a/util.cpp +++ b/util.cpp @@ -124,6 +124,26 @@ namespace config return atoi(mapArgs[strArg].c_str()); return nDefault; } + + void ReadConfigFile(boost::filesystem::path path) + { + boost::filesystem::ifstream streamConfig(path); + if (!streamConfig.good()) + return; // No i2pd.conf file is OK + + std::set setOptions; + setOptions.insert("*"); + + for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it) + { + // Don't overwrite existing settings so command line settings override i2pd.conf + std::string strKey = std::string("-") + it->string_key; + if (mapArgs.count(strKey) == 0) + { + mapArgs[strKey] = it->value[0]; + } + } + } } namespace filesystem @@ -193,26 +213,6 @@ namespace filesystem return pathTunnelsConfigFile; } - void ReadConfigFile(std::map& mapSettingsRet) - { - boost::filesystem::ifstream streamConfig(GetConfigFile()); - if (!streamConfig.good()) - return; // No i2pd.conf file is OK - - std::set setOptions; - setOptions.insert("*"); - - for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it) - { - // Don't overwrite existing settings so command line settings override i2pd.conf - std::string strKey = std::string("-") + it->string_key; - if (mapSettingsRet.count(strKey) == 0) - { - mapSettingsRet[strKey] = it->value[0]; - } - } - } - boost::filesystem::path GetDefaultDataDir() { // Windows < Vista: C:\Documents and Settings\Username\.i2pd diff --git a/util.h b/util.h index 040b3a34..905c2a8d 100644 --- a/util.h +++ b/util.h @@ -16,10 +16,10 @@ namespace util { namespace config { - extern std::map mapArgs; void OptionParser(int argc, const char* const argv[]); int GetArg(const std::string& strArg, int nDefault); std::string GetArg(const std::string& strArg, const std::string& strDefault); + void ReadConfigFile(boost::filesystem::path path); } namespace filesystem @@ -32,7 +32,6 @@ namespace util boost::filesystem::path GetDefaultDataDir(); boost::filesystem::path GetConfigFile(); boost::filesystem::path GetTunnelsConfigFile(); - void ReadConfigFile(std::map& mapSettingsRet); boost::filesystem::path GetCertificatesDir(); }
Streams
StreamIDDestinationSentReceivedOutInBufRTTWindowStatus
" << it.first << "" << i2p::client::context.GetAddressBook ().ToAddress(it.second->GetRemoteIdentity ()) << "" << it.second->GetNumSentBytes () << "" << it.second->GetNumReceivedBytes () << "" << it.second->GetSendQueueSize () << "" << it.second->GetReceiveQueueSize () << "" << it.second->GetSendBufferSize () << "" << it.second->GetRTT () << "" << it.second->GetWindowSize () << "" << (int)it.second->GetStatus () << "