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. 211
      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 @@ -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");

31
ClientContext.cpp

@ -45,31 +45,38 @@ namespace client @@ -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 ();
}
@ -310,7 +317,9 @@ namespace client @@ -310,7 +317,9 @@ namespace client
while (comma != std::string::npos);
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 ();
else
LogPrint (eLogError, "Clients: I2P server tunnel for destination ", m_AddressBook.ToAddress(localDestination->GetIdentHash ()), " already exists");

3
ClientContext.h

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
#define CLIENT_CONTEXT_H__
#include <map>
#include <tuple>
#include <mutex>
#include <memory>
#include "Destination.h"
@ -74,7 +75,7 @@ namespace client @@ -74,7 +75,7 @@ namespace client
i2p::proxy::HTTPProxy * m_HttpProxy;
i2p::proxy::SOCKSProxy * m_SocksProxy;
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;
BOBCommandChannel * m_BOBCommandChannel;

23
Daemon.cpp

@ -63,9 +63,9 @@ namespace i2p @@ -63,9 +63,9 @@ 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());
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
LogPrint(eLogInfo, "i2pd v", VERSION, " starting");
LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string());
i2p::util::config::ReadConfigFile(i2p::util::filesystem::GetConfigFile());
isDaemon = i2p::util::config::GetArg("-daemon", 0);
isLogging = i2p::util::config::GetArg("-log", 1);
@ -120,8 +120,10 @@ namespace i2p @@ -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<i2p::util::HTTPServer>(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<i2p::util::HTTPServer>(new i2p::util::HTTPServer(httpAddr, httpPort));
d.httpServer->Start();
LogPrint(eLogInfo, "Daemon: starting NetDB");
@ -140,12 +142,13 @@ namespace i2p @@ -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<i2p::client::I2PControlService>(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<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
d.m_I2PControlService->Start ();
}
return true;

6
Daemon.h

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

211
HTTPServer.cpp

@ -357,45 +357,47 @@ namespace util @@ -357,45 +357,47 @@ namespace util
{
std::stringstream s;
// Html5 head start
s << "<!DOCTYPE html>\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 << "<link rel='shortcut icon' href='" + itoopieFavicon + "'>";
s << "<title>Purple I2P " << VERSION " Webconsole</title>";
s << "<style>";
s << "<!DOCTYPE html>\r\n<html lang=\"en\">"; // TODO: Add support for locale.
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 + "'>\r\n";
s << "<title>Purple I2P " << VERSION " Webconsole</title>\r\n";
s << "<style>\r\n";
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:hover {color: #FAFAFA; background: #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 << ".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 << ".expiring_tunnel {color: #d3ae3f;}";
s << ".failed_tunnel {color: #d33f3f;}";
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=wrapper>";
s << "<div class=left>";
s << "<a href=/>Main page</a><br><br>";
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATIONS << ">Local destinations</a><br>";
s << "<a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a><br>";
s << "<a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a><br>";
s << "<a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a><br><br>";
s << "<a href=/?" << HTTP_COMMAND_I2P_TUNNELS << ">I2P tunnels</a><br>";
s << "<div class=left>\r\n";
s << "<a href=/>Main page</a><br>\r\n<br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATIONS << ">Local destinations</a><br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a><br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a><br>\r\n";
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>\r\n";
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 ())
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
s << "<a href=/?" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << ">Start accepting tunnels</a><br><br>";
s << "<a href=/?" << HTTP_COMMAND_RUN_PEER_TEST << ">Run peer test</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>\r\n<br>\r\n";
s << "</div><div class=right>";
if (address.length () > 1)
HandleCommand (address.substr (2), s);
else
FillContent (s);
s << "</div></div></body></html>";
s << "</div></div>\r\n</body>\r\n</html>";
SendReply (s.str ());
}
@ -403,7 +405,7 @@ namespace util @@ -403,7 +405,7 @@ namespace util
{
s << "<b>Uptime:</b> " << boost::posix_time::to_simple_string (
boost::posix_time::time_duration (boost::posix_time::seconds (
i2p::context.GetUptime ()))) << "<br>";
i2p::context.GetUptime ()))) << "<br>\r\n";
s << "<b>Status:</b> ";
switch (i2p::context.GetStatus ())
{
@ -412,14 +414,14 @@ namespace util @@ -412,14 +414,14 @@ namespace util
case eRouterStatusFirewalled: s << "Firewalled"; break;
default: s << "Unknown";
}
s << "<br>";
s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>";
s << "<br>\r\n";
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 << " (" << 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 << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>";
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br><br>";
s << "<b>Our external address:</b>" << "<br>" ;
s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>\r\n";
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br>\r\n<br>\r\n";
s << "<b>Our external address:</b>" << "<br>\r\n" ;
for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
{
switch (address.transportStyle)
@ -439,11 +441,11 @@ namespace util @@ -439,11 +441,11 @@ namespace util
default:
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>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)
@ -486,30 +488,31 @@ namespace util @@ -486,30 +488,31 @@ namespace util
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 ())
{
auto ident = it.second->GetIdentHash ();;
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
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)
{
s << "<b>Local Destination:</b><br><br>";
s << "<b>Local Destination:</b><br>\r\n<br>\r\n";
i2p::data::IdentHash ident;
ident.FromBase32 (b32);
auto dest = i2p::client::context.FindLocalDestination (ident);
if (dest)
{
s << "<b>Base64:</b><br>" << dest->GetIdentity ()->ToBase64 () << "<br><br>";
s << "<b>LeaseSets:</b> <i>" << dest->GetNumRemoteLeaseSets () << "</i><br>";
s << "<b>Base64:</b><br>\r\n<textarea readonly=\"readonly\" cols=\"64\" rows=\"1\" wrap=\"off\">";
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 ();
if (pool)
{
s << "<b>Tunnels:</b><br>";
s << "<b>Tunnels:</b><br>\r\n";
for (auto it: pool->GetOutboundTunnels ())
{
it->Print (s);
@ -518,7 +521,7 @@ namespace util @@ -518,7 +521,7 @@ namespace util
s << " " << "Failed";
else if (state == i2p::tunnel::eTunnelStateExpiring)
s << " " << "Exp";
s << "<br>" << std::endl;
s << "<br>\r\n" << std::endl;
}
for (auto it: pool->GetInboundTunnels ())
{
@ -528,28 +531,56 @@ namespace util @@ -528,28 +531,56 @@ namespace util
s << " " << "Failed";
else if (state == i2p::tunnel::eTunnelStateExpiring)
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 ())
{
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>"<< std::endl;
}
s << "<tr>";
s << "<td>" << it.first << "</td>";
s << "<td>" << i2p::client::context.GetAddressBook ().ToAddress(it.second->GetRemoteIdentity ()) << "</td>";
s << "<td>" << it.second->GetNumSentBytes () << "</td>";
s << "<td>" << it.second->GetNumReceivedBytes () << "</td>";
s << "<td>" << it.second->GetSendQueueSize () << "</td>";
s << "<td>" << it.second->GetReceiveQueueSize () << "</td>";
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)
{
s << "<b>Tunnels:</b><br><br>";
s << "<b>Queue size:</b>" << i2p::tunnel::tunnels.GetQueueSize () << "<br>";
s << "<b>Tunnels:</b><br>\r\n<br>\r\n";
s << "<b>Queue size:</b> " << i2p::tunnel::tunnels.GetQueueSize () << "<br>\r\n";
for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ())
{
it->Print (s);
@ -558,7 +589,7 @@ namespace util @@ -558,7 +589,7 @@ namespace util
s << "<span class=failed_tunnel> " << "Failed</span>";
else if (state == i2p::tunnel::eTunnelStateExpiring)
s << "<span class=expiring_tunnel> " << "Exp</span>";
s << " " << (int)it->GetNumSentBytes () << "<br>";
s << " " << (int)it->GetNumSentBytes () << "<br>\r\n";
s << std::endl;
}
@ -570,78 +601,78 @@ namespace util @@ -570,78 +601,78 @@ namespace util
s << "<span class=failed_tunnel> " << "Failed</span>";
else if (state == i2p::tunnel::eTunnelStateExpiring)
s << "<span class=expiring_tunnel> " << "Exp</span>";
s << " " << (int)it.second->GetNumReceivedBytes () << "<br>";
s << " " << (int)it.second->GetNumReceivedBytes () << "<br>\r\n";
s << std::endl;
}
}
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 ())
{
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))
s << "-->" << it.second->GetTunnelID ();
s << "" << it.second->GetTunnelID ();
else
s << "-->" << it.second->GetTunnelID () << "-->";
s << " " << it.second->GetNumTransmittedBytes () << "<br>";
s << "" << it.second->GetTunnelID () << "";
s << " " << it.second->GetNumTransmittedBytes () << "<br>\r\n";
}
}
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 ();
if (ntcpServer)
{
s << "<b>NTCP</b><br>";
s << "<b>NTCP</b><br>\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 << "<br>" << std::endl;
s << "<br>\r\n" << std::endl;
}
}
}
auto ssuServer = i2p::transport::transports.GetSSUServer ();
if (ssuServer)
{
s << "<br><b>SSU</b><br>";
s << "<br>\r\n<b>SSU</b><br>\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 << "<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 ())
{
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 << "<br>" << std::endl;
s << "<br>\r\n" << std::endl;
}
}
}
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 ();
if (sam)
{
@ -649,14 +680,14 @@ namespace util @@ -649,14 +680,14 @@ namespace util
{
s << "<a href=/?" << HTTP_COMMAND_SAM_SESSION;
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)
{
s << "<b>SAM Session:</b><br><br>";
s << "<b>SAM Session:</b><br>\r\n<br>\r\n";
auto sam = i2p::client::context.GetSAMBridge ();
if (sam)
{
@ -666,8 +697,8 @@ namespace util @@ -666,8 +697,8 @@ namespace util
auto& ident = session->localDestination->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>" << std::endl;
s << "<b>Streams:</b><br>";
s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>\r\n" << std::endl;
s << "<b>Streams:</b><br>\r\n";
for (auto it: session->sockets)
{
switch (it->GetSocketType ())
@ -685,7 +716,7 @@ namespace util @@ -685,7 +716,7 @@ namespace util
s << "unknown";
}
s << " [" << it->GetSocket ().remote_endpoint() << "]";
s << "<br>" << std::endl;
s << "<br>\r\n" << std::endl;
}
}
}
@ -693,45 +724,46 @@ namespace util @@ -693,45 +724,46 @@ namespace util
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 ())
{
s << it.second->GetName () << "<--";
s << it.second->GetName () << "";
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
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 ())
{
s << it.second->GetName () << "-->";
s << it.second->GetName () << "";
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
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)
{
s << "<b>Stop Accepting Tunnels:</b><br><br>";
s << "<b>Stop Accepting Tunnels:</b><br>\r\n<br>\r\n";
i2p::context.SetAcceptsTunnels (false);
s << "Accepting tunnels stopped" << std::endl;
}
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);
s << "Accepting tunnels started" << std::endl;
}
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 ();
s << "Peer test is running" << std::endl;
}
@ -739,7 +771,7 @@ namespace util @@ -739,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 ());
}
@ -749,7 +781,7 @@ namespace util @@ -749,7 +781,7 @@ namespace util
if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination))
{
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;
}
@ -777,7 +809,7 @@ namespace util @@ -777,7 +809,7 @@ namespace util
SendToDestination (leaseSet, port, buf, len);
else
// 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 @@ -811,7 +843,7 @@ namespace util
else
{
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)
Terminate ();
}
@ -898,3 +930,4 @@ namespace util @@ -898,3 +930,4 @@ namespace util
}

4
I2NPProtocol.cpp

@ -38,7 +38,7 @@ namespace i2p @@ -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 @@ -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<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID)

1
I2PTunnel.h

@ -123,6 +123,7 @@ namespace client @@ -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 (); }

2
Log.cpp

@ -65,7 +65,7 @@ void Log::SetLogLevel (const std::string& level) @@ -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)

33
NetDb.cpp

@ -164,20 +164,23 @@ namespace data @@ -164,20 +164,23 @@ 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
{
LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase32());
r = std::make_shared<RouterInfo> (buf, len);
if (!r->IsUnreachable ())
{
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
m_RouterInfos[r->GetIdentHash ()] = r;
}
if (r->IsFloodfill ())
{
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
m_Floodfills.push_back (r);
LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase64());
{
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
m_RouterInfos[r->GetIdentHash ()] = r;
}
if (r->IsFloodfill ())
{
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
m_Floodfills.push_back (r);
}
}
}
// take care about requested destination
@ -194,10 +197,10 @@ namespace data @@ -194,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);
}
}
@ -206,11 +209,11 @@ namespace data @@ -206,11 +209,11 @@ namespace data
auto leaseSet = std::make_shared<LeaseSet> (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());
}
}
}
@ -432,7 +435,7 @@ namespace data @@ -432,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;
}
@ -441,7 +444,7 @@ namespace data @@ -441,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);
}
}

8
NetDbRequests.cpp

@ -122,15 +122,15 @@ namespace data @@ -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;
}
}

2
RouterContext.cpp

@ -51,7 +51,7 @@ namespace i2p @@ -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);

7
RouterInfo.cpp

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include "I2PEndian.h"
#include <fstream>
#include <boost/lexical_cast.hpp>
#include "version.h"
#include "Crypto.h"
#include "Base.h"
#include "Timestamp.h"
@ -243,6 +244,12 @@ namespace data @@ -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))

73
SOCKS.cpp

@ -145,13 +145,14 @@ namespace proxy @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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<i2p::client::I2PTunnelConnection>(GetOwner(), m_sock, m_stream);
GetOwner()->AddHandler (connection);
connection->I2PConnect (m_remaining_data,m_remaining_data_len);
@ -532,7 +529,7 @@ namespace proxy @@ -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 @@ -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 @@ -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);
}
}

2
SSUSession.cpp

@ -853,7 +853,7 @@ namespace transport @@ -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 ();
}
}

37
Tunnel.cpp

@ -163,7 +163,7 @@ namespace tunnel @@ -163,7 +163,7 @@ namespace tunnel
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
@ -186,7 +186,7 @@ namespace tunnel @@ -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 @@ -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<i2p::I2NPMessage> msg)
@ -238,14 +238,14 @@ namespace tunnel @@ -238,14 +238,14 @@ namespace tunnel
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
{
s << GetTunnelID () << ":me";
PrintHops (s);
s << "-->";
s << "";
}
Tunnels tunnels;
@ -368,7 +368,7 @@ namespace tunnel @@ -368,7 +368,7 @@ namespace tunnel
std::unique_lock<std::mutex> 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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<OutboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () },
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ())
@ -619,7 +619,7 @@ namespace tunnel @@ -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 @@ -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 @@ -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<InboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () })
);
@ -676,7 +676,7 @@ namespace tunnel @@ -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<std::mutex> l(m_TransitTunnelsMutex);
it = m_TransitTunnels.erase (it);
@ -787,3 +787,4 @@ namespace tunnel @@ -787,3 +787,4 @@ namespace tunnel
}
}
}

2
TunnelEndpoint.cpp

@ -226,7 +226,7 @@ namespace tunnel @@ -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:

2
TunnelPool.cpp

@ -203,7 +203,7 @@ namespace tunnel @@ -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)
{

45
util.cpp

@ -70,12 +70,10 @@ namespace util @@ -70,12 +70,10 @@ namespace util
namespace config
{
std::map<std::string, std::string> mapArgs;
std::map<std::string, std::vector<std::string> > 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 @@ -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)
@ -127,6 +124,26 @@ namespace config @@ -127,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<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
@ -196,28 +213,6 @@ namespace filesystem @@ -196,28 +213,6 @@ namespace filesystem
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()
{
// Windows < Vista: C:\Documents and Settings\Username\.i2pd

6
util.h

@ -16,12 +16,10 @@ namespace util @@ -16,12 +16,10 @@ namespace util
{
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[]);
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);
void ReadConfigFile(boost::filesystem::path path);
}
namespace filesystem
@ -34,8 +32,6 @@ namespace util @@ -34,8 +32,6 @@ namespace util
boost::filesystem::path GetDefaultDataDir();
boost::filesystem::path GetConfigFile();
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();
}

1
version.h

@ -12,6 +12,7 @@ @@ -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

Loading…
Cancel
Save