Browse Source

Merge branch 'openssl' of https://github.com/PurpleI2P/i2pd into openssl

pull/326/head
orignal 9 years ago
parent
commit
eb2d68fc28
  1. 2
      AddressBook.cpp
  2. 31
      ClientContext.cpp
  3. 3
      ClientContext.h
  4. 23
      Daemon.cpp
  5. 6
      Daemon.h
  6. 209
      HTTPServer.cpp
  7. 4
      I2NPProtocol.cpp
  8. 1
      I2PTunnel.h
  9. 2
      Log.cpp
  10. 33
      NetDb.cpp
  11. 8
      NetDbRequests.cpp
  12. 2
      RouterContext.cpp
  13. 7
      RouterInfo.cpp
  14. 73
      SOCKS.cpp
  15. 2
      SSUSession.cpp
  16. 37
      Tunnel.cpp
  17. 2
      TunnelEndpoint.cpp
  18. 2
      TunnelPool.cpp
  19. 45
      util.cpp
  20. 6
      util.h
  21. 1
      version.h

2
AddressBook.cpp

@ -393,7 +393,7 @@ namespace client
if (!s.length()) continue; // skip empty line if (!s.length()) continue; // skip empty line
m_Subscriptions.push_back (new AddressBookSubscription (*this, s)); 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 else
LogPrint (eLogWarning, "Addresbook: subscriptions.txt not found"); LogPrint (eLogWarning, "Addresbook: subscriptions.txt not found");

31
ClientContext.cpp

@ -45,31 +45,38 @@ namespace client
LoadPrivateKeys (keys, proxyKeys); LoadPrivateKeys (keys, proxyKeys);
localDestination = CreateNewLocalDestination (keys, false); localDestination = CreateNewLocalDestination (keys, false);
} }
LogPrint(eLogInfo, "Clients: starting HTTP Proxy"); std::string httpProxyAddr = i2p::util::config::GetArg("-httpproxyaddress", "127.0.0.1");
m_HttpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyaddress", "127.0.0.1"), i2p::util::config::GetArg("-httpproxyport", 4446), localDestination); 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(); 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(); m_SocksProxy->Start();
// I2P tunnels // I2P tunnels
ReadTunnels (); ReadTunnels ();
// SAM // 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) if (samPort)
{ {
LogPrint(eLogInfo, "Clients: starting SAM bridge"); LogPrint(eLogInfo, "Clients: starting SAM bridge at", samAddr, ":", samPort);
m_SamBridge = new SAMBridge (i2p::util::config::GetArg("-samaddress", "127.0.0.1"), samPort); m_SamBridge = new SAMBridge (samAddr, samPort);
m_SamBridge->Start (); m_SamBridge->Start ();
} }
// BOB // 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) if (bobPort)
{ {
LogPrint(eLogInfo, "Clients: starting BOB command channel"); LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort);
m_BOBCommandChannel = new BOBCommandChannel (i2p::util::config::GetArg("-bobaddress", "127.0.0.1"), bobPort); m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort);
m_BOBCommandChannel->Start (); m_BOBCommandChannel->Start ();
} }
@ -310,7 +317,9 @@ namespace client
while (comma != std::string::npos); while (comma != std::string::npos);
serverTunnel->SetAccessList (idents); serverTunnel->SetAccessList (idents);
} }
if (m_ServerTunnels.insert (std::make_pair (localDestination->GetIdentHash (), std::unique_ptr<I2PServerTunnel>(serverTunnel))).second) if (m_ServerTunnels.insert (std::make_pair (
std::make_tuple (localDestination->GetIdentHash (), inPort),
std::unique_ptr<I2PServerTunnel>(serverTunnel))).second)
serverTunnel->Start (); serverTunnel->Start ();
else else
LogPrint (eLogError, "Clients: I2P server tunnel for destination ", m_AddressBook.ToAddress(localDestination->GetIdentHash ()), " already exists"); LogPrint (eLogError, "Clients: I2P server tunnel for destination ", m_AddressBook.ToAddress(localDestination->GetIdentHash ()), " already exists");

3
ClientContext.h

@ -2,6 +2,7 @@
#define CLIENT_CONTEXT_H__ #define CLIENT_CONTEXT_H__
#include <map> #include <map>
#include <tuple>
#include <mutex> #include <mutex>
#include <memory> #include <memory>
#include "Destination.h" #include "Destination.h"
@ -74,7 +75,7 @@ namespace client
i2p::proxy::HTTPProxy * m_HttpProxy; i2p::proxy::HTTPProxy * m_HttpProxy;
i2p::proxy::SOCKSProxy * m_SocksProxy; i2p::proxy::SOCKSProxy * m_SocksProxy;
std::map<int, std::unique_ptr<I2PClientTunnel> > m_ClientTunnels; // port->tunnel std::map<int, std::unique_ptr<I2PClientTunnel> > m_ClientTunnels; // port->tunnel
std::map<i2p::data::IdentHash, std::unique_ptr<I2PServerTunnel> > m_ServerTunnels; // destination->tunnel std::map<std::tuple<i2p::data::IdentHash, int>, std::unique_ptr<I2PServerTunnel> > m_ServerTunnels; // <destination,port>->tunnel
SAMBridge * m_SamBridge; SAMBridge * m_SamBridge;
BOBCommandChannel * m_BOBCommandChannel; BOBCommandChannel * m_BOBCommandChannel;

23
Daemon.cpp

@ -63,9 +63,9 @@ namespace i2p
i2p::util::config::OptionParser(argc, argv); i2p::util::config::OptionParser(argc, argv);
i2p::context.Init (); i2p::context.Init ();
LogPrint(eLogInfo, "\n\n\n\ni2pd v", VERSION, " starting\n"); LogPrint(eLogInfo, "i2pd v", VERSION, " starting");
LogPrint(eLogDebug, "data directory: ", i2p::util::filesystem::GetDataDir().string()); LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string());
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); i2p::util::config::ReadConfigFile(i2p::util::filesystem::GetConfigFile());
isDaemon = i2p::util::config::GetArg("-daemon", 0); isDaemon = i2p::util::config::GetArg("-daemon", 0);
isLogging = i2p::util::config::GetArg("-log", 1); isLogging = i2p::util::config::GetArg("-log", 1);
@ -120,8 +120,10 @@ namespace i2p
g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info")); g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info"));
} }
LogPrint(eLogInfo, "Daemon: staring HTTP Server"); std::string httpAddr = i2p::util::config::GetArg("-httpaddress", "127.0.0.1");
d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpaddress", "127.0.0.1"), i2p::util::config::GetArg("-httpport", 7070))); uint16_t httpPort = i2p::util::config::GetArg("-httpport", 7070);
LogPrint(eLogInfo, "Daemon: staring HTTP Server at ", httpAddr, ":", httpPort);
d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(httpAddr, httpPort));
d.httpServer->Start(); d.httpServer->Start();
LogPrint(eLogInfo, "Daemon: starting NetDB"); LogPrint(eLogInfo, "Daemon: starting NetDB");
@ -140,12 +142,13 @@ namespace i2p
LogPrint(eLogInfo, "Daemon: starting Client"); LogPrint(eLogInfo, "Daemon: starting Client");
i2p::client::context.Start (); i2p::client::context.Start ();
// I2P Control // I2P Control Protocol
int i2pcontrolPort = i2p::util::config::GetArg("-i2pcontrolport", 0); std::string i2pcpAddr = i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1");
if (i2pcontrolPort) uint16_t i2pcpPort = i2p::util::config::GetArg("-i2pcontrolport", 0);
if (i2pcpPort)
{ {
LogPrint(eLogInfo, "Daemon: starting I2PControl"); LogPrint(eLogInfo, "Daemon: starting I2PControl at ", i2pcpAddr, ":", i2pcpPort);
d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"), i2pcontrolPort)); d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
d.m_I2PControlService->Start (); d.m_I2PControlService->Start ();
} }
return true; return true;

6
Daemon.h

@ -1,4 +1,6 @@
#pragma once #ifndef DAEMON_H__
#define DAEMON_H__
#include <string> #include <string>
#ifdef _WIN32 #ifdef _WIN32
@ -69,3 +71,5 @@ namespace i2p
#endif #endif
} }
} }
#endif // DAEMON_H__

209
HTTPServer.cpp

@ -357,45 +357,47 @@ namespace util
{ {
std::stringstream s; std::stringstream s;
// Html5 head start // Html5 head start
s << "<!DOCTYPE html>\n<html lang=\"en\">"; // TODO: Add support for locale. s << "<!DOCTYPE html>\r\n<html lang=\"en\">"; // TODO: Add support for locale.
s << "<head><meta charset=\"utf-8\">"; // TODO: Find something to parse html/template system. This is horrible. s << "<head>\r\n<meta charset=\"utf-8\">\r\n"; // TODO: Find something to parse html/template system. This is horrible.
s << "<link rel='shortcut icon' href='" + itoopieFavicon + "'>"; s << "<link rel='shortcut icon' href='" + itoopieFavicon + "'>\r\n";
s << "<title>Purple I2P " << VERSION " Webconsole</title>"; s << "<title>Purple I2P " << VERSION " Webconsole</title>\r\n";
s << "<style>"; s << "<style>\r\n";
s << "body {font: 100%/1.5em sans-serif; margin: 0; padding: 1.5em; background: #FAFAFA; color: #103456;}"; s << "body {font: 100%/1.5em sans-serif; margin: 0; padding: 1.5em; background: #FAFAFA; color: #103456;}";
s << "a {text-decoration: none; color: #894C84;}"; s << "a {text-decoration: none; color: #894C84;}";
s << "a:hover {color: #FAFAFA; background: #894C84;}"; s << "a:hover {color: #FAFAFA; background: #894C84;}";
s << ".header {font-size: 2.5em; text-align: center; margin: 1.5em 0; color: #894C84;}"; 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 << ".wrapper {margin: 0 auto; padding: 1em; max-width: 60em;}";
s << ".left {float: left; position: absolute;}"; 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: 46em; overflow: auto;}";
s << ".established_tunnel {color: #56b734;}"; s << ".established_tunnel {color: #56b734;}";
s << ".expiring_tunnel {color: #d3ae3f;}"; s << ".expiring_tunnel {color: #d3ae3f;}";
s << ".failed_tunnel {color: #d33f3f;}"; s << ".failed_tunnel {color: #d33f3f;}";
s << ".another_tunnel {color: #434343;}"; s << ".another_tunnel {color: #434343;}";
s << "</style></head><body>"; s << "caption {font-size: 1.5em; text-align: center; color: #894C84;}";
s << "table {width: 100%; border-collapse: collapse; text-align: center;}";
s << "</style>\r\n</head>\r\n<body>\r\n";
s << "<div class=header><b>i2pd </b>webconsole</div>"; s << "<div class=header><b>i2pd </b>webconsole</div>";
s << "<div class=wrapper>"; s << "<div class=wrapper>";
s << "<div class=left>"; s << "<div class=left>\r\n";
s << "<a href=/>Main page</a><br><br>"; s << "<a href=/>Main page</a><br>\r\n<br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATIONS << ">Local destinations</a><br>"; s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATIONS << ">Local destinations</a><br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a><br>"; s << "<a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a><br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a><br>"; s << "<a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a><br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a><br><br>"; s << "<a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a><br>\r\n<br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_I2P_TUNNELS << ">I2P tunnels</a><br>"; s << "<a href=/?" << HTTP_COMMAND_I2P_TUNNELS << ">I2P tunnels</a><br>\r\n";
if (i2p::client::context.GetSAMBridge ()) if (i2p::client::context.GetSAMBridge ())
s << "<a href=/?" << HTTP_COMMAND_SAM_SESSIONS << ">SAM sessions</a><br><br>"; s << "<a href=/?" << HTTP_COMMAND_SAM_SESSIONS << ">SAM sessions</a><br>\r\n<br>\r\n";
if (i2p::context.AcceptsTunnels ()) if (i2p::context.AcceptsTunnels ())
s << "<a href=/?" << HTTP_COMMAND_STOP_ACCEPTING_TUNNELS << ">Stop accepting tunnels</a><br><br>"; s << "<a href=/?" << HTTP_COMMAND_STOP_ACCEPTING_TUNNELS << ">Stop accepting tunnels</a><br>\r\n<br>\r\n";
else else
s << "<a href=/?" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << ">Start accepting tunnels</a><br><br>"; s << "<a href=/?" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << ">Start accepting tunnels</a><br>\r\n<br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_RUN_PEER_TEST << ">Run peer test</a><br><br>"; s << "<a href=/?" << HTTP_COMMAND_RUN_PEER_TEST << ">Run peer test</a><br>\r\n<br>\r\n";
s << "</div><div class=right>"; s << "</div><div class=right>";
if (address.length () > 1) if (address.length () > 1)
HandleCommand (address.substr (2), s); HandleCommand (address.substr (2), s);
else else
FillContent (s); FillContent (s);
s << "</div></div></body></html>"; s << "</div></div>\r\n</body>\r\n</html>";
SendReply (s.str ()); SendReply (s.str ());
} }
@ -403,7 +405,7 @@ namespace util
{ {
s << "<b>Uptime:</b> " << boost::posix_time::to_simple_string ( s << "<b>Uptime:</b> " << boost::posix_time::to_simple_string (
boost::posix_time::time_duration (boost::posix_time::seconds ( boost::posix_time::time_duration (boost::posix_time::seconds (
i2p::context.GetUptime ()))) << "<br>"; i2p::context.GetUptime ()))) << "<br>\r\n";
s << "<b>Status:</b> "; s << "<b>Status:</b> ";
switch (i2p::context.GetStatus ()) switch (i2p::context.GetStatus ())
{ {
@ -412,14 +414,14 @@ namespace util
case eRouterStatusFirewalled: s << "Firewalled"; break; case eRouterStatusFirewalled: s << "Firewalled"; break;
default: s << "Unknown"; default: s << "Unknown";
} }
s << "<br>"; s << "<br>\r\n";
s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>"; s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>\r\n";
s << "<b>Received:</b> " << i2p::transport::transports.GetTotalReceivedBytes ()/1000 << "K"; s << "<b>Received:</b> " << i2p::transport::transports.GetTotalReceivedBytes ()/1000 << "K";
s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)<br>"; s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)<br>\r\n";
s << "<b>Sent:</b> " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K"; s << "<b>Sent:</b> " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K";
s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>"; s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>\r\n";
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br><br>"; s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br>\r\n<br>\r\n";
s << "<b>Our external address:</b>" << "<br>" ; s << "<b>Our external address:</b>" << "<br>\r\n" ;
for (auto& address : i2p::context.GetRouterInfo().GetAddresses()) for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
{ {
switch (address.transportStyle) switch (address.transportStyle)
@ -439,11 +441,11 @@ namespace util
default: default:
s << "Unknown&nbsp;&nbsp;"; s << "Unknown&nbsp;&nbsp;";
} }
s << address.host.to_string() << ":" << address.port << "<br>"; s << address.host.to_string() << ":" << address.port << "<br>\r\n";
} }
s << "<br><b>Routers:</b> " << i2p::data::netdb.GetNumRouters () << " "; s << "<br>\r\n<b>Routers:</b> " << i2p::data::netdb.GetNumRouters () << " ";
s << "<b>Floodfills:</b> " << i2p::data::netdb.GetNumFloodfills () << " "; s << "<b>Floodfills:</b> " << i2p::data::netdb.GetNumFloodfills () << " ";
s << "<b>LeaseSets:</b> " << i2p::data::netdb.GetNumLeaseSets () << "<br>"; s << "<b>LeaseSets:</b> " << i2p::data::netdb.GetNumLeaseSets () << "<br>\r\n";
} }
void HTTPConnection::HandleCommand (const std::string& command, std::stringstream& s) void HTTPConnection::HandleCommand (const std::string& command, std::stringstream& s)
@ -486,30 +488,31 @@ namespace util
void HTTPConnection::ShowLocalDestinations (std::stringstream& s) void HTTPConnection::ShowLocalDestinations (std::stringstream& s)
{ {
s << "<b>Local Destinations:</b><br><br>"; s << "<b>Local Destinations:</b><br>\r\n<br>\r\n";
for (auto& it: i2p::client::context.GetDestinations ()) for (auto& it: i2p::client::context.GetDestinations ())
{ {
auto ident = it.second->GetIdentHash ();; auto ident = it.second->GetIdentHash ();;
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION; s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">"; s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>" << std::endl; s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>\r\n" << std::endl;
} }
} }
void HTTPConnection::ShowLocalDestination (const std::string& b32, std::stringstream& s) void HTTPConnection::ShowLocalDestination (const std::string& b32, std::stringstream& s)
{ {
s << "<b>Local Destination:</b><br><br>"; s << "<b>Local Destination:</b><br>\r\n<br>\r\n";
i2p::data::IdentHash ident; i2p::data::IdentHash ident;
ident.FromBase32 (b32); ident.FromBase32 (b32);
auto dest = i2p::client::context.FindLocalDestination (ident); auto dest = i2p::client::context.FindLocalDestination (ident);
if (dest) if (dest)
{ {
s << "<b>Base64:</b><br>" << dest->GetIdentity ()->ToBase64 () << "<br><br>"; s << "<b>Base64:</b><br>\r\n<textarea readonly=\"readonly\" cols=\"64\" rows=\"1\" wrap=\"off\">";
s << "<b>LeaseSets:</b> <i>" << dest->GetNumRemoteLeaseSets () << "</i><br>"; s << dest->GetIdentity ()->ToBase64 () << "</textarea><br>\r\n<br>\r\n";
s << "<b>LeaseSets:</b> <i>" << dest->GetNumRemoteLeaseSets () << "</i><br>\r\n";
auto pool = dest->GetTunnelPool (); auto pool = dest->GetTunnelPool ();
if (pool) if (pool)
{ {
s << "<b>Tunnels:</b><br>"; s << "<b>Tunnels:</b><br>\r\n";
for (auto it: pool->GetOutboundTunnels ()) for (auto it: pool->GetOutboundTunnels ())
{ {
it->Print (s); it->Print (s);
@ -518,7 +521,7 @@ namespace util
s << " " << "Failed"; s << " " << "Failed";
else if (state == i2p::tunnel::eTunnelStateExpiring) else if (state == i2p::tunnel::eTunnelStateExpiring)
s << " " << "Exp"; s << " " << "Exp";
s << "<br>" << std::endl; s << "<br>\r\n" << std::endl;
} }
for (auto it: pool->GetInboundTunnels ()) for (auto it: pool->GetInboundTunnels ())
{ {
@ -528,28 +531,56 @@ namespace util
s << " " << "Failed"; s << " " << "Failed";
else if (state == i2p::tunnel::eTunnelStateExpiring) else if (state == i2p::tunnel::eTunnelStateExpiring)
s << " " << "Exp"; s << " " << "Exp";
s << "<br>" << std::endl; s << "<br>\r\n" << std::endl;
} }
} }
s << "<br><b>Streams:</b><br>"; // s << "<br>\r\n<b>Streams:</b><br>\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 << "<br>\r\n"<< std::endl;
// }
s << "<br>\r\n<table><caption>Streams</caption><tr>";
s << "<th>StreamID</th>";
s << "<th>Destination</th>";
s << "<th>Sent</th>";
s << "<th>Received</th>";
s << "<th>Out</th>";
s << "<th>In</th>";
s << "<th>Buf</th>";
s << "<th>RTT</th>";
s << "<th>Window</th>";
s << "<th>Status</th>";
s << "</tr>";
for (auto it: dest->GetStreamingDestination ()->GetStreams ()) for (auto it: dest->GetStreamingDestination ()->GetStreams ())
{ {
s << it.first << "->" << i2p::client::context.GetAddressBook ().ToAddress(it.second->GetRemoteIdentity ()) << " "; s << "<tr>";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; s << "<td>" << it.first << "</td>";
s << " [out:" << it.second->GetSendQueueSize () << "][in:" << it.second->GetReceiveQueueSize () << "]"; s << "<td>" << i2p::client::context.GetAddressBook ().ToAddress(it.second->GetRemoteIdentity ()) << "</td>";
s << "[buf:" << it.second->GetSendBufferSize () << "]"; s << "<td>" << it.second->GetNumSentBytes () << "</td>";
s << "[RTT:" << it.second->GetRTT () << "]"; s << "<td>" << it.second->GetNumReceivedBytes () << "</td>";
s << "[Window:" << it.second->GetWindowSize () << "]"; s << "<td>" << it.second->GetSendQueueSize () << "</td>";
s << "[Status:" << (int)it.second->GetStatus () << "]"; s << "<td>" << it.second->GetReceiveQueueSize () << "</td>";
s << "<br>"<< std::endl; s << "<td>" << it.second->GetSendBufferSize () << "</td>";
s << "<td>" << it.second->GetRTT () << "</td>";
s << "<td>" << it.second->GetWindowSize () << "</td>";
s << "<td>" << (int)it.second->GetStatus () << "</td>";
s << "</tr><br>\r\n" << std::endl;
} }
} }
} }
void HTTPConnection::ShowTunnels (std::stringstream& s) void HTTPConnection::ShowTunnels (std::stringstream& s)
{ {
s << "<b>Tunnels:</b><br><br>"; s << "<b>Tunnels:</b><br>\r\n<br>\r\n";
s << "<b>Queue size:</b>" << i2p::tunnel::tunnels.GetQueueSize () << "<br>"; s << "<b>Queue size:</b> " << i2p::tunnel::tunnels.GetQueueSize () << "<br>\r\n";
for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ())
{ {
it->Print (s); it->Print (s);
@ -558,7 +589,7 @@ namespace util
s << "<span class=failed_tunnel> " << "Failed</span>"; s << "<span class=failed_tunnel> " << "Failed</span>";
else if (state == i2p::tunnel::eTunnelStateExpiring) else if (state == i2p::tunnel::eTunnelStateExpiring)
s << "<span class=expiring_tunnel> " << "Exp</span>"; s << "<span class=expiring_tunnel> " << "Exp</span>";
s << " " << (int)it->GetNumSentBytes () << "<br>"; s << " " << (int)it->GetNumSentBytes () << "<br>\r\n";
s << std::endl; s << std::endl;
} }
@ -570,78 +601,78 @@ namespace util
s << "<span class=failed_tunnel> " << "Failed</span>"; s << "<span class=failed_tunnel> " << "Failed</span>";
else if (state == i2p::tunnel::eTunnelStateExpiring) else if (state == i2p::tunnel::eTunnelStateExpiring)
s << "<span class=expiring_tunnel> " << "Exp</span>"; s << "<span class=expiring_tunnel> " << "Exp</span>";
s << " " << (int)it.second->GetNumReceivedBytes () << "<br>"; s << " " << (int)it.second->GetNumReceivedBytes () << "<br>\r\n";
s << std::endl; s << std::endl;
} }
} }
void HTTPConnection::ShowTransitTunnels (std::stringstream& s) void HTTPConnection::ShowTransitTunnels (std::stringstream& s)
{ {
s << "<b>Transit tunnels:</b><br><br>"; s << "<b>Transit tunnels:</b><br>\r\n<br>\r\n";
for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ())
{ {
if (dynamic_cast<i2p::tunnel::TransitTunnelGateway *>(it.second)) if (dynamic_cast<i2p::tunnel::TransitTunnelGateway *>(it.second))
s << it.second->GetTunnelID () << "-->"; s << it.second->GetTunnelID () << "";
else if (dynamic_cast<i2p::tunnel::TransitTunnelEndpoint *>(it.second)) else if (dynamic_cast<i2p::tunnel::TransitTunnelEndpoint *>(it.second))
s << "-->" << it.second->GetTunnelID (); s << "" << it.second->GetTunnelID ();
else else
s << "-->" << it.second->GetTunnelID () << "-->"; s << "" << it.second->GetTunnelID () << "";
s << " " << it.second->GetNumTransmittedBytes () << "<br>"; s << " " << it.second->GetNumTransmittedBytes () << "<br>\r\n";
} }
} }
void HTTPConnection::ShowTransports (std::stringstream& s) void HTTPConnection::ShowTransports (std::stringstream& s)
{ {
s << "<b>Transports:</b><br><br>"; s << "<b>Transports:</b><br>\r\n<br>\r\n";
auto ntcpServer = i2p::transport::transports.GetNTCPServer (); auto ntcpServer = i2p::transport::transports.GetNTCPServer ();
if (ntcpServer) if (ntcpServer)
{ {
s << "<b>NTCP</b><br>"; s << "<b>NTCP</b><br>\r\n";
for (auto it: ntcpServer->GetNTCPSessions ()) for (auto it: ntcpServer->GetNTCPSessions ())
{ {
if (it.second && it.second->IsEstablished ()) if (it.second && it.second->IsEstablished ())
{ {
// incoming connection doesn't have remote RI // 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 ()) << ": " s << i2p::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": "
<< it.second->GetSocket ().remote_endpoint().address ().to_string (); << 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 << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<br>" << std::endl; s << "<br>\r\n" << std::endl;
} }
} }
} }
auto ssuServer = i2p::transport::transports.GetSSUServer (); auto ssuServer = i2p::transport::transports.GetSSUServer ();
if (ssuServer) if (ssuServer)
{ {
s << "<br><b>SSU</b><br>"; s << "<br>\r\n<b>SSU</b><br>\r\n";
for (auto it: ssuServer->GetSessions ()) for (auto it: ssuServer->GetSessions ())
{ {
auto endpoint = it.second->GetRemoteEndpoint (); auto endpoint = it.second->GetRemoteEndpoint ();
if (it.second->IsOutgoing ()) s << "-->"; if (it.second->IsOutgoing ()) s << "";
s << endpoint.address ().to_string () << ":" << endpoint.port (); 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 << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
if (it.second->GetRelayTag ()) if (it.second->GetRelayTag ())
s << " [itag:" << it.second->GetRelayTag () << "]"; s << " [itag:" << it.second->GetRelayTag () << "]";
s << "<br>" << std::endl; s << "<br>\r\n" << std::endl;
} }
s << "<br><b>SSU6</b><br>"; s << "<br>\r\n<b>SSU6</b><br>\r\n";
for (auto it: ssuServer->GetSessionsV6 ()) for (auto it: ssuServer->GetSessionsV6 ())
{ {
auto endpoint = it.second->GetRemoteEndpoint (); auto endpoint = it.second->GetRemoteEndpoint ();
if (it.second->IsOutgoing ()) s << "-->"; if (it.second->IsOutgoing ()) s << "";
s << endpoint.address ().to_string () << ":" << endpoint.port (); 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 << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<br>" << std::endl; s << "<br>\r\n" << std::endl;
} }
} }
} }
void HTTPConnection::ShowSAMSessions (std::stringstream& s) void HTTPConnection::ShowSAMSessions (std::stringstream& s)
{ {
s << "<b>SAM Sessions:</b><br><br>"; s << "<b>SAM Sessions:</b><br>\r\n<br>\r\n";
auto sam = i2p::client::context.GetSAMBridge (); auto sam = i2p::client::context.GetSAMBridge ();
if (sam) if (sam)
{ {
@ -649,14 +680,14 @@ namespace util
{ {
s << "<a href=/?" << HTTP_COMMAND_SAM_SESSION; s << "<a href=/?" << HTTP_COMMAND_SAM_SESSION;
s << "&" << HTTP_PARAM_SAM_SESSION_ID << "=" << it.first << ">"; s << "&" << HTTP_PARAM_SAM_SESSION_ID << "=" << it.first << ">";
s << it.first << "</a><br>" << std::endl; s << it.first << "</a><br>\r\n" << std::endl;
} }
} }
} }
void HTTPConnection::ShowSAMSession (const std::string& id, std::stringstream& s) void HTTPConnection::ShowSAMSession (const std::string& id, std::stringstream& s)
{ {
s << "<b>SAM Session:</b><br><br>"; s << "<b>SAM Session:</b><br>\r\n<br>\r\n";
auto sam = i2p::client::context.GetSAMBridge (); auto sam = i2p::client::context.GetSAMBridge ();
if (sam) if (sam)
{ {
@ -666,8 +697,8 @@ namespace util
auto& ident = session->localDestination->GetIdentHash(); auto& ident = session->localDestination->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION; s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">"; s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>" << std::endl; s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>\r\n" << std::endl;
s << "<b>Streams:</b><br>"; s << "<b>Streams:</b><br>\r\n";
for (auto it: session->sockets) for (auto it: session->sockets)
{ {
switch (it->GetSocketType ()) switch (it->GetSocketType ())
@ -685,7 +716,7 @@ namespace util
s << "unknown"; s << "unknown";
} }
s << " [" << it->GetSocket ().remote_endpoint() << "]"; s << " [" << it->GetSocket ().remote_endpoint() << "]";
s << "<br>" << std::endl; s << "<br>\r\n" << std::endl;
} }
} }
} }
@ -693,45 +724,46 @@ namespace util
void HTTPConnection::ShowI2PTunnels (std::stringstream& s) void HTTPConnection::ShowI2PTunnels (std::stringstream& s)
{ {
s << "<b>Client Tunnels:</b><br><br>"; s << "<b>Client Tunnels:</b><br>\r\n<br>\r\n";
for (auto& it: i2p::client::context.GetClientTunnels ()) for (auto& it: i2p::client::context.GetClientTunnels ())
{ {
s << it.second->GetName () << "<--"; s << it.second->GetName () << "";
auto& ident = it.second->GetLocalDestination ()->GetIdentHash(); auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION; s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">"; s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident); s << i2p::client::context.GetAddressBook ().ToAddress(ident);
s << "</a><br>"<< std::endl; s << "</a><br>\r\n"<< std::endl;
} }
s << "<br><b>Server Tunnels:</b><br><br>"; s << "<br>\r\n<b>Server Tunnels:</b><br>\r\n<br>\r\n";
for (auto& it: i2p::client::context.GetServerTunnels ()) for (auto& it: i2p::client::context.GetServerTunnels ())
{ {
s << it.second->GetName () << "-->"; s << it.second->GetName () << "";
auto& ident = it.second->GetLocalDestination ()->GetIdentHash(); auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION; s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">"; s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident); s << i2p::client::context.GetAddressBook ().ToAddress(ident);
s << "</a><br>"<< std::endl; s << ":" << it.second->GetLocalPort ();
s << "</a><br>\r\n"<< std::endl;
} }
} }
void HTTPConnection::StopAcceptingTunnels (std::stringstream& s) void HTTPConnection::StopAcceptingTunnels (std::stringstream& s)
{ {
s << "<b>Stop Accepting Tunnels:</b><br><br>"; s << "<b>Stop Accepting Tunnels:</b><br>\r\n<br>\r\n";
i2p::context.SetAcceptsTunnels (false); i2p::context.SetAcceptsTunnels (false);
s << "Accepting tunnels stopped" << std::endl; s << "Accepting tunnels stopped" << std::endl;
} }
void HTTPConnection::StartAcceptingTunnels (std::stringstream& s) void HTTPConnection::StartAcceptingTunnels (std::stringstream& s)
{ {
s << "<b>Start Accepting Tunnels:</b><br><br>"; s << "<b>Start Accepting Tunnels:</b><br>\r\n<br>\r\n";
i2p::context.SetAcceptsTunnels (true); i2p::context.SetAcceptsTunnels (true);
s << "Accepting tunnels started" << std::endl; s << "Accepting tunnels started" << std::endl;
} }
void HTTPConnection::RunPeerTest (std::stringstream& s) void HTTPConnection::RunPeerTest (std::stringstream& s)
{ {
s << "<b>Run Peer Test:</b><br><br>"; s << "<b>Run Peer Test:</b><br>\r\n<br>\r\n";
i2p::transport::transports.PeerTest (); i2p::transport::transports.PeerTest ();
s << "Peer test is running" << std::endl; s << "Peer test is running" << std::endl;
} }
@ -739,7 +771,7 @@ namespace util
void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri) 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"; 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 ()); SendToAddress (address, 80, request.c_str (), request.size ());
} }
@ -749,7 +781,7 @@ namespace util
if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination)) if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination))
{ {
LogPrint (eLogWarning, "HTTPServer: Unknown address ", address); LogPrint (eLogWarning, "HTTPServer: Unknown address ", address);
SendReply ("<html>" + itoopieImage + "<br>Unknown address " + address + "</html>", 404); SendReply ("<html>" + itoopieImage + "<br>\r\nUnknown address " + address + "</html>", 404);
return; return;
} }
@ -777,7 +809,7 @@ namespace util
SendToDestination (leaseSet, port, buf, len); SendToDestination (leaseSet, port, buf, len);
else else
// still no LeaseSet // still no LeaseSet
SendReply (leaseSet ? "<html>" + itoopieImage + "<br>Leases expired</html>" : "<html>" + itoopieImage + "LeaseSet not found</html>", 504); SendReply (leaseSet ? "<html>" + itoopieImage + "<br>\r\nLeases expired</html>" : "<html>" + itoopieImage + "LeaseSet not found</html>", 504);
} }
} }
@ -811,7 +843,7 @@ namespace util
else else
{ {
if (ecode == boost::asio::error::timed_out) if (ecode == boost::asio::error::timed_out)
SendReply ("<html>" + itoopieImage + "<br>Not responding</html>", 504); SendReply ("<html>" + itoopieImage + "<br>\r\nNot responding</html>", 504);
else if (ecode != boost::asio::error::operation_aborted) else if (ecode != boost::asio::error::operation_aborted)
Terminate (); Terminate ();
} }
@ -898,3 +930,4 @@ namespace util
} }

4
I2NPProtocol.cpp

@ -38,7 +38,7 @@ namespace i2p
SetTypeID (msgType); SetTypeID (msgType);
if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4); if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4);
SetMsgID (replyMsgID); 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 (); UpdateSize ();
UpdateChks (); UpdateChks ();
} }
@ -48,7 +48,7 @@ namespace i2p
uint32_t msgID; uint32_t msgID;
RAND_bytes ((uint8_t *)&msgID, 4); RAND_bytes ((uint8_t *)&msgID, 4);
SetMsgID (msgID); SetMsgID (msgID);
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000); SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000);
} }
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID) std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID)

1
I2PTunnel.h

@ -123,6 +123,7 @@ namespace client
const std::string& GetAddress() const { return m_Address; } const std::string& GetAddress() const { return m_Address; }
int GetPort () const { return m_Port; }; 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 boost::asio::ip::tcp::endpoint& GetEndpoint () const { return m_Endpoint; }
const char* GetName() { return m_Name.c_str (); } const char* GetName() { return m_Name.c_str (); }

2
Log.cpp

@ -65,7 +65,7 @@ void Log::SetLogLevel (const std::string& level)
LogPrint(eLogError, "Log: Unknown loglevel: ", level); LogPrint(eLogError, "Log: Unknown loglevel: ", level);
return; 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) void Log::SetLogStream (std::ostream * logStream)

33
NetDb.cpp

@ -164,20 +164,23 @@ namespace data
auto ts = r->GetTimestamp (); auto ts = r->GetTimestamp ();
r->Update (buf, len); r->Update (buf, len);
if (r->GetTimestamp () > ts) if (r->GetTimestamp () > ts)
LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase32()); LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64());
} }
else else
{ {
LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase32());
r = std::make_shared<RouterInfo> (buf, len); r = std::make_shared<RouterInfo> (buf, len);
if (!r->IsUnreachable ())
{ {
std::unique_lock<std::mutex> l(m_RouterInfosMutex); LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase64());
m_RouterInfos[r->GetIdentHash ()] = r; {
} std::unique_lock<std::mutex> l(m_RouterInfosMutex);
if (r->IsFloodfill ()) m_RouterInfos[r->GetIdentHash ()] = r;
{ }
std::unique_lock<std::mutex> l(m_FloodfillsMutex); if (r->IsFloodfill ())
m_Floodfills.push_back (r); {
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
m_Floodfills.push_back (r);
}
} }
} }
// take care about requested destination // take care about requested destination
@ -194,10 +197,10 @@ namespace data
{ {
it->second->Update (buf, len); it->second->Update (buf, len);
if (it->second->IsValid ()) if (it->second->IsValid ())
LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase32()); LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase64());
else else
{ {
LogPrint (eLogWarning, "NetDb: LeaseSet update failed: ", ident.ToBase32()); LogPrint (eLogWarning, "NetDb: LeaseSet update failed: ", ident.ToBase64());
m_LeaseSets.erase (it); m_LeaseSets.erase (it);
} }
} }
@ -206,11 +209,11 @@ namespace data
auto leaseSet = std::make_shared<LeaseSet> (buf, len); auto leaseSet = std::make_shared<LeaseSet> (buf, len);
if (leaseSet->IsValid ()) if (leaseSet->IsValid ())
{ {
LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase32()); LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase64());
m_LeaseSets[ident] = leaseSet; m_LeaseSets[ident] = leaseSet;
} }
else else
LogPrint (eLogError, "NetDb: new LeaseSet validation failed: ", ident.ToBase32()); LogPrint (eLogError, "NetDb: new LeaseSet validation failed: ", ident.ToBase64());
} }
} }
} }
@ -432,7 +435,7 @@ namespace data
auto dest = m_Requests.CreateRequest (destination, false, requestComplete); // non-exploratory auto dest = m_Requests.CreateRequest (destination, false, requestComplete); // non-exploratory
if (!dest) if (!dest)
{ {
LogPrint (eLogWarning, "NetDb: destination ", destination.ToBase32(), " is requested already"); LogPrint (eLogWarning, "NetDb: destination ", destination.ToBase64(), " is requested already");
return; return;
} }
@ -441,7 +444,7 @@ namespace data
transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
else 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); m_Requests.RequestComplete (destination, nullptr);
} }
} }

8
NetDbRequests.cpp

@ -122,15 +122,15 @@ namespace data
else else
{ {
done = true; done = true;
if (!inbound) LogPrint (eLogWarning, "No inbound tunnels"); if (!inbound) LogPrint (eLogWarning, "NetDbReq: No inbound tunnels");
if (!outbound) LogPrint (eLogWarning, "No outbound tunnels"); if (!outbound) LogPrint (eLogWarning, "NetDbReq: No outbound tunnels");
if (!nextFloodfill) LogPrint (eLogWarning, "No more floodfills"); if (!nextFloodfill) LogPrint (eLogWarning, "NetDbReq: No more floodfills");
} }
} }
else else
{ {
if (!dest->IsExploratory ()) 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; done = true;
} }
} }

2
RouterContext.cpp

@ -51,7 +51,7 @@ namespace i2p
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC
routerInfo.SetProperty ("coreVersion", I2P_VERSION); 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 ("router.version", I2P_VERSION);
routerInfo.SetProperty ("stat_uptime", "90m"); routerInfo.SetProperty ("stat_uptime", "90m");
routerInfo.CreateBuffer (m_Keys); routerInfo.CreateBuffer (m_Keys);

7
RouterInfo.cpp

@ -3,6 +3,7 @@
#include "I2PEndian.h" #include "I2PEndian.h"
#include <fstream> #include <fstream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "version.h"
#include "Crypto.h" #include "Crypto.h"
#include "Base.h" #include "Base.h"
#include "Timestamp.h" #include "Timestamp.h"
@ -243,6 +244,12 @@ namespace data
// extract caps // extract caps
if (!strcmp (key, "caps")) if (!strcmp (key, "caps"))
ExtractCaps (value); 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)) if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers))

73
SOCKS.cpp

@ -145,13 +145,14 @@ namespace proxy
void SOCKSHandler::AsyncSockRead() void SOCKSHandler::AsyncSockRead()
{ {
LogPrint(eLogDebug,"--- SOCKS async sock read"); LogPrint(eLogDebug, "SOCKS: async sock read");
if(m_sock) if (m_sock) {
m_sock->async_receive(boost::asio::buffer(m_sock_buff, socks_buffer_size), m_sock->async_receive(boost::asio::buffer(m_sock_buff, socks_buffer_size),
std::bind(&SOCKSHandler::HandleSockRecv, shared_from_this(), std::bind(&SOCKSHandler::HandleSockRecv, shared_from_this(),
std::placeholders::_1, std::placeholders::_2)); std::placeholders::_1, std::placeholders::_2));
else } else {
LogPrint(eLogError,"--- SOCKS no socket for read"); LogPrint(eLogError,"SOCKS: no socket for read");
}
} }
void SOCKSHandler::Terminate() void SOCKSHandler::Terminate()
@ -159,13 +160,13 @@ namespace proxy
if (Kill()) return; if (Kill()) return;
if (m_sock) if (m_sock)
{ {
LogPrint(eLogDebug,"--- SOCKS close sock"); LogPrint(eLogDebug, "SOCKS: closing socket");
m_sock->close(); m_sock->close();
m_sock = nullptr; m_sock = nullptr;
} }
if (m_stream) if (m_stream)
{ {
LogPrint(eLogDebug,"--- SOCKS close stream"); LogPrint(eLogDebug, "SOCKS: closing stream");
m_stream.reset (); m_stream.reset ();
} }
Done(shared_from_this()); Done(shared_from_this());
@ -216,14 +217,14 @@ namespace proxy
boost::asio::const_buffers_1 response(m_response,2); boost::asio::const_buffers_1 response(m_response,2);
if (m_authchosen == AUTH_UNACCEPTABLE) 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, boost::asio::async_write(*m_sock, response, std::bind(&SOCKSHandler::SentSocksFailed,
shared_from_this(), std::placeholders::_1)); shared_from_this(), std::placeholders::_1));
return false; return false;
} }
else 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, boost::asio::async_write(*m_sock, response, std::bind(&SOCKSHandler::SentSocksResponse,
shared_from_this(), std::placeholders::_1)); shared_from_this(), std::placeholders::_1));
return true; return true;
@ -238,12 +239,12 @@ namespace proxy
switch (m_socksv) switch (m_socksv)
{ {
case SOCKS4: 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 if (error < SOCKS4_OK) error = SOCKS4_FAIL; //Transparently map SOCKS5 errors
response = GenerateSOCKS4Response(error, m_4aip, m_port); response = GenerateSOCKS4Response(error, m_4aip, m_port);
break; break;
case SOCKS5: case SOCKS5:
LogPrint(eLogWarning,"--- SOCKS5 failed: ", error); LogPrint(eLogWarning, "SOCKS: v5 request failed: ", error);
response = GenerateSOCKS5Response(error, m_addrtype, m_address, m_port); response = GenerateSOCKS5Response(error, m_addrtype, m_address, m_port);
break; break;
} }
@ -258,11 +259,11 @@ namespace proxy
switch (m_socksv) switch (m_socksv)
{ {
case SOCKS4: case SOCKS4:
LogPrint(eLogInfo,"--- SOCKS4 connection success"); LogPrint(eLogInfo, "SOCKS: v4 connection success");
response = GenerateSOCKS4Response(SOCKS4_OK, m_4aip, m_port); response = GenerateSOCKS4Response(SOCKS4_OK, m_4aip, m_port);
break; break;
case SOCKS5: case SOCKS5:
LogPrint(eLogInfo,"--- SOCKS5 connection success"); LogPrint(eLogInfo, "SOCKS: v5 connection success");
auto s = i2p::client::context.GetAddressBook().ToAddress(GetOwner()->GetLocalDestination()->GetIdentHash()); auto s = i2p::client::context.GetAddressBook().ToAddress(GetOwner()->GetLocalDestination()->GetIdentHash());
address ad; ad.dns.FromString(s); address ad; ad.dns.FromString(s);
//HACK only 16 bits passed in port as SOCKS5 doesn't allow for more //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 ) if ( m_cmd != CMD_CONNECT )
{ {
//TODO: we need to support binds and other shit! //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); SocksRequestFailed(SOCKS5_CMD_UNSUP);
return false; return false;
} }
@ -303,10 +304,10 @@ namespace proxy
switch (m_socksv) switch (m_socksv)
{ {
case SOCKS5: case SOCKS5:
LogPrint(eLogError,"--- SOCKS5 unsupported address type: ", m_addrtype); LogPrint(eLogError, "SOCKS: v5 unsupported address type: ", m_addrtype);
break; break;
case SOCKS4: case SOCKS4:
LogPrint(eLogError,"--- SOCKS4a rejected because it's actually SOCKS4"); LogPrint(eLogError, "SOCKS: request with v4a rejected because it's actually SOCKS4");
break; break;
} }
SocksRequestFailed(SOCKS5_ADDR_UNSUP); SocksRequestFailed(SOCKS5_ADDR_UNSUP);
@ -315,7 +316,7 @@ namespace proxy
//TODO: we may want to support other domains //TODO: we may want to support other domains
if(m_addrtype == ADDR_DNS && m_address.dns.ToString().find(".i2p") == std::string::npos) 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); SocksRequestFailed(SOCKS5_ADDR_UNSUP);
return false; return false;
} }
@ -340,7 +341,7 @@ namespace proxy
EnterState(GET5_AUTHNUM); //Initialize the parser at the right position EnterState(GET5_AUTHNUM); //Initialize the parser at the right position
break; break;
default: default:
LogPrint(eLogError,"--- SOCKS rejected invalid version: ", ((int)*sock_buff)); LogPrint(eLogError, "SOCKS: rejected invalid version: ", ((int)*sock_buff));
Terminate(); Terminate();
return false; return false;
} }
@ -367,7 +368,7 @@ namespace proxy
case CMD_UDP: case CMD_UDP:
if (m_socksv == SOCKS5) break; if (m_socksv == SOCKS5) break;
default: default:
LogPrint(eLogError,"--- SOCKS invalid command: ", ((int)*sock_buff)); LogPrint(eLogError, "SOCKS: invalid command: ", ((int)*sock_buff));
SocksRequestFailed(SOCKS5_GEN_FAIL); SocksRequestFailed(SOCKS5_GEN_FAIL);
return false; return false;
} }
@ -419,7 +420,7 @@ namespace proxy
} }
if (m_address.dns.size >= max_socks_hostname_size) 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); SocksRequestFailed(SOCKS4_FAIL);
return false; return false;
} }
@ -428,7 +429,7 @@ namespace proxy
case GET5_REQUESTV: case GET5_REQUESTV:
if (*sock_buff != SOCKS5) 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); SocksRequestFailed(SOCKS5_GEN_FAIL);
return false; return false;
} }
@ -437,7 +438,7 @@ namespace proxy
case GET5_GETRSV: case GET5_GETRSV:
if ( *sock_buff != 0 ) 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); SocksRequestFailed(SOCKS5_GEN_FAIL);
return false; return false;
} }
@ -450,7 +451,7 @@ namespace proxy
case ADDR_IPV6: EnterState(GET5_IPV6); break; case ADDR_IPV6: EnterState(GET5_IPV6); break;
case ADDR_DNS : EnterState(GET5_HOST_SIZE); break; case ADDR_DNS : EnterState(GET5_HOST_SIZE); break;
default: default:
LogPrint(eLogError,"--- SOCKS5 unknown address type: ", ((int)*sock_buff)); LogPrint(eLogError, "SOCKS: v5 unknown address type: ", ((int)*sock_buff));
SocksRequestFailed(SOCKS5_GEN_FAIL); SocksRequestFailed(SOCKS5_GEN_FAIL);
return false; return false;
} }
@ -469,7 +470,7 @@ namespace proxy
if (m_parseleft == 0) EnterState(GET_PORT); if (m_parseleft == 0) EnterState(GET_PORT);
break; break;
default: default:
LogPrint(eLogError,"--- SOCKS parse state?? ", m_state); LogPrint(eLogError, "SOCKS: parse state?? ", m_state);
Terminate(); Terminate();
return false; return false;
} }
@ -487,11 +488,11 @@ namespace proxy
void SOCKSHandler::HandleSockRecv(const boost::system::error_code & ecode, std::size_t len) 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) if(ecode)
{ {
LogPrint(eLogWarning," --- SOCKS sock recv got error: ", ecode); LogPrint(eLogWarning, "SOCKS: recv got error: ", ecode);
Terminate(); Terminate();
return; return;
} }
@ -499,7 +500,7 @@ namespace proxy
{ {
if (m_state == DONE) 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, GetOwner()->CreateStream ( std::bind (&SOCKSHandler::HandleStreamRequestComplete,
shared_from_this(), std::placeholders::_1), m_address.dns.ToString(), m_port); 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) void SOCKSHandler::SentSocksFailed(const boost::system::error_code & ecode)
{ {
if (!ecode) if (ecode)
Terminate(); LogPrint (eLogError, "SOCKS: closing socket after sending failure because: ", ecode.message ());
else Terminate();
{
LogPrint (eLogError,"--- SOCKS Closing socket after sending failure because: ", ecode.message ());
Terminate();
}
} }
void SOCKSHandler::SentSocksDone(const boost::system::error_code & ecode) void SOCKSHandler::SentSocksDone(const boost::system::error_code & ecode)
@ -524,7 +521,7 @@ namespace proxy
if (!ecode) if (!ecode)
{ {
if (Kill()) return; if (Kill()) return;
LogPrint (eLogInfo,"--- SOCKS New I2PTunnel connection"); LogPrint (eLogInfo, "SOCKS: new I2PTunnel connection");
auto connection = std::make_shared<i2p::client::I2PTunnelConnection>(GetOwner(), m_sock, m_stream); auto connection = std::make_shared<i2p::client::I2PTunnelConnection>(GetOwner(), m_sock, m_stream);
GetOwner()->AddHandler (connection); GetOwner()->AddHandler (connection);
connection->I2PConnect (m_remaining_data,m_remaining_data_len); connection->I2PConnect (m_remaining_data,m_remaining_data_len);
@ -532,7 +529,7 @@ namespace proxy
} }
else else
{ {
LogPrint (eLogError,"--- SOCKS Closing socket after completion reply because: ", ecode.message ()); LogPrint (eLogError, "SOCKS: closing socket after completion reply because: ", ecode.message ());
Terminate(); Terminate();
} }
} }
@ -541,7 +538,7 @@ namespace proxy
{ {
if (ecode) 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(); Terminate();
} }
} }
@ -555,7 +552,7 @@ namespace proxy
} }
else 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); SocksRequestFailed(SOCKS5_HOST_UNREACH);
} }
} }

2
SSUSession.cpp

@ -853,7 +853,7 @@ namespace transport
{ {
if (ecode != boost::asio::error::operation_aborted) 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 (); Failed ();
} }
} }

37
Tunnel.cpp

@ -163,7 +163,7 @@ namespace tunnel
void Tunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) void Tunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> 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<std::shared_ptr<const i2p::data::IdentityEx> > Tunnel::GetPeers () const std::vector<std::shared_ptr<const i2p::data::IdentityEx> > Tunnel::GetPeers () const
@ -186,7 +186,7 @@ namespace tunnel
{ {
for (auto& it: m_Hops) for (auto& it: m_Hops)
{ {
s << "-->"; s << "";
s << i2p::data::GetIdentHashAbbreviation (it->ident->GetIdentHash ()); s << i2p::data::GetIdentHashAbbreviation (it->ident->GetIdentHash ());
} }
} }
@ -203,7 +203,7 @@ namespace tunnel
void InboundTunnel::Print (std::stringstream& s) const void InboundTunnel::Print (std::stringstream& s) const
{ {
PrintHops (s); PrintHops (s);
s << "-->" << GetTunnelID () << ":me"; s << "" << GetTunnelID () << ":me";
} }
void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg) void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg)
@ -238,14 +238,14 @@ namespace tunnel
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg) void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> 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 void OutboundTunnel::Print (std::stringstream& s) const
{ {
s << GetTunnelID () << ":me"; s << GetTunnelID () << ":me";
PrintHops (s); PrintHops (s);
s << "-->"; s << "";
} }
Tunnels tunnels; Tunnels tunnels;
@ -368,7 +368,7 @@ namespace tunnel
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex); std::unique_lock<std::mutex> l(m_TransitTunnelsMutex);
if (!m_TransitTunnels.insert (std::make_pair (tunnel->GetTunnelID (), tunnel)).second) 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; delete tunnel;
} }
} }
@ -432,7 +432,7 @@ namespace tunnel
HandleTunnelGatewayMsg (tunnel, msg); HandleTunnelGatewayMsg (tunnel, msg);
} }
else else
LogPrint (eLogWarning, "Tunnel ", tunnelID, " not found"); LogPrint (eLogWarning, "Tunnel: tunnel with id ", tunnelID, " not found");
break; break;
} }
case eI2NPVariableTunnelBuild: case eI2NPVariableTunnelBuild:
@ -442,7 +442,7 @@ namespace tunnel
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
break; break;
default: default:
LogPrint (eLogError, "Tunnel: Unexpected messsage type ", (int)typeID); LogPrint (eLogError, "Tunnel: unexpected messsage type ", (int) typeID);
} }
msg = m_Queue.Get (); msg = m_Queue.Get ();
@ -475,7 +475,7 @@ namespace tunnel
{ {
if (!tunnel) if (!tunnel)
{ {
LogPrint (eLogError, "Missing tunnel for TunnelGateway"); LogPrint (eLogError, "Tunnel: missing tunnel for gateway");
return; return;
} }
const uint8_t * payload = msg->GetPayload (); const uint8_t * payload = msg->GetPayload ();
@ -484,7 +484,7 @@ namespace tunnel
msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE; msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE;
msg->len = msg->offset + len; msg->len = msg->offset + len;
auto typeID = msg->GetTypeID (); 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) if (IsRouterInfoMsg (msg) || typeID == eI2NPDatabaseSearchReply)
// transit DatabaseStore my contain new/updated RI // transit DatabaseStore my contain new/updated RI
@ -521,7 +521,7 @@ namespace tunnel
case eTunnelStatePending: case eTunnelStatePending:
if (ts > tunnel->GetCreationTime () + TUNNEL_CREATION_TIMEOUT) 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 // update stats
auto config = tunnel->GetTunnelConfig (); auto config = tunnel->GetTunnelConfig ();
if (config) if (config)
@ -546,7 +546,7 @@ namespace tunnel
it++; it++;
break; break;
case eTunnelStateBuildFailed: 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); it = pendingTunnels.erase (it);
m_NumFailedTunnelCreations++; m_NumFailedTunnelCreations++;
break; break;
@ -571,7 +571,7 @@ namespace tunnel
auto tunnel = *it; auto tunnel = *it;
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) 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 (); auto pool = tunnel->GetTunnelPool ();
if (pool) if (pool)
pool->TunnelExpired (tunnel); pool->TunnelExpired (tunnel);
@ -602,7 +602,7 @@ namespace tunnel
auto inboundTunnel = GetNextInboundTunnel (); auto inboundTunnel = GetNextInboundTunnel ();
auto router = i2p::data::netdb.GetRandomRouter (); auto router = i2p::data::netdb.GetRandomRouter ();
if (!inboundTunnel || !router) return; if (!inboundTunnel || !router) return;
LogPrint (eLogDebug, "Creating one hop outbound tunnel"); LogPrint (eLogDebug, "Tunnel: creating one hop outbound tunnel");
CreateTunnel<OutboundTunnel> ( CreateTunnel<OutboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () }, std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () },
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()) inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ())
@ -619,7 +619,7 @@ namespace tunnel
auto tunnel = it->second; auto tunnel = it->second;
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) 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 (); auto pool = tunnel->GetTunnelPool ();
if (pool) if (pool)
pool->TunnelExpired (tunnel); pool->TunnelExpired (tunnel);
@ -647,7 +647,7 @@ namespace tunnel
if (m_InboundTunnels.empty ()) if (m_InboundTunnels.empty ())
{ {
LogPrint (eLogDebug, "Creating zero hops inbound tunnel..."); LogPrint (eLogDebug, "Tunnel: Creating zero hops inbound tunnel");
CreateZeroHopsInboundTunnel (); CreateZeroHopsInboundTunnel ();
if (!m_ExploratoryPool) if (!m_ExploratoryPool)
{ {
@ -661,7 +661,7 @@ namespace tunnel
{ {
// trying to create one more inbound tunnel // trying to create one more inbound tunnel
auto router = i2p::data::netdb.GetRandomRouter (); auto router = i2p::data::netdb.GetRandomRouter ();
LogPrint (eLogDebug, "Creating one hop inbound tunnel..."); LogPrint (eLogDebug, "Tunnel: creating one hop inbound tunnel");
CreateTunnel<InboundTunnel> ( CreateTunnel<InboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () }) std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () })
); );
@ -676,7 +676,7 @@ namespace tunnel
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{ {
auto tmp = it->second; auto tmp = it->second;
LogPrint (eLogDebug, "Transit tunnel ", tmp->GetTunnelID (), " expired"); LogPrint (eLogDebug, "Tunnel: Transit tunnel with id ", tmp->GetTunnelID (), " expired");
{ {
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex); std::unique_lock<std::mutex> l(m_TransitTunnelsMutex);
it = m_TransitTunnels.erase (it); it = m_TransitTunnels.erase (it);
@ -787,3 +787,4 @@ namespace tunnel
} }
} }
} }

2
TunnelEndpoint.cpp

@ -226,7 +226,7 @@ namespace tunnel
void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg) void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg)
{ {
auto typeID = msg.data->GetTypeID (); 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) switch (msg.deliveryType)
{ {
case eDeliveryTypeLocal: case eDeliveryTypeLocal:

2
TunnelPool.cpp

@ -203,7 +203,7 @@ namespace tunnel
{ {
for (auto it: m_Tests) 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 test failed again with another tunnel we consider it failed
if (it.second.first) if (it.second.first)
{ {

45
util.cpp

@ -70,12 +70,10 @@ namespace util
namespace config namespace config
{ {
std::map<std::string, std::string> mapArgs; std::map<std::string, std::string> mapArgs;
std::map<std::string, std::vector<std::string> > mapMultiArgs;
void OptionParser(int argc, const char* const argv[]) void OptionParser(int argc, const char* const argv[])
{ {
mapArgs.clear(); mapArgs.clear();
mapMultiArgs.clear();
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
std::string strKey (argv[i]); std::string strKey (argv[i]);
@ -96,7 +94,6 @@ namespace config
break; break;
mapArgs[strKey] = strValue; mapArgs[strKey] = strValue;
mapMultiArgs[strKey].push_back(strValue);
} }
BOOST_FOREACH(PAIRTYPE(const std::string,std::string)& entry, mapArgs) BOOST_FOREACH(PAIRTYPE(const std::string,std::string)& entry, mapArgs)
@ -127,6 +124,26 @@ namespace config
return atoi(mapArgs[strArg].c_str()); return atoi(mapArgs[strArg].c_str());
return nDefault; 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<std::string> 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 namespace filesystem
@ -196,28 +213,6 @@ namespace filesystem
return pathTunnelsConfigFile; return pathTunnelsConfigFile;
} }
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet)
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good())
return; // No i2pd.conf file is OK
std::set<std::string> 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];
}
mapMultiSettingsRet[strKey].push_back(it->value[0]);
}
}
boost::filesystem::path GetDefaultDataDir() boost::filesystem::path GetDefaultDataDir()
{ {
// Windows < Vista: C:\Documents and Settings\Username\.i2pd // Windows < Vista: C:\Documents and Settings\Username\.i2pd

6
util.h

@ -16,12 +16,10 @@ namespace util
{ {
namespace config namespace config
{ {
extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
void OptionParser(int argc, const char* const argv[]); void OptionParser(int argc, const char* const argv[]);
int GetArg(const std::string& strArg, int nDefault); int GetArg(const std::string& strArg, int nDefault);
std::string GetArg(const std::string& strArg, const std::string& strDefault); std::string GetArg(const std::string& strArg, const std::string& strDefault);
const char* GetCharArg(const std::string& strArg, const std::string& nDefault); void ReadConfigFile(boost::filesystem::path path);
} }
namespace filesystem namespace filesystem
@ -34,8 +32,6 @@ namespace util
boost::filesystem::path GetDefaultDataDir(); boost::filesystem::path GetDefaultDataDir();
boost::filesystem::path GetConfigFile(); boost::filesystem::path GetConfigFile();
boost::filesystem::path GetTunnelsConfigFile(); boost::filesystem::path GetTunnelsConfigFile();
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
boost::filesystem::path GetCertificatesDir(); boost::filesystem::path GetCertificatesDir();
} }

1
version.h

@ -12,6 +12,7 @@
#define I2PD_VERSION_PATCH 0 #define I2PD_VERSION_PATCH 0
#define I2PD_VERSION MAKE_VERSION(I2PD_VERSION_MAJOR, I2PD_VERSION_MINOR, I2PD_VERSION_MICRO) #define I2PD_VERSION MAKE_VERSION(I2PD_VERSION_MAJOR, I2PD_VERSION_MINOR, I2PD_VERSION_MICRO)
#define VERSION I2PD_VERSION #define VERSION I2PD_VERSION
#define I2PD_NET_ID 2
#define I2P_VERSION_MAJOR 0 #define I2P_VERSION_MAJOR 0
#define I2P_VERSION_MINOR 9 #define I2P_VERSION_MINOR 9

Loading…
Cancel
Save