mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-29 04:07:49 +02:00
Logging: consistent capitalization
This commit is contained in:
parent
ee275105a0
commit
a92628b2c6
4 changed files with 117 additions and 117 deletions
|
@ -118,16 +118,16 @@ namespace util
|
|||
|
||||
i2p::log::Logger().SetLogLevel(loglevel);
|
||||
if (logstream) {
|
||||
LogPrint(eLogInfo, "Log: will send messages to std::ostream");
|
||||
LogPrint(eLogInfo, "Log: Sending messages to std::ostream");
|
||||
i2p::log::Logger().SendTo (logstream);
|
||||
} else if (logs == "file") {
|
||||
if (logfile == "")
|
||||
logfile = i2p::fs::DataDirPath("i2pd.log");
|
||||
LogPrint(eLogInfo, "Log: will send messages to ", logfile);
|
||||
LogPrint(eLogInfo, "Log: Sending messages to ", logfile);
|
||||
i2p::log::Logger().SendTo (logfile);
|
||||
#ifndef _WIN32
|
||||
} else if (logs == "syslog") {
|
||||
LogPrint(eLogInfo, "Log: will send messages to syslog");
|
||||
LogPrint(eLogInfo, "Log: Sending messages to syslog");
|
||||
i2p::log::Logger().SendTo("i2pd", LOG_DAEMON);
|
||||
#endif
|
||||
} else {
|
||||
|
@ -135,9 +135,9 @@ namespace util
|
|||
}
|
||||
|
||||
LogPrint(eLogNone, "i2pd v", VERSION, " starting");
|
||||
LogPrint(eLogDebug, "FS: main config file: ", config);
|
||||
LogPrint(eLogDebug, "FS: data directory: ", datadir);
|
||||
LogPrint(eLogDebug, "FS: certificates directory: ", certsdir);
|
||||
LogPrint(eLogDebug, "FS: Main config file: ", config);
|
||||
LogPrint(eLogDebug, "FS: Data directory: ", datadir);
|
||||
LogPrint(eLogDebug, "FS: Certificates directory: ", certsdir);
|
||||
|
||||
bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation);
|
||||
bool aesni; i2p::config::GetOption("cpuext.aesni", aesni);
|
||||
|
@ -204,7 +204,7 @@ namespace util
|
|||
uint16_t port; i2p::config::GetOption("port", port);
|
||||
if (!i2p::config::IsDefault("port"))
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: accepting incoming connections at port ", port);
|
||||
LogPrint(eLogInfo, "Daemon: Accepting incoming connections at port ", port);
|
||||
i2p::context.UpdatePort (port);
|
||||
}
|
||||
i2p::context.SetSupportsV6 (ipv6);
|
||||
|
@ -252,7 +252,7 @@ namespace util
|
|||
|
||||
bool isFloodfill; i2p::config::GetOption("floodfill", isFloodfill);
|
||||
if (isFloodfill) {
|
||||
LogPrint(eLogInfo, "Daemon: router will be floodfill");
|
||||
LogPrint(eLogInfo, "Daemon: Router configured as floodfill");
|
||||
i2p::context.SetFloodfill (true);
|
||||
}
|
||||
else
|
||||
|
@ -267,7 +267,7 @@ namespace util
|
|||
if (bandwidth[0] >= 'K' && bandwidth[0] <= 'X')
|
||||
{
|
||||
i2p::context.SetBandwidth (bandwidth[0]);
|
||||
LogPrint(eLogInfo, "Daemon: bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps");
|
||||
LogPrint(eLogInfo, "Daemon: Bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -275,23 +275,23 @@ namespace util
|
|||
if (value > 0)
|
||||
{
|
||||
i2p::context.SetBandwidth (value);
|
||||
LogPrint(eLogInfo, "Daemon: bandwidth set to ", i2p::context.GetBandwidthLimit (), " KBps");
|
||||
LogPrint(eLogInfo, "Daemon: Bandwidth set to ", i2p::context.GetBandwidthLimit (), " KBps");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: unexpected bandwidth ", bandwidth, ". Set to 'low'");
|
||||
LogPrint(eLogInfo, "Daemon: Unexpected bandwidth ", bandwidth, ". Set to 'low'");
|
||||
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isFloodfill)
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: floodfill bandwidth set to 'extra'");
|
||||
LogPrint(eLogInfo, "Daemon: Floodfill bandwidth set to 'extra'");
|
||||
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_EXTRA_BANDWIDTH2);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: bandwidth set to 'low'");
|
||||
LogPrint(eLogInfo, "Daemon: Bandwidth set to 'low'");
|
||||
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2);
|
||||
}
|
||||
|
||||
|
@ -301,12 +301,12 @@ namespace util
|
|||
std::string family; i2p::config::GetOption("family", family);
|
||||
i2p::context.SetFamily (family);
|
||||
if (family.length () > 0)
|
||||
LogPrint(eLogInfo, "Daemon: family set to ", family);
|
||||
LogPrint(eLogInfo, "Daemon: Router family set to ", family);
|
||||
|
||||
bool trust; i2p::config::GetOption("trust.enabled", trust);
|
||||
if (trust)
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: explicit trust enabled");
|
||||
LogPrint(eLogInfo, "Daemon: Explicit trust enabled");
|
||||
std::string fam; i2p::config::GetOption("trust.family", fam);
|
||||
std::string routers; i2p::config::GetOption("trust.routers", routers);
|
||||
bool restricted = false;
|
||||
|
@ -336,18 +336,18 @@ namespace util
|
|||
pos = comma + 1;
|
||||
}
|
||||
while (comma != std::string::npos);
|
||||
LogPrint(eLogInfo, "Daemon: setting restricted routes to use ", idents.size(), " trusted routers");
|
||||
LogPrint(eLogInfo, "Daemon: Setting restricted routes to use ", idents.size(), " trusted routers");
|
||||
i2p::transport::transports.RestrictRoutesToRouters(idents);
|
||||
restricted = idents.size() > 0;
|
||||
}
|
||||
if(!restricted)
|
||||
LogPrint(eLogError, "Daemon: no trusted routers of families specified");
|
||||
LogPrint(eLogError, "Daemon: No trusted routers of families specified");
|
||||
}
|
||||
|
||||
bool hidden; i2p::config::GetOption("trust.hidden", hidden);
|
||||
if (hidden)
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: using hidden mode");
|
||||
LogPrint(eLogInfo, "Daemon: Hidden mode enabled");
|
||||
i2p::data::netdb.SetHidden(true);
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ namespace util
|
|||
bool Daemon_Singleton::start()
|
||||
{
|
||||
i2p::log::Logger().Start();
|
||||
LogPrint(eLogInfo, "Daemon: starting NetDB");
|
||||
LogPrint(eLogInfo, "Daemon: Starting NetDB");
|
||||
i2p::data::netdb.Start();
|
||||
|
||||
bool upnp; i2p::config::GetOption("upnp.enabled", upnp);
|
||||
|
@ -379,9 +379,9 @@ namespace util
|
|||
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
||||
bool ssu; i2p::config::GetOption("ssu", ssu);
|
||||
bool checkInReserved; i2p::config::GetOption("reservedrange", checkInReserved);
|
||||
LogPrint(eLogInfo, "Daemon: starting Transports");
|
||||
if(!ssu) LogPrint(eLogInfo, "Daemon: ssu disabled");
|
||||
if(!ntcp2) LogPrint(eLogInfo, "Daemon: ntcp2 disabled");
|
||||
LogPrint(eLogInfo, "Daemon: Starting Transports");
|
||||
if(!ssu) LogPrint(eLogInfo, "Daemon: SSU disabled");
|
||||
if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled");
|
||||
|
||||
i2p::transport::transports.SetCheckReserved(checkInReserved);
|
||||
i2p::transport::transports.Start(ntcp2, ssu);
|
||||
|
@ -389,7 +389,7 @@ namespace util
|
|||
LogPrint(eLogInfo, "Daemon: Transports started");
|
||||
else
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: failed to start Transports");
|
||||
LogPrint(eLogError, "Daemon: Failed to start transports");
|
||||
/** shut down netdb right away */
|
||||
i2p::transport::transports.Stop();
|
||||
i2p::data::netdb.Stop();
|
||||
|
@ -400,7 +400,7 @@ namespace util
|
|||
if (http) {
|
||||
std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
|
||||
uint16_t httpPort; i2p::config::GetOption("http.port", httpPort);
|
||||
LogPrint(eLogInfo, "Daemon: starting webconsole at ", httpAddr, ":", httpPort);
|
||||
LogPrint(eLogInfo, "Daemon: Starting webconsole at ", httpAddr, ":", httpPort);
|
||||
try
|
||||
{
|
||||
d.httpServer = std::unique_ptr<i2p::http::HTTPServer>(new i2p::http::HTTPServer(httpAddr, httpPort));
|
||||
|
@ -408,16 +408,16 @@ namespace util
|
|||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogError, "Daemon: failed to start webconsole: ", ex.what ());
|
||||
LogPrint (eLogError, "Daemon: Failed to start webconsole: ", ex.what ());
|
||||
ThrowFatal ("Unable to start webconsole at ", httpAddr, ":", httpPort, ": ", ex.what ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LogPrint(eLogInfo, "Daemon: starting Tunnels");
|
||||
LogPrint(eLogInfo, "Daemon: Starting tunnels");
|
||||
i2p::tunnel::tunnels.Start();
|
||||
|
||||
LogPrint(eLogInfo, "Daemon: starting Client");
|
||||
LogPrint(eLogInfo, "Daemon: Starting client");
|
||||
i2p::client::context.Start ();
|
||||
|
||||
// I2P Control Protocol
|
||||
|
@ -425,7 +425,7 @@ namespace util
|
|||
if (i2pcontrol) {
|
||||
std::string i2pcpAddr; i2p::config::GetOption("i2pcontrol.address", i2pcpAddr);
|
||||
uint16_t i2pcpPort; i2p::config::GetOption("i2pcontrol.port", i2pcpPort);
|
||||
LogPrint(eLogInfo, "Daemon: starting I2PControl at ", i2pcpAddr, ":", i2pcpPort);
|
||||
LogPrint(eLogInfo, "Daemon: Starting I2PControl at ", i2pcpAddr, ":", i2pcpPort);
|
||||
try
|
||||
{
|
||||
d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
|
||||
|
@ -433,7 +433,7 @@ namespace util
|
|||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogError, "Daemon: failed to start I2PControl: ", ex.what ());
|
||||
LogPrint (eLogError, "Daemon: Failed to start I2PControl: ", ex.what ());
|
||||
ThrowFatal ("Unable to start I2PControl service at ", i2pcpAddr, ":", i2pcpPort, ": ", ex.what ());
|
||||
}
|
||||
}
|
||||
|
@ -442,10 +442,10 @@ namespace util
|
|||
|
||||
bool Daemon_Singleton::stop()
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: shutting down");
|
||||
LogPrint(eLogInfo, "Daemon: stopping Client");
|
||||
LogPrint(eLogInfo, "Daemon: Shutting down");
|
||||
LogPrint(eLogInfo, "Daemon: Stopping client");
|
||||
i2p::client::context.Stop();
|
||||
LogPrint(eLogInfo, "Daemon: stopping Tunnels");
|
||||
LogPrint(eLogInfo, "Daemon: Stopping tunnels");
|
||||
i2p::tunnel::tunnels.Stop();
|
||||
|
||||
if (d.UPnP)
|
||||
|
@ -460,18 +460,18 @@ namespace util
|
|||
d.m_NTPSync = nullptr;
|
||||
}
|
||||
|
||||
LogPrint(eLogInfo, "Daemon: stopping Transports");
|
||||
LogPrint(eLogInfo, "Daemon: Stopping transports");
|
||||
i2p::transport::transports.Stop();
|
||||
LogPrint(eLogInfo, "Daemon: stopping NetDB");
|
||||
LogPrint(eLogInfo, "Daemon: Stopping NetDB");
|
||||
i2p::data::netdb.Stop();
|
||||
if (d.httpServer) {
|
||||
LogPrint(eLogInfo, "Daemon: stopping HTTP Server");
|
||||
LogPrint(eLogInfo, "Daemon: Stopping HTTP Server");
|
||||
d.httpServer->Stop();
|
||||
d.httpServer = nullptr;
|
||||
}
|
||||
if (d.m_I2PControlService)
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: stopping I2PControl");
|
||||
LogPrint(eLogInfo, "Daemon: Stopping I2PControl");
|
||||
d.m_I2PControlService->Stop ();
|
||||
d.m_I2PControlService = nullptr;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace i2p
|
|||
|
||||
if (pid < 0) // error
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: could not fork: ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Could not fork: ", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -81,13 +81,13 @@ namespace i2p
|
|||
int sid = setsid();
|
||||
if (sid < 0)
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: could not create process group.");
|
||||
LogPrint(eLogError, "Daemon: Could not create process group.");
|
||||
return false;
|
||||
}
|
||||
std::string d = i2p::fs::GetDataDir();
|
||||
if (chdir(d.c_str()) != 0)
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: could not chdir: ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Could not chdir: ", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -102,14 +102,14 @@ namespace i2p
|
|||
uint16_t nfiles; i2p::config::GetOption("limits.openfiles", nfiles);
|
||||
getrlimit(RLIMIT_NOFILE, &limit);
|
||||
if (nfiles == 0) {
|
||||
LogPrint(eLogInfo, "Daemon: using system limit in ", limit.rlim_cur, " max open files");
|
||||
LogPrint(eLogInfo, "Daemon: Using system limit in ", limit.rlim_cur, " max open files");
|
||||
} else if (nfiles <= limit.rlim_max) {
|
||||
limit.rlim_cur = nfiles;
|
||||
if (setrlimit(RLIMIT_NOFILE, &limit) == 0) {
|
||||
LogPrint(eLogInfo, "Daemon: set max number of open files to ",
|
||||
LogPrint(eLogInfo, "Daemon: Set max number of open files to ",
|
||||
nfiles, " (system limit is ", limit.rlim_max, ")");
|
||||
} else {
|
||||
LogPrint(eLogError, "Daemon: can't set max number of open files: ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Can't set max number of open files: ", strerror(errno));
|
||||
}
|
||||
} else {
|
||||
LogPrint(eLogError, "Daemon: limits.openfiles exceeds system limit: ", limit.rlim_max);
|
||||
|
@ -122,11 +122,11 @@ namespace i2p
|
|||
if (cfsize <= limit.rlim_max) {
|
||||
limit.rlim_cur = cfsize;
|
||||
if (setrlimit(RLIMIT_CORE, &limit) != 0) {
|
||||
LogPrint(eLogError, "Daemon: can't set max size of coredump: ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Can't set max size of coredump: ", strerror(errno));
|
||||
} else if (cfsize == 0) {
|
||||
LogPrint(eLogInfo, "Daemon: coredumps disabled");
|
||||
} else {
|
||||
LogPrint(eLogInfo, "Daemon: set max size of core files to ", cfsize / 1024, "Kb");
|
||||
LogPrint(eLogInfo, "Daemon: Set max size of core files to ", cfsize / 1024, "Kb");
|
||||
}
|
||||
} else {
|
||||
LogPrint(eLogError, "Daemon: limits.coresize exceeds system limit: ", limit.rlim_max);
|
||||
|
@ -143,14 +143,14 @@ namespace i2p
|
|||
pidFH = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
|
||||
if (pidFH < 0)
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Could not create pid file ", pidfile, ": ", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef ANDROID
|
||||
if (lockf(pidFH, F_TLOCK, 0) != 0)
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Could not lock pid file ", pidfile, ": ", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@ -159,7 +159,7 @@ namespace i2p
|
|||
ftruncate(pidFH, 0);
|
||||
if (write(pidFH, pid, strlen(pid)) < 0)
|
||||
{
|
||||
LogPrint(eLogError, "Daemon: could not write pidfile: ", strerror(errno));
|
||||
LogPrint(eLogError, "Daemon: Could not write pidfile: ", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,28 +27,28 @@ namespace tunnel
|
|||
void Path::Add (std::shared_ptr<const i2p::data::RouterInfo> r)
|
||||
{
|
||||
if (r)
|
||||
{
|
||||
{
|
||||
peers.push_back (r->GetRouterIdentity ());
|
||||
if (r->GetVersion () < i2p::data::NETDB_MIN_SHORT_TUNNEL_BUILD_VERSION ||
|
||||
if (r->GetVersion () < i2p::data::NETDB_MIN_SHORT_TUNNEL_BUILD_VERSION ||
|
||||
r->GetRouterIdentity ()->GetCryptoKeyType () != i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)
|
||||
isShort = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Path::Reverse ()
|
||||
{
|
||||
std::reverse (peers.begin (), peers.end ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TunnelPool::TunnelPool (int numInboundHops, int numOutboundHops, int numInboundTunnels, int numOutboundTunnels):
|
||||
m_NumInboundHops (numInboundHops), m_NumOutboundHops (numOutboundHops),
|
||||
m_NumInboundTunnels (numInboundTunnels), m_NumOutboundTunnels (numOutboundTunnels),
|
||||
m_IsActive (true), m_CustomPeerSelector(nullptr)
|
||||
{
|
||||
if (m_NumInboundTunnels > TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY)
|
||||
if (m_NumInboundTunnels > TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY)
|
||||
m_NumInboundTunnels = TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY;
|
||||
if (m_NumOutboundTunnels > TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY)
|
||||
m_NumOutboundTunnels = TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY;
|
||||
if (m_NumOutboundTunnels > TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY)
|
||||
m_NumOutboundTunnels = TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY;
|
||||
m_NextManageTime = i2p::util::GetSecondsSinceEpoch () + rand () % TUNNEL_POOL_MANAGE_INTERVAL;
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,10 @@ namespace tunnel
|
|||
if (it->IsSlow () && !slowTunnel)
|
||||
slowTunnel = it;
|
||||
else
|
||||
{
|
||||
{
|
||||
v.push_back (it);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (slowTunnel && (int)v.size () < (num/2+1))
|
||||
|
@ -202,8 +202,8 @@ namespace tunnel
|
|||
{
|
||||
if (it->IsEstablished () && it != excluded)
|
||||
{
|
||||
if (it->IsSlow () || (HasLatencyRequirement() && it->LatencyIsKnown() &&
|
||||
!it->LatencyFitsRange(m_MinLatency, m_MaxLatency)))
|
||||
if (it->IsSlow () || (HasLatencyRequirement() && it->LatencyIsKnown() &&
|
||||
!it->LatencyFitsRange(m_MinLatency, m_MaxLatency)))
|
||||
{
|
||||
i++; skipped = true;
|
||||
continue;
|
||||
|
@ -213,7 +213,7 @@ namespace tunnel
|
|||
}
|
||||
if (i > ind && tunnel) break;
|
||||
}
|
||||
if (!tunnel && skipped)
|
||||
if (!tunnel && skipped)
|
||||
{
|
||||
ind = rand () % (tunnels.size ()/2 + 1), i = 0;
|
||||
for (const auto& it: tunnels)
|
||||
|
@ -270,12 +270,12 @@ namespace tunnel
|
|||
if (!num && !m_OutboundTunnels.empty () && m_NumOutboundHops > 0)
|
||||
{
|
||||
for (auto it: m_OutboundTunnels)
|
||||
{
|
||||
{
|
||||
CreatePairedInboundTunnel (it);
|
||||
num++;
|
||||
if (num >= m_NumInboundTunnels) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = num; i < m_NumInboundTunnels; i++)
|
||||
CreateInboundTunnel ();
|
||||
|
||||
|
@ -293,7 +293,7 @@ namespace tunnel
|
|||
|
||||
for (auto& it: tests)
|
||||
{
|
||||
LogPrint (eLogWarning, "Tunnels: test of tunnel ", 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)
|
||||
{
|
||||
|
@ -357,19 +357,19 @@ namespace tunnel
|
|||
void TunnelPool::ManageTunnels (uint64_t ts)
|
||||
{
|
||||
if (ts > m_NextManageTime)
|
||||
{
|
||||
{
|
||||
CreateTunnels ();
|
||||
TestTunnels ();
|
||||
m_NextManageTime = ts + TUNNEL_POOL_MANAGE_INTERVAL + (rand () % TUNNEL_POOL_MANAGE_INTERVAL)/2;
|
||||
}
|
||||
}
|
||||
|
||||
m_NextManageTime = ts + TUNNEL_POOL_MANAGE_INTERVAL + (rand () % TUNNEL_POOL_MANAGE_INTERVAL)/2;
|
||||
}
|
||||
}
|
||||
|
||||
void TunnelPool::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
||||
{
|
||||
if (m_LocalDestination)
|
||||
m_LocalDestination->ProcessGarlicMessage (msg);
|
||||
else
|
||||
LogPrint (eLogWarning, "Tunnels: local destination doesn't exist, dropped");
|
||||
LogPrint (eLogWarning, "Tunnels: Local destination doesn't exist, dropped");
|
||||
}
|
||||
|
||||
void TunnelPool::ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg)
|
||||
|
@ -394,23 +394,23 @@ namespace tunnel
|
|||
if (found)
|
||||
{
|
||||
uint64_t dlt = i2p::util::GetMillisecondsSinceEpoch () - timestamp;
|
||||
LogPrint (eLogDebug, "Tunnels: test of ", msgID, " successful. ", dlt, " milliseconds");
|
||||
LogPrint (eLogDebug, "Tunnels: Test of ", msgID, " successful. ", dlt, " milliseconds");
|
||||
uint64_t latency = dlt / 2;
|
||||
// restore from test failed state if any
|
||||
if (test.first)
|
||||
{
|
||||
{
|
||||
if (test.first->GetState () == eTunnelStateTestFailed)
|
||||
test.first->SetState (eTunnelStateEstablished);
|
||||
// update latency
|
||||
test.first->AddLatencySample(latency);
|
||||
}
|
||||
}
|
||||
if (test.second)
|
||||
{
|
||||
{
|
||||
if (test.second->GetState () == eTunnelStateTestFailed)
|
||||
test.second->SetState (eTunnelStateEstablished);
|
||||
// update latency
|
||||
test.second->AddLatencySample(latency);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -424,8 +424,8 @@ namespace tunnel
|
|||
bool TunnelPool::IsExploratory () const
|
||||
{
|
||||
return i2p::tunnel::tunnels.GetExploratoryPool () == shared_from_this ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop, bool reverse) const
|
||||
{
|
||||
auto hop = IsExploratory () ? i2p::data::netdb.GetRandomRouter (prevHop, reverse):
|
||||
|
@ -453,7 +453,7 @@ namespace tunnel
|
|||
(inbound && i2p::transport::transports.GetNumPeers () > 25))
|
||||
{
|
||||
auto r = i2p::transport::transports.GetRandomPeer ();
|
||||
if (r && !r->GetProfile ()->IsBad () &&
|
||||
if (r && !r->GetProfile ()->IsBad () &&
|
||||
(numHops > 1 || (r->IsV4 () && (!inbound || r->IsReachable ())))) // first inbound must be reachable
|
||||
{
|
||||
prevHop = r;
|
||||
|
@ -466,10 +466,10 @@ namespace tunnel
|
|||
{
|
||||
auto hop = nextHop (prevHop, inbound);
|
||||
if (!hop && !i) // if no suitable peer found for first hop, try already connected
|
||||
{
|
||||
{
|
||||
LogPrint (eLogInfo, "Tunnels: Can't select first hop for a tunnel. Trying already connected");
|
||||
hop = i2p::transport::transports.GetRandomPeer ();
|
||||
}
|
||||
}
|
||||
if (!hop)
|
||||
{
|
||||
LogPrint (eLogError, "Tunnels: Can't select next hop for ", prevHop->GetIdentHashBase64 ());
|
||||
|
@ -480,7 +480,7 @@ namespace tunnel
|
|||
{
|
||||
auto hop1 = nextHop (prevHop, true);
|
||||
if (hop1) hop = hop1;
|
||||
}
|
||||
}
|
||||
prevHop = hop;
|
||||
path.Add (hop);
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ namespace tunnel
|
|||
{
|
||||
int numHops = isInbound ? m_NumInboundHops : m_NumOutboundHops;
|
||||
if (numHops > (int)m_ExplicitPeers->size ()) numHops = m_ExplicitPeers->size ();
|
||||
if (!numHops) return false;
|
||||
if (!numHops) return false;
|
||||
for (int i = 0; i < numHops; i++)
|
||||
{
|
||||
auto& ident = (*m_ExplicitPeers)[i];
|
||||
|
@ -592,8 +592,8 @@ namespace tunnel
|
|||
// TODO: implement it better
|
||||
tunnel = tunnels.CreateOutboundTunnel (config, inboundTunnel->GetTunnelPool ());
|
||||
tunnel->SetTunnelPool (shared_from_this ());
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
tunnel = tunnels.CreateOutboundTunnel (config, shared_from_this ());
|
||||
if (tunnel && tunnel->IsEstablished ()) // zero hops
|
||||
TunnelCreated (tunnel);
|
||||
|
@ -638,7 +638,7 @@ namespace tunnel
|
|||
{
|
||||
LogPrint (eLogDebug, "Tunnels: Creating paired inbound tunnel...");
|
||||
auto tunnel = tunnels.CreateInboundTunnel (
|
||||
m_NumOutboundHops > 0 ? std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers ()) : nullptr,
|
||||
m_NumOutboundHops > 0 ? std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers ()) : nullptr,
|
||||
shared_from_this (), outboundTunnel);
|
||||
if (tunnel->IsEstablished ()) // zero hops
|
||||
TunnelCreated (tunnel);
|
||||
|
|
|
@ -191,13 +191,13 @@ namespace proxy
|
|||
|
||||
void SOCKSHandler::AsyncSockRead()
|
||||
{
|
||||
LogPrint(eLogDebug, "SOCKS: async sock read");
|
||||
LogPrint(eLogDebug, "SOCKS: async socket 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");
|
||||
LogPrint(eLogError,"SOCKS: No socket for read");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,19 +206,19 @@ namespace proxy
|
|||
if (Kill()) return;
|
||||
if (m_sock)
|
||||
{
|
||||
LogPrint(eLogDebug, "SOCKS: closing socket");
|
||||
LogPrint(eLogDebug, "SOCKS: Closing socket");
|
||||
m_sock->close();
|
||||
m_sock = nullptr;
|
||||
}
|
||||
if (m_upstreamSock)
|
||||
{
|
||||
LogPrint(eLogDebug, "SOCKS: closing upstream socket");
|
||||
LogPrint(eLogDebug, "SOCKS: Closing upstream socket");
|
||||
m_upstreamSock->close();
|
||||
m_upstreamSock = nullptr;
|
||||
}
|
||||
if (m_stream)
|
||||
{
|
||||
LogPrint(eLogDebug, "SOCKS: closing stream");
|
||||
LogPrint(eLogDebug, "SOCKS: Closing stream");
|
||||
m_stream.reset ();
|
||||
}
|
||||
Done(shared_from_this());
|
||||
|
@ -386,7 +386,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;
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ namespace proxy
|
|||
LogPrint(eLogError, "SOCKS: v5 unsupported address type: ", m_addrtype);
|
||||
break;
|
||||
case SOCKS4:
|
||||
LogPrint(eLogError, "SOCKS: request with v4a rejected because it's actually SOCKS4");
|
||||
LogPrint(eLogError, "SOCKS: Request with v4a rejected because it's actually SOCKS4");
|
||||
break;
|
||||
}
|
||||
SocksRequestFailed(SOCKS5_ADDR_UNSUP);
|
||||
|
@ -426,7 +426,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;
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ namespace proxy
|
|||
[[fallthrough]];
|
||||
#endif
|
||||
default:
|
||||
LogPrint(eLogError, "SOCKS: invalid command: ", ((int)*sock_buff));
|
||||
LogPrint(eLogError, "SOCKS: Invalid command: ", ((int)*sock_buff));
|
||||
SocksRequestFailed(SOCKS5_GEN_FAIL);
|
||||
return false;
|
||||
}
|
||||
|
@ -576,10 +576,10 @@ namespace proxy
|
|||
|
||||
void SOCKSHandler::HandleSockRecv(const boost::system::error_code & ecode, std::size_t len)
|
||||
{
|
||||
LogPrint(eLogDebug, "SOCKS: received ", len, " bytes");
|
||||
LogPrint(eLogDebug, "SOCKS: Received ", len, " bytes");
|
||||
if(ecode)
|
||||
{
|
||||
LogPrint(eLogWarning, "SOCKS: recv got error: ", ecode);
|
||||
LogPrint(eLogWarning, "SOCKS: Receive error: ", ecode);
|
||||
Terminate();
|
||||
return;
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ namespace proxy
|
|||
if (m_state == READY)
|
||||
{
|
||||
const std::string addr = m_address.dns.ToString();
|
||||
LogPrint(eLogInfo, "SOCKS: requested ", addr, ":" , m_port);
|
||||
LogPrint(eLogInfo, "SOCKS: Requested ", addr, ":" , m_port);
|
||||
const size_t addrlen = addr.size();
|
||||
// does it end with .i2p?
|
||||
if ( addr.rfind(".i2p") == addrlen - 4) {
|
||||
|
@ -612,7 +612,7 @@ namespace proxy
|
|||
void SOCKSHandler::SentSocksFailed(const boost::system::error_code & ecode)
|
||||
{
|
||||
if (ecode)
|
||||
LogPrint (eLogError, "SOCKS: closing socket after sending failure because: ", ecode.message ());
|
||||
LogPrint (eLogError, "SOCKS: Closing socket after sending failure because: ", ecode.message ());
|
||||
Terminate();
|
||||
}
|
||||
|
||||
|
@ -621,7 +621,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);
|
||||
|
@ -629,7 +629,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();
|
||||
}
|
||||
}
|
||||
|
@ -638,7 +638,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();
|
||||
}
|
||||
}
|
||||
|
@ -652,14 +652,14 @@ namespace proxy
|
|||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogError, "SOCKS: error when creating the stream, check the previous warnings for more info");
|
||||
LogPrint (eLogError, "SOCKS: Error creating stream, check previous warnings for more info");
|
||||
SocksRequestFailed(SOCKS5_HOST_UNREACH);
|
||||
}
|
||||
}
|
||||
|
||||
void SOCKSHandler::ForwardSOCKS()
|
||||
{
|
||||
LogPrint(eLogInfo, "SOCKS: forwarding to upstream");
|
||||
LogPrint(eLogInfo, "SOCKS: Forwarding to upstream");
|
||||
EnterState(UPSTREAM_RESOLVE);
|
||||
boost::asio::ip::tcp::resolver::query q(m_UpstreamProxyAddress, std::to_string(m_UpstreamProxyPort));
|
||||
m_proxy_resolver.async_resolve(q, std::bind(&SOCKSHandler::HandleUpstreamResolved, shared_from_this(),
|
||||
|
@ -668,12 +668,12 @@ namespace proxy
|
|||
|
||||
void SOCKSHandler::AsyncUpstreamSockRead()
|
||||
{
|
||||
LogPrint(eLogDebug, "SOCKS: async upstream sock read");
|
||||
LogPrint(eLogDebug, "SOCKS: async upstream socket read");
|
||||
if (m_upstreamSock) {
|
||||
m_upstreamSock->async_read_some(boost::asio::buffer(m_upstream_response, SOCKS_UPSTREAM_SOCKS4A_REPLY_SIZE),
|
||||
std::bind(&SOCKSHandler::HandleUpstreamSockRecv, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
||||
} else {
|
||||
LogPrint(eLogError, "SOCKS: no upstream socket for read");
|
||||
LogPrint(eLogError, "SOCKS: No upstream socket for read");
|
||||
SocksRequestFailed(SOCKS5_GEN_FAIL);
|
||||
}
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ namespace proxy
|
|||
// we are trying to handshake but it failed
|
||||
SocksRequestFailed(SOCKS5_NET_UNREACH);
|
||||
} else {
|
||||
LogPrint(eLogError, "SOCKS: bad state when reading from upstream: ", (int) m_state);
|
||||
LogPrint(eLogError, "SOCKS: Bad state when reading from upstream: ", (int) m_state);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -694,7 +694,7 @@ namespace proxy
|
|||
|
||||
void SOCKSHandler::SocksUpstreamSuccess()
|
||||
{
|
||||
LogPrint(eLogInfo, "SOCKS: upstream success");
|
||||
LogPrint(eLogInfo, "SOCKS: Upstream success");
|
||||
boost::asio::const_buffers_1 response(nullptr, 0);
|
||||
switch (m_socksv)
|
||||
{
|
||||
|
@ -734,7 +734,7 @@ namespace proxy
|
|||
SocksUpstreamSuccess();
|
||||
} else {
|
||||
// upstream failure
|
||||
LogPrint(eLogError, "SOCKS: upstream proxy failure: ", (int) resp);
|
||||
LogPrint(eLogError, "SOCKS: Upstream proxy failure: ", (int) resp);
|
||||
// TODO: runtime error?
|
||||
SocksRequestFailed(SOCKS5_GEN_FAIL);
|
||||
}
|
||||
|
@ -744,30 +744,30 @@ namespace proxy
|
|||
}
|
||||
} else {
|
||||
// invalid state
|
||||
LogPrint(eLogError, "SOCKS: invalid state reading from upstream: ", (int) m_state);
|
||||
LogPrint(eLogError, "SOCKS: Invalid state reading from upstream: ", (int) m_state);
|
||||
}
|
||||
}
|
||||
|
||||
void SOCKSHandler::SendUpstreamRequest()
|
||||
{
|
||||
LogPrint(eLogInfo, "SOCKS: negotiating with upstream proxy");
|
||||
LogPrint(eLogInfo, "SOCKS: Negotiating with upstream proxy");
|
||||
EnterState(UPSTREAM_HANDSHAKE);
|
||||
if (m_upstreamSock) {
|
||||
boost::asio::write(*m_upstreamSock, GenerateUpstreamRequest());
|
||||
AsyncUpstreamSockRead();
|
||||
} else {
|
||||
LogPrint(eLogError, "SOCKS: no upstream socket to send handshake to");
|
||||
LogPrint(eLogError, "SOCKS: No upstream socket to send handshake to");
|
||||
}
|
||||
}
|
||||
|
||||
void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr)
|
||||
{
|
||||
if (ecode) {
|
||||
LogPrint(eLogWarning, "SOCKS: could not connect to upstream proxy: ", ecode.message());
|
||||
LogPrint(eLogWarning, "SOCKS: Could not connect to upstream proxy: ", ecode.message());
|
||||
SocksRequestFailed(SOCKS5_NET_UNREACH);
|
||||
return;
|
||||
}
|
||||
LogPrint(eLogInfo, "SOCKS: connected to upstream proxy");
|
||||
LogPrint(eLogInfo, "SOCKS: Connected to upstream proxy");
|
||||
SendUpstreamRequest();
|
||||
}
|
||||
|
||||
|
@ -775,11 +775,11 @@ namespace proxy
|
|||
{
|
||||
if (ecode) {
|
||||
// error resolving
|
||||
LogPrint(eLogWarning, "SOCKS: upstream proxy", m_UpstreamProxyAddress, " not resolved: ", ecode.message());
|
||||
LogPrint(eLogWarning, "SOCKS: Upstream proxy", m_UpstreamProxyAddress, " not resolved: ", ecode.message());
|
||||
SocksRequestFailed(SOCKS5_NET_UNREACH);
|
||||
return;
|
||||
}
|
||||
LogPrint(eLogInfo, "SOCKS: upstream proxy resolved");
|
||||
LogPrint(eLogInfo, "SOCKS: Upstream proxy resolved");
|
||||
EnterState(UPSTREAM_CONNECT);
|
||||
auto & service = GetOwner()->GetService();
|
||||
m_upstreamSock = std::make_shared<boost::asio::ip::tcp::socket>(service);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue