From cc1e8e3dcf2996c3d89dcd7ba6d40ae98e25cff0 Mon Sep 17 00:00:00 2001 From: dr|z3d Date: Fri, 20 Aug 2021 02:19:57 +0000 Subject: [PATCH] Logging: more capitalization; update TorBrowser UA to current --- Win32/Win32NetState.cpp | 4 +- daemon/I2PControl.cpp | 40 +++--- daemon/UPnP.cpp | 26 ++-- libi2pd/NTCP2.cpp | 64 ++++----- libi2pd_client/ClientContext.cpp | 60 ++++---- libi2pd_client/HTTPProxy.cpp | 44 +++--- libi2pd_client/I2CP.cpp | 192 +++++++++++++------------- libi2pd_client/I2PService.cpp | 24 ++-- libi2pd_client/I2PTunnel.cpp | 134 +++++++++--------- libi2pd_client/MatchedDestination.cpp | 14 +- libi2pd_client/SAM.cpp | 180 ++++++++++++------------ 11 files changed, 391 insertions(+), 391 deletions(-) diff --git a/Win32/Win32NetState.cpp b/Win32/Win32NetState.cpp index dd4dd08c..5c56711d 100644 --- a/Win32/Win32NetState.cpp +++ b/Win32/Win32NetState.cpp @@ -32,7 +32,7 @@ void SubscribeToEvents() Result = pNetworkListManager->IsConnectedToInternet(&IsConnect); if (SUCCEEDED(Result)) { i2p::transport::transports.SetOnline (true); - LogPrint(eLogInfo, "NetState: current state: ", IsConnect == VARIANT_TRUE ? "connected" : "disconnected"); + LogPrint(eLogInfo, "NetState: Current state: ", IsConnect == VARIANT_TRUE ? "connected" : "disconnected"); } Result = pNetworkListManager->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPContainer); @@ -79,7 +79,7 @@ void UnSubscribeFromEvents() } catch (std::exception& ex) { - LogPrint (eLogError, "NetState: received exception: ", ex.what ()); + LogPrint (eLogError, "NetState: Received exception: ", ex.what ()); } } diff --git a/daemon/I2PControl.cpp b/daemon/I2PControl.cpp index 73dde618..e1f9a103 100644 --- a/daemon/I2PControl.cpp +++ b/daemon/I2PControl.cpp @@ -48,10 +48,10 @@ namespace client if (i2pcp_key.at(0) != '/') i2pcp_key = i2p::fs::DataDirPath(i2pcp_key); if (!i2p::fs::Exists (i2pcp_crt) || !i2p::fs::Exists (i2pcp_key)) { - LogPrint (eLogInfo, "I2PControl: creating new certificate for control connection"); + LogPrint (eLogInfo, "I2PControl: Creating new certificate for control connection"); CreateCertificate (i2pcp_crt.c_str(), i2pcp_key.c_str()); } else { - LogPrint(eLogDebug, "I2PControl: using cert from ", i2pcp_crt); + LogPrint(eLogDebug, "I2PControl: Using cert from ", i2pcp_crt); } m_SSLContext.set_options (boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use); m_SSLContext.use_certificate_file (i2pcp_crt, boost::asio::ssl::context::pem); @@ -142,7 +142,7 @@ namespace client try { m_Service.run (); } catch (std::exception& ex) { - LogPrint (eLogError, "I2PControl: runtime exception: ", ex.what ()); + LogPrint (eLogError, "I2PControl: Runtime exception: ", ex.what ()); } } } @@ -160,10 +160,10 @@ namespace client Accept (); if (ecode) { - LogPrint (eLogError, "I2PControl: accept error: ", ecode.message ()); + LogPrint (eLogError, "I2PControl: Accept error: ", ecode.message ()); return; } - LogPrint (eLogDebug, "I2PControl: new request from ", socket->lowest_layer ().remote_endpoint ()); + LogPrint (eLogDebug, "I2PControl: New request from ", socket->lowest_layer ().remote_endpoint ()); Handshake (socket); } @@ -176,7 +176,7 @@ namespace client void I2PControlService::HandleHandshake (const boost::system::error_code& ecode, std::shared_ptr socket) { if (ecode) { - LogPrint (eLogError, "I2PControl: handshake error: ", ecode.message ()); + LogPrint (eLogError, "I2PControl: Handshake error: ", ecode.message ()); return; } //std::this_thread::sleep_for (std::chrono::milliseconds(5)); @@ -202,7 +202,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "I2PControl: read error: ", ecode.message ()); + LogPrint (eLogError, "I2PControl: Read error: ", ecode.message ()); return; } else @@ -225,7 +225,7 @@ namespace client } if (ss.eof ()) { - LogPrint (eLogError, "I2PControl: malformed request, HTTP header expected"); + LogPrint (eLogError, "I2PControl: Malformed request, HTTP header expected"); return; // TODO: } std::streamoff rem = contentLength + ss.tellg () - bytes_transferred; // more bytes to read @@ -250,7 +250,7 @@ namespace client } else { - LogPrint (eLogWarning, "I2PControl: unknown method ", method); + LogPrint (eLogWarning, "I2PControl: Unknown method ", method); response << "{\"id\":null,\"error\":"; response << "{\"code\":-32601,\"message\":\"Method not found\"},"; response << "\"jsonrpc\":\"2.0\"}"; @@ -259,7 +259,7 @@ namespace client } catch (std::exception& ex) { - LogPrint (eLogError, "I2PControl: exception when handle request: ", ex.what ()); + LogPrint (eLogError, "I2PControl: Exception when handle request: ", ex.what ()); std::ostringstream response; response << "{\"id\":null,\"error\":"; response << "{\"code\":-32700,\"message\":\"" << ex.what () << "\"},"; @@ -268,7 +268,7 @@ namespace client } catch (...) { - LogPrint (eLogError, "I2PControl: handle request unknown exception"); + LogPrint (eLogError, "I2PControl: Handle request unknown exception"); } } } @@ -329,7 +329,7 @@ namespace client std::shared_ptr socket, std::shared_ptr buf) { if (ecode) { - LogPrint (eLogError, "I2PControl: write error: ", ecode.message ()); + LogPrint (eLogError, "I2PControl: Write error: ", ecode.message ()); } } @@ -379,7 +379,7 @@ namespace client void I2PControlService::PasswordHandler (const std::string& value) { - LogPrint (eLogWarning, "I2PControl: new password=", value, ", to make it persistent you should update your config!"); + LogPrint (eLogWarning, "I2PControl: New password=", value, ", to make it persistent you should update your config!"); m_Password = value; m_Tokens.clear (); } @@ -395,8 +395,8 @@ namespace client auto it1 = m_RouterInfoHandlers.find (it->first); if (it1 != m_RouterInfoHandlers.end ()) { - if (!first) results << ","; - else first = false; + if (!first) results << ","; + else first = false; (this->*(it1->second))(results); } else @@ -577,25 +577,25 @@ namespace client // save cert if ((f = fopen (crt_path, "wb")) != NULL) { - LogPrint (eLogInfo, "I2PControl: saving new cert to ", crt_path); + LogPrint (eLogInfo, "I2PControl: Saving new cert to ", crt_path); PEM_write_X509 (f, x509); fclose (f); } else { - LogPrint (eLogError, "I2PControl: can't write cert: ", strerror(errno)); + LogPrint (eLogError, "I2PControl: Can't write cert: ", strerror(errno)); } // save key if ((f = fopen (key_path, "wb")) != NULL) { - LogPrint (eLogInfo, "I2PControl: saving cert key to ", key_path); + LogPrint (eLogInfo, "I2PControl: Saving cert key to ", key_path); PEM_write_PrivateKey (f, pkey, NULL, NULL, 0, NULL, NULL); fclose (f); } else { - LogPrint (eLogError, "I2PControl: can't write key: ", strerror(errno)); + LogPrint (eLogError, "I2PControl: Can't write key: ", strerror(errno)); } X509_free (x509); } else { - LogPrint (eLogError, "I2PControl: can't create RSA key for certificate"); + LogPrint (eLogError, "I2PControl: Can't create RSA key for certificate"); } EVP_PKEY_free (pkey); } diff --git a/daemon/UPnP.cpp b/daemon/UPnP.cpp index 25e24bb5..fe6a565e 100644 --- a/daemon/UPnP.cpp +++ b/daemon/UPnP.cpp @@ -29,7 +29,7 @@ namespace transport { if (m_IsRunning) { - LogPrint(eLogInfo, "UPnP: stopping"); + LogPrint(eLogInfo, "UPnP: Stopping"); m_IsRunning = false; m_Timer.cancel (); m_Service.stop (); @@ -46,7 +46,7 @@ namespace transport void UPnP::Start() { m_IsRunning = true; - LogPrint(eLogInfo, "UPnP: starting"); + LogPrint(eLogInfo, "UPnP: Starting"); m_Service.post (std::bind (&UPnP::Discover, this)); std::unique_lock l(m_StartedMutex); m_Thread.reset (new std::thread (std::bind (&UPnP::Run, this))); @@ -72,7 +72,7 @@ namespace transport } catch (std::exception& ex) { - LogPrint (eLogError, "UPnP: runtime exception: ", ex.what ()); + LogPrint (eLogError, "UPnP: Runtime exception: ", ex.what ()); PortMapping (); } } @@ -106,7 +106,7 @@ namespace transport if (isError) { - LogPrint (eLogError, "UPnP: unable to discover Internet Gateway Devices: error ", err); + LogPrint (eLogError, "UPnP: Unable to discover Internet Gateway Devices: error ", err); return; } @@ -117,22 +117,22 @@ namespace transport err = UPNP_GetExternalIPAddress (m_upnpUrls.controlURL, m_upnpData.first.servicetype, m_externalIPAddress); if(err != UPNPCOMMAND_SUCCESS) { - LogPrint (eLogError, "UPnP: unable to get external address: error ", err); + LogPrint (eLogError, "UPnP: Unable to get external address: error ", err); return; } else { - LogPrint (eLogError, "UPnP: found Internet Gateway Device ", m_upnpUrls.controlURL); + LogPrint (eLogError, "UPnP: Found Internet Gateway Device ", m_upnpUrls.controlURL); if (!m_externalIPAddress[0]) { - LogPrint (eLogError, "UPnP: found Internet Gateway Device doesn't know our external address"); + LogPrint (eLogError, "UPnP: Found Internet Gateway Device doesn't know our external address"); return; } } } else { - LogPrint (eLogError, "UPnP: unable to find valid Internet Gateway Device: error ", err); + LogPrint (eLogError, "UPnP: Unable to find valid Internet Gateway Device: error ", err); return; } @@ -183,7 +183,7 @@ namespace transport err = CheckMapping (strPort.c_str (), strType.c_str ()); if (err != UPNPCOMMAND_SUCCESS) // if mapping not found { - LogPrint (eLogDebug, "UPnP: possibly port ", strPort, " is not forwarded: return code ", err); + LogPrint (eLogDebug, "UPnP: Port ", strPort, " is possibly not forwarded: return code ", err); #if ((MINIUPNPC_API_VERSION >= 8) || defined (UPNPDISCOVER_SUCCESS)) err = UPNP_AddPortMapping (m_upnpUrls.controlURL, m_upnpData.first.servicetype, strPort.c_str (), strPort.c_str (), m_NetworkAddr, strDesc.c_str (), strType.c_str (), NULL, NULL); @@ -192,18 +192,18 @@ namespace transport #endif if (err != UPNPCOMMAND_SUCCESS) { - LogPrint (eLogError, "UPnP: port forwarding to ", m_NetworkAddr, ":", strPort, " failed: return code ", err); + LogPrint (eLogError, "UPnP: Port forwarding to ", m_NetworkAddr, ":", strPort, " failed: return code ", err); return; } else { - LogPrint (eLogInfo, "UPnP: port successfully forwarded (", m_externalIPAddress ,":", strPort, " type ", strType, " -> ", m_NetworkAddr ,":", strPort ,")"); + LogPrint (eLogInfo, "UPnP: Port successfully forwarded (", m_externalIPAddress ,":", strPort, " type ", strType, " -> ", m_NetworkAddr ,":", strPort ,")"); return; } } else { - LogPrint (eLogDebug, "UPnP: external forward from ", m_NetworkAddr, ":", strPort, " exists on current Internet Gateway Device"); + LogPrint (eLogDebug, "UPnP: External forward from ", m_NetworkAddr, ":", strPort, " exists on current Internet Gateway Device"); return; } } @@ -225,7 +225,7 @@ namespace transport } std::string strType (GetProto (address)), strPort (std::to_string (address->port)); int err = UPNPCOMMAND_SUCCESS; - + err = CheckMapping (strPort.c_str (), strType.c_str ()); if (err == UPNPCOMMAND_SUCCESS) { diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index ed84b8e7..8d7a6125 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -377,7 +377,7 @@ namespace transport transports.PeerDisconnected (shared_from_this ()); m_Server.RemoveNTCP2Session (shared_from_this ()); m_SendQueue.clear (); - LogPrint (eLogDebug, "NTCP2: session terminated"); + LogPrint (eLogDebug, "NTCP2: Session terminated"); } } @@ -435,7 +435,7 @@ namespace transport (void) bytes_transferred; if (ecode) { - LogPrint (eLogWarning, "NTCP2: couldn't send SessionRequest message: ", ecode.message ()); + LogPrint (eLogWarning, "NTCP2: Couldn't send SessionRequest message: ", ecode.message ()); Terminate (); } else @@ -566,7 +566,7 @@ namespace transport (void) bytes_transferred; if (ecode) { - LogPrint (eLogWarning, "NTCP2: couldn't send SessionConfirmed message: ", ecode.message ()); + LogPrint (eLogWarning, "NTCP2: Couldn't send SessionConfirmed message: ", ecode.message ()); Terminate (); } else @@ -593,7 +593,7 @@ namespace transport (void) bytes_transferred; if (ecode) { - LogPrint (eLogWarning, "NTCP2: couldn't send SessionCreated message: ", ecode.message ()); + LogPrint (eLogWarning, "NTCP2: Couldn't send SessionCreated message: ", ecode.message ()); Terminate (); } else @@ -636,7 +636,7 @@ namespace transport // process RI if (buf[0] != eNTCP2BlkRouterInfo) { - LogPrint (eLogWarning, "NTCP2: unexpected block ", (int)buf[0], " in SessionConfirmed"); + LogPrint (eLogWarning, "NTCP2: Unexpected block ", (int)buf[0], " in SessionConfirmed"); Terminate (); return; } @@ -741,7 +741,7 @@ namespace transport if (ecode) { if (ecode != boost::asio::error::operation_aborted) - LogPrint (eLogWarning, "NTCP2: receive length read error: ", ecode.message ()); + LogPrint (eLogWarning, "NTCP2: Receive length read error: ", ecode.message ()); Terminate (); } else @@ -756,7 +756,7 @@ namespace transport #endif // m_NextReceivedLen comes from the network in BigEndian m_NextReceivedLen = be16toh (m_NextReceivedLen) ^ le16toh (m_ReceiveIV.key); - LogPrint (eLogDebug, "NTCP2: received length ", m_NextReceivedLen); + LogPrint (eLogDebug, "NTCP2: Received length ", m_NextReceivedLen); if (m_NextReceivedLen >= 16) { if (m_NextReceivedBuffer) delete[] m_NextReceivedBuffer; @@ -774,7 +774,7 @@ namespace transport } else { - LogPrint (eLogError, "NTCP2: received length ", m_NextReceivedLen, " is too short"); + LogPrint (eLogError, "NTCP2: Received length ", m_NextReceivedLen, " is too short"); Terminate (); } } @@ -796,7 +796,7 @@ namespace transport if (ecode) { if (ecode != boost::asio::error::operation_aborted) - LogPrint (eLogWarning, "NTCP2: receive read error: ", ecode.message ()); + LogPrint (eLogWarning, "NTCP2: Receive read error: ", ecode.message ()); Terminate (); } else @@ -808,7 +808,7 @@ namespace transport CreateNonce (m_ReceiveSequenceNumber, nonce); m_ReceiveSequenceNumber++; if (i2p::crypto::AEADChaCha20Poly1305 (m_NextReceivedBuffer, m_NextReceivedLen-16, nullptr, 0, m_ReceiveKey, nonce, m_NextReceivedBuffer, m_NextReceivedLen, false)) { - LogPrint (eLogDebug, "NTCP2: received message decrypted"); + LogPrint (eLogDebug, "NTCP2: Received message decrypted"); ProcessNextFrame (m_NextReceivedBuffer, m_NextReceivedLen-16); delete[] m_NextReceivedBuffer; m_NextReceivedBuffer = nullptr; // we don't need received buffer anymore ReceiveLength (); @@ -869,14 +869,14 @@ namespace transport case eNTCP2BlkTermination: if (size >= 9) { - LogPrint (eLogDebug, "NTCP2: termination. reason=", (int)(frame[offset + 8])); + LogPrint (eLogDebug, "NTCP2: Termination. reason=", (int)(frame[offset + 8])); Terminate (); } else LogPrint (eLogWarning, "NTCP2: Unexpected termination block size ", size); break; case eNTCP2BlkPadding: - LogPrint (eLogDebug, "NTCP2: padding"); + LogPrint (eLogDebug, "NTCP2: Padding"); break; default: LogPrint (eLogWarning, "NTCP2: Unknown block type ", (int)blk); @@ -898,7 +898,7 @@ namespace transport #endif // length must be in BigEndian htobe16buf (lengthBuf, frameLen ^ le16toh (m_SendIV.key)); - LogPrint (eLogDebug, "NTCP2: sent length ", frameLen); + LogPrint (eLogDebug, "NTCP2: Sent length ", frameLen); } void NTCP2Session::SendI2NPMsgs (std::vector >& msgs) @@ -1059,15 +1059,15 @@ namespace transport size_t paddingSize = (msgLen*NTCP2_MAX_PADDING_RATIO)/100; if (msgLen + paddingSize + 3 > NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) paddingSize = NTCP2_UNENCRYPTED_FRAME_MAX_SIZE - msgLen -3; if (paddingSize > len) paddingSize = len; - if (paddingSize) + if (paddingSize) { if (m_NextPaddingSize >= 16) { RAND_bytes ((uint8_t *)m_PaddingSizes, sizeof (m_PaddingSizes)); m_NextPaddingSize = 0; - } + } paddingSize = m_PaddingSizes[m_NextPaddingSize++] % paddingSize; - } + } buf[0] = eNTCP2BlkPadding; // blk htobe16buf (buf + 1, paddingSize); // size memset (buf + 3, 0, paddingSize); @@ -1126,7 +1126,7 @@ namespace transport SendQueue (); else if (m_SendQueue.size () > NTCP2_MAX_OUTGOING_QUEUE_SIZE) { - LogPrint (eLogWarning, "NTCP2: outgoing messages queue size to ", + LogPrint (eLogWarning, "NTCP2: Outgoing messages queue size to ", GetIdentHashBase64(), " exceeds ", NTCP2_MAX_OUTGOING_QUEUE_SIZE); Terminate (); } @@ -1232,7 +1232,7 @@ namespace transport } catch ( std::exception & ex ) { - LogPrint(eLogError, "NTCP2: failed to bind to v6 port ", address->port, ": ", ex.what()); + LogPrint(eLogError, "NTCP2: Failed to bind to v6 port ", address->port, ": ", ex.what()); ThrowFatal ("Unable to start IPv6 NTCP2 transport at port ", address->port, ": ", ex.what ()); continue; } @@ -1273,7 +1273,7 @@ namespace transport auto it = m_NTCP2Sessions.find (ident); if (it != m_NTCP2Sessions.end ()) { - LogPrint (eLogWarning, "NTCP2: session to ", ident.ToBase64 (), " already exists"); + LogPrint (eLogWarning, "NTCP2: Session to ", ident.ToBase64 (), " already exists"); if (incoming) // replace by new session it->second->Terminate (); @@ -1342,7 +1342,7 @@ namespace transport boost::system::error_code ec; conn->GetSocket ().bind (*localAddress, ec); if (ec) - LogPrint (eLogError, "NTCP2: can't bind to ", localAddress->address ().to_string (), ": ", ec.message ()); + LogPrint (eLogError, "NTCP2: Can't bind to ", localAddress->address ().to_string (), ": ", ec.message ()); } conn->GetSocket ().async_connect (conn->GetRemoteEndpoint (), std::bind (&NTCP2Server::HandleConnect, this, std::placeholders::_1, conn, timer)); } @@ -1509,7 +1509,7 @@ namespace transport { if (ecode) { - LogPrint(eLogWarning, "NTCP2: failed to connect to proxy ", ecode.message()); + LogPrint(eLogWarning, "NTCP2: Failed to connect to proxy ", ecode.message()); timer->cancel(); conn->Terminate(); return; @@ -1526,7 +1526,7 @@ namespace transport (void) transferred; if(ec) { - LogPrint(eLogWarning, "NTCP2: socks5 write error ", ec.message()); + LogPrint(eLogWarning, "NTCP2: SOCKS5 write error ", ec.message()); } }); auto readbuff = std::make_shared >(2); @@ -1535,7 +1535,7 @@ namespace transport { if(ec) { - LogPrint(eLogError, "NTCP2: socks5 read error ", ec.message()); + LogPrint(eLogError, "NTCP2: SOCKS5 read error ", ec.message()); timer->cancel(); conn->Terminate(); return; @@ -1549,14 +1549,14 @@ namespace transport } else if ((*readbuff)[1] == 0xff) { - LogPrint(eLogError, "NTCP2: socks5 proxy rejected authentication"); + LogPrint(eLogError, "NTCP2: SOCKS5 proxy rejected authentication"); timer->cancel(); conn->Terminate(); return; } LogPrint(eLogError, "NTCP2:", (int)(*readbuff)[1]); } - LogPrint(eLogError, "NTCP2: socks5 server gave invalid response"); + LogPrint(eLogError, "NTCP2: SOCKS5 server gave invalid response"); timer->cancel(); conn->Terminate(); }); @@ -1584,7 +1584,7 @@ namespace transport { (void) transferred; if(ec) - LogPrint(eLogError, "NTCP2: http proxy write error ", ec.message()); + LogPrint(eLogError, "NTCP2: HTTP proxy write error ", ec.message()); }); boost::asio::streambuf * readbuff = new boost::asio::streambuf; @@ -1593,7 +1593,7 @@ namespace transport { if(ec) { - LogPrint(eLogError, "NTCP2: http proxy read error ", ec.message()); + LogPrint(eLogError, "NTCP2: HTTP proxy read error ", ec.message()); timer->cancel(); conn->Terminate(); } @@ -1611,10 +1611,10 @@ namespace transport return; } else - LogPrint(eLogError, "NTCP2: http proxy rejected request ", res.code); + LogPrint(eLogError, "NTCP2: HTTP proxy rejected request ", res.code); } else - LogPrint(eLogError, "NTCP2: http proxy gave malformed response"); + LogPrint(eLogError, "NTCP2: HTTP proxy gave malformed response"); timer->cancel(); conn->Terminate(); delete readbuff; @@ -1623,7 +1623,7 @@ namespace transport break; } default: - LogPrint(eLogError, "NTCP2: unknown proxy type, invalid state"); + LogPrint(eLogError, "NTCP2: Unknown proxy type, invalid state"); } } @@ -1664,7 +1664,7 @@ namespace transport { if(ec) { - LogPrint(eLogError, "NTCP2: failed to write handshake to socks proxy ", ec.message()); + LogPrint(eLogError, "NTCP2: Failed to write handshake to socks proxy ", ec.message()); return; } }); @@ -1674,7 +1674,7 @@ namespace transport { if(e) { - LogPrint(eLogError, "NTCP2: socks proxy read error ", e.message()); + LogPrint(eLogError, "NTCP2: SOCKS proxy read error ", e.message()); } else if(transferred == sz) { diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index 6e9ac391..55b1c4df 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -65,7 +65,7 @@ namespace client std::string samAddr; i2p::config::GetOption("sam.address", samAddr); uint16_t samPort; i2p::config::GetOption("sam.port", samPort); bool singleThread; i2p::config::GetOption("sam.singlethread", singleThread); - LogPrint(eLogInfo, "Clients: starting SAM bridge at ", samAddr, ":", samPort); + LogPrint(eLogInfo, "Clients: Starting SAM bridge at ", samAddr, ":", samPort); try { m_SamBridge = new SAMBridge (samAddr, samPort, singleThread); @@ -83,7 +83,7 @@ namespace client if (bob) { std::string bobAddr; i2p::config::GetOption("bob.address", bobAddr); uint16_t bobPort; i2p::config::GetOption("bob.port", bobPort); - LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort); + LogPrint(eLogInfo, "Clients: Starting BOB command channel at ", bobAddr, ":", bobPort); try { m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort); @@ -103,7 +103,7 @@ namespace client std::string i2cpAddr; i2p::config::GetOption("i2cp.address", i2cpAddr); uint16_t i2cpPort; i2p::config::GetOption("i2cp.port", i2cpPort); bool singleThread; i2p::config::GetOption("i2cp.singlethread", singleThread); - LogPrint(eLogInfo, "Clients: starting I2CP at ", i2cpAddr, ":", i2cpPort); + LogPrint(eLogInfo, "Clients: Starting I2CP at ", i2cpAddr, ":", i2cpPort); try { m_I2CPServer = new I2CPServer (i2cpAddr, i2cpPort, singleThread); @@ -130,7 +130,7 @@ namespace client { if (m_HttpProxy) { - LogPrint(eLogInfo, "Clients: stopping HTTP Proxy"); + LogPrint(eLogInfo, "Clients: Stopping HTTP Proxy"); m_HttpProxy->Stop(); delete m_HttpProxy; m_HttpProxy = nullptr; @@ -138,7 +138,7 @@ namespace client if (m_SocksProxy) { - LogPrint(eLogInfo, "Clients: stopping SOCKS Proxy"); + LogPrint(eLogInfo, "Clients: Stopping SOCKS Proxy"); m_SocksProxy->Stop(); delete m_SocksProxy; m_SocksProxy = nullptr; @@ -146,21 +146,21 @@ namespace client for (auto& it: m_ClientTunnels) { - LogPrint(eLogInfo, "Clients: stopping I2P client tunnel on port ", it.first); + LogPrint(eLogInfo, "Clients: Stopping I2P client tunnel on port ", it.first); it.second->Stop (); } m_ClientTunnels.clear (); for (auto& it: m_ServerTunnels) { - LogPrint(eLogInfo, "Clients: stopping I2P server tunnel"); + LogPrint(eLogInfo, "Clients: Stopping I2P server tunnel"); it.second->Stop (); } m_ServerTunnels.clear (); if (m_SamBridge) { - LogPrint(eLogInfo, "Clients: stopping SAM bridge"); + LogPrint(eLogInfo, "Clients: Stopping SAM bridge"); m_SamBridge->Stop (); delete m_SamBridge; m_SamBridge = nullptr; @@ -168,7 +168,7 @@ namespace client if (m_BOBCommandChannel) { - LogPrint(eLogInfo, "Clients: stopping BOB command channel"); + LogPrint(eLogInfo, "Clients: Stopping BOB command channel"); m_BOBCommandChannel->Stop (); delete m_BOBCommandChannel; m_BOBCommandChannel = nullptr; @@ -176,13 +176,13 @@ namespace client if (m_I2CPServer) { - LogPrint(eLogInfo, "Clients: stopping I2CP"); + LogPrint(eLogInfo, "Clients: Stopping I2CP"); m_I2CPServer->Stop (); delete m_I2CPServer; m_I2CPServer = nullptr; } - LogPrint(eLogInfo, "Clients: stopping AddressBook"); + LogPrint(eLogInfo, "Clients: Stopping AddressBook"); m_AddressBook.Stop (); { @@ -274,7 +274,7 @@ namespace client s.read ((char *)buf, len); if(!keys.FromBuffer (buf, len)) { - LogPrint (eLogError, "Clients: failed to load keyfile ", filename); + LogPrint (eLogError, "Clients: Failed to load keyfile ", filename); success = false; } else @@ -283,7 +283,7 @@ namespace client } else { - LogPrint (eLogError, "Clients: can't open file ", fullPath, " Creating new one with signature type ", sigType, " crypto type ", cryptoType); + LogPrint (eLogError, "Clients: Can't open file ", fullPath, " .. creating new one with signature type ", sigType, " crypto type ", cryptoType); keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType); std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out); size_t len = keys.GetFullLen (); @@ -402,7 +402,7 @@ namespace client void ClientContext::CreateNewSharedLocalDestination () { - std::map params + std::map params { { I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, "3" }, { I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, "3" }, @@ -508,11 +508,11 @@ namespace client // TODO: cleanup this in 2.8.0 tunConf = i2p::fs::DataDirPath ("tunnels.cfg"); if (i2p::fs::Exists(tunConf)) - LogPrint(eLogWarning, "Clients: please rename tunnels.cfg -> tunnels.conf here: ", tunConf); + LogPrint(eLogWarning, "Clients: Please rename tunnels.cfg -> tunnels.conf here: ", tunConf); else tunConf = i2p::fs::DataDirPath ("tunnels.conf"); } - LogPrint(eLogDebug, "Clients: tunnels config file: ", tunConf); + LogPrint(eLogDebug, "Clients: Tunnels config file: ", tunConf); ReadTunnels (tunConf, numClientTunnels, numServerTunnels); std::string tunDir; i2p::config::GetOption("tunnelsdir", tunDir); @@ -526,7 +526,7 @@ namespace client for (auto& it: files) { if (it.substr(it.size() - 5) != ".conf") continue; // skip files which not ends with ".conf" - LogPrint(eLogDebug, "Clients: tunnels extra config file: ", it); + LogPrint(eLogDebug, "Clients: Tunnels extra config file: ", it); ReadTunnels (it, numClientTunnels, numServerTunnels); } } @@ -582,7 +582,7 @@ namespace client if (it != destinations.end ()) localDestination = it->second; else - { + { i2p::data::PrivateKeys k; if(LoadPrivateKeys (k, keys, sigType, cryptoType)) { @@ -597,7 +597,7 @@ namespace client destinations[keys] = localDestination; } } - } + } } if (type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT) { @@ -705,17 +705,17 @@ namespace client if (it != destinations.end ()) localDestination = it->second; else - { + { i2p::data::PrivateKeys k; if(!LoadPrivateKeys (k, keys, sigType, cryptoType)) continue; localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ()); if (!localDestination) - { + { localDestination = CreateNewLocalDestination (k, true, &options); destinations[keys] = localDestination; - } - } + } + } if (type == I2P_TUNNELS_SECTION_TYPE_UDPSERVER) { // udp server tunnel @@ -727,12 +727,12 @@ namespace client address = "::1"; else address = "127.0.0.1"; - } - auto localAddress = boost::asio::ip::address::from_string(address); + } + auto localAddress = boost::asio::ip::address::from_string(address); auto serverTunnel = std::make_shared(name, localDestination, localAddress, endpoint, port, gzip); if(!isUniqueLocal) { - LogPrint(eLogInfo, "Clients: disabling loopback address mapping"); + LogPrint(eLogInfo, "Clients: Disabling loopback address mapping"); serverTunnel->SetUniqueLocal(isUniqueLocal); } std::lock_guard lock(m_ForwardsMutex); @@ -825,7 +825,7 @@ namespace client std::string httpOutProxyURL; i2p::config::GetOption("httpproxy.outproxy", httpOutProxyURL); bool httpAddresshelper; i2p::config::GetOption("httpproxy.addresshelper", httpAddresshelper); i2p::data::SigningKeyType sigType; i2p::config::GetOption("httpproxy.signaturetype", sigType); - LogPrint(eLogInfo, "Clients: starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort); + LogPrint(eLogInfo, "Clients: Starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort); if (httpProxyKeys.length () > 0) { i2p::data::PrivateKeys keys; @@ -837,7 +837,7 @@ namespace client if (localDestination) localDestination->Acquire (); } else - LogPrint(eLogError, "Clients: failed to load HTTP Proxy key"); + LogPrint(eLogError, "Clients: Failed to load HTTP Proxy key"); } try { @@ -867,12 +867,12 @@ namespace client std::string socksOutProxyAddr; i2p::config::GetOption("socksproxy.outproxy", socksOutProxyAddr); uint16_t socksOutProxyPort; i2p::config::GetOption("socksproxy.outproxyport", socksOutProxyPort); i2p::data::SigningKeyType sigType; i2p::config::GetOption("socksproxy.signaturetype", sigType); - LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort); + LogPrint(eLogInfo, "Clients: Starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort); if (httpProxyKeys == socksProxyKeys && m_HttpProxy) { localDestination = m_HttpProxy->GetLocalDestination (); localDestination->Acquire (); - } + } else if (socksProxyKeys.length () > 0) { i2p::data::PrivateKeys keys; diff --git a/libi2pd_client/HTTPProxy.cpp b/libi2pd_client/HTTPProxy.cpp index 7acdc333..ed371e23 100644 --- a/libi2pd_client/HTTPProxy.cpp +++ b/libi2pd_client/HTTPProxy.cpp @@ -124,9 +124,9 @@ namespace proxy { void HTTPReqHandler::AsyncSockRead() { - LogPrint(eLogDebug, "HTTPProxy: async sock read"); + LogPrint(eLogDebug, "HTTPProxy: async socket read"); if (!m_sock) { - LogPrint(eLogError, "HTTPProxy: no socket for read"); + LogPrint(eLogError, "HTTPProxy: No socket for read"); return; } m_sock->async_read_some(boost::asio::buffer(m_recv_chunk, sizeof(m_recv_chunk)), @@ -138,13 +138,13 @@ namespace proxy { if (Kill()) return; if (m_sock) { - LogPrint(eLogDebug, "HTTPProxy: close sock"); + LogPrint(eLogDebug, "HTTPProxy: Close socket"); m_sock->close(); m_sock = nullptr; } if(m_proxysock) { - LogPrint(eLogDebug, "HTTPProxy: close proxysock"); + LogPrint(eLogDebug, "HTTPProxy: Close proxy socket"); if(m_proxysock->is_open()) m_proxysock->close(); m_proxysock = nullptr; @@ -269,13 +269,13 @@ namespace proxy { return false; /* need more data */ if (m_req_len < 0) { - LogPrint(eLogError, "HTTPProxy: unable to parse request"); + LogPrint(eLogError, "HTTPProxy: Unable to parse request"); GenericProxyError(tr("Invalid request"), tr("Proxy unable to parse your request")); return true; /* parse error */ } /* parsing success, now let's look inside request */ - LogPrint(eLogDebug, "HTTPProxy: requested: ", m_ClientRequest.uri); + LogPrint(eLogDebug, "HTTPProxy: Requested: ", m_ClientRequest.uri); m_RequestURL.parse(m_ClientRequest.uri); bool m_Confirm; @@ -284,14 +284,14 @@ namespace proxy { { if (!m_Addresshelper) { - LogPrint(eLogWarning, "HTTPProxy: addresshelper request rejected"); + LogPrint(eLogWarning, "HTTPProxy: Addresshelper request rejected"); GenericProxyError(tr("Invalid request"), tr("addresshelper is not supported")); return true; } if (!i2p::client::context.GetAddressBook ().FindAddress (m_RequestURL.host) || m_Confirm) { i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, jump); - LogPrint (eLogInfo, "HTTPProxy: added address from addresshelper for ", m_RequestURL.host); + LogPrint (eLogInfo, "HTTPProxy: Added address from addresshelper for ", m_RequestURL.host); std::string full_url = m_RequestURL.to_string(); std::stringstream ss; ss << tr("Host") <<" " << m_RequestURL.host << " " << tr("added to router's addressbook from helper") << ". "; @@ -375,13 +375,13 @@ namespace proxy { } } else { if(m_OutproxyUrl.size()) { - LogPrint (eLogDebug, "HTTPProxy: use outproxy ", m_OutproxyUrl); + LogPrint (eLogDebug, "HTTPProxy: Using outproxy ", m_OutproxyUrl); if(m_ProxyURL.parse(m_OutproxyUrl)) ForwardToUpstreamProxy(); else GenericProxyError(tr("Outproxy failure"), tr("bad outproxy settings")); } else { - LogPrint (eLogWarning, "HTTPProxy: outproxy failure for ", dest_host, ": no outproxy enabled"); + LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled"); std::stringstream ss; ss << tr("Host") << " " << dest_host << " " << tr("not inside I2P network, but outproxy is not enabled"); GenericProxyError(tr("Outproxy failure"), ss.str()); } @@ -404,7 +404,7 @@ namespace proxy { m_send_buf = m_ClientRequest.to_string(); m_send_buf.append(m_recv_buf); /* connect to destination */ - LogPrint(eLogDebug, "HTTPProxy: connecting to host ", dest_host, ":", dest_port); + LogPrint(eLogDebug, "HTTPProxy: Connecting to host ", dest_host, ":", dest_port); GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleStreamRequestComplete, shared_from_this(), std::placeholders::_1), dest_host, dest_port); return true; @@ -412,7 +412,7 @@ namespace proxy { void HTTPReqHandler::ForwardToUpstreamProxy() { - LogPrint(eLogDebug, "HTTPProxy: forward to upstream"); + LogPrint(eLogDebug, "HTTPProxy: Forward to upstream"); // build http request m_ClientRequestURL = m_RequestURL; @@ -424,7 +424,7 @@ namespace proxy { // update User-Agent to ESR version of Firefox, same as Tor Browser below version 8, for non-HTTPS connections if(m_ClientRequest.method != "CONNECT") - m_ClientRequest.UpdateHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"); + m_ClientRequest.UpdateHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"); m_ClientRequest.write(m_ClientRequestBuffer); m_ClientRequestBuffer << m_recv_buf.substr(m_req_len); @@ -490,7 +490,7 @@ namespace proxy { } uint16_t port = m_RequestURL.port; if(!port) port = 80; - LogPrint(eLogDebug, "HTTPProxy: connected to socks upstream"); + LogPrint(eLogDebug, "HTTPProxy: Connected to SOCKS upstream"); std::string host = m_RequestURL.host; std::size_t reqsize = 0; @@ -517,14 +517,14 @@ namespace proxy { void HTTPReqHandler::HandleSocksProxySendHandshake(const boost::system::error_code & ec, std::size_t bytes_transferred) { - LogPrint(eLogDebug, "HTTPProxy: upstream socks handshake sent"); + LogPrint(eLogDebug, "HTTPProxy: Upstream SOCKS handshake sent"); if(ec) GenericProxyError(tr("Cannot negotiate with socks proxy"), ec.message()); else m_proxysock->async_read_some(boost::asio::buffer(m_socks_buf, 8), std::bind(&HTTPReqHandler::HandleSocksProxyReply, this, std::placeholders::_1, std::placeholders::_2)); } void HTTPReqHandler::HandoverToUpstreamProxy() { - LogPrint(eLogDebug, "HTTPProxy: handover to socks proxy"); + LogPrint(eLogDebug, "HTTPProxy: Handover to SOCKS proxy"); auto connection = std::make_shared(GetOwner(), m_proxysock, m_sock); m_sock = nullptr; m_proxysock = nullptr; @@ -576,7 +576,7 @@ namespace proxy { }); } else { m_send_buf = m_ClientRequestBuffer.str(); - LogPrint(eLogDebug, "HTTPProxy: send ", m_send_buf.size(), " bytes"); + LogPrint(eLogDebug, "HTTPProxy: Send ", m_send_buf.size(), " bytes"); boost::asio::async_write(*m_proxysock, boost::asio::buffer(m_send_buf), boost::asio::transfer_all(), [&](const boost::system::error_code & ec, std::size_t transferred) { if(ec) GenericProxyError(tr("failed to send request to upstream"), ec.message()); @@ -606,7 +606,7 @@ namespace proxy { void HTTPReqHandler::HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec) { if(!ec) { - LogPrint(eLogDebug, "HTTPProxy: connected to http upstream"); + LogPrint(eLogDebug, "HTTPProxy: Connected to HTTP upstream"); GenericProxyError(tr("cannot connect"), tr("http out proxy not implemented")); } else GenericProxyError(tr("cannot connect to upstream http proxy"), ec.message()); } @@ -614,10 +614,10 @@ namespace proxy { /* will be called after some data received from client */ void HTTPReqHandler::HandleSockRecv(const boost::system::error_code & ecode, std::size_t len) { - LogPrint(eLogDebug, "HTTPProxy: sock recv: ", len, " bytes, recv buf: ", m_recv_buf.length(), ", send buf: ", m_send_buf.length()); + LogPrint(eLogDebug, "HTTPProxy: Socket recv: ", len, " bytes, recv buf: ", m_recv_buf.length(), ", send buf: ", m_send_buf.length()); if(ecode) { - LogPrint(eLogWarning, "HTTPProxy: sock recv got error: ", ecode); + LogPrint(eLogWarning, "HTTPProxy: Socket recv error: ", ecode); Terminate(); return; } @@ -633,14 +633,14 @@ namespace proxy { void HTTPReqHandler::SentHTTPFailed(const boost::system::error_code & ecode) { if (ecode) - LogPrint (eLogError, "HTTPProxy: Closing socket after sending failure because: ", ecode.message ()); + LogPrint (eLogError, "HTTPProxy: Closing socket after send failure: ", ecode.message ()); Terminate(); } void HTTPReqHandler::HandleStreamRequestComplete (std::shared_ptr stream) { if (!stream) { - LogPrint (eLogError, "HTTPProxy: error when creating the stream, check the previous warnings for more info"); + LogPrint (eLogError, "HTTPProxy: Error creating stream, check previous warnings for more info"); GenericProxyError(tr("Host is down"), tr("Can't create connection to requested host, it may be down. Please try again later.")); return; } diff --git a/libi2pd_client/I2CP.cpp b/libi2pd_client/I2CP.cpp index 25a5504a..fc27d1e7 100644 --- a/libi2pd_client/I2CP.cpp +++ b/libi2pd_client/I2CP.cpp @@ -23,7 +23,7 @@ namespace i2p namespace client { - I2CPDestination::I2CPDestination (boost::asio::io_service& service, std::shared_ptr owner, + I2CPDestination::I2CPDestination (boost::asio::io_service& service, std::shared_ptr owner, std::shared_ptr identity, bool isPublic, const std::map& params): LeaseSetDestination (service, isPublic, ¶ms), m_Owner (owner), m_Identity (identity), m_EncryptionKeyType (m_Identity->GetCryptoKeyType ()), @@ -36,8 +36,8 @@ namespace client LeaseSetDestination::Stop (); m_Owner = nullptr; m_LeaseSetCreationTimer.cancel (); - } - + } + void I2CPDestination::SetEncryptionPrivateKey (const uint8_t * key) { m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (m_Identity->GetCryptoKeyType (), key); @@ -46,12 +46,12 @@ namespace client void I2CPDestination::SetECIESx25519EncryptionPrivateKey (const uint8_t * key) { if (!m_ECIESx25519Decryptor || memcmp (m_ECIESx25519PrivateKey, key, 32)) // new key? - { + { m_ECIESx25519Decryptor = std::make_shared(key, true); // calculate public memcpy (m_ECIESx25519PrivateKey, key, 32); - } - } - + } + } + bool I2CPDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx, i2p::data::CryptoKeyType preferredCrypto) const { if (preferredCrypto == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD && m_ECIESx25519Decryptor) @@ -59,7 +59,7 @@ namespace client if (m_Decryptor) return m_Decryptor->Decrypt (encrypted, data, ctx, true); else - LogPrint (eLogError, "I2CP: decryptor is not set"); + LogPrint (eLogError, "I2CP: Decryptor is not set"); return false; } @@ -68,14 +68,14 @@ namespace client if (keyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD && m_ECIESx25519Decryptor) return m_ECIESx25519Decryptor->GetPubicKey (); return nullptr; - } - - bool I2CPDestination::SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const - { - return keyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ? (bool)m_ECIESx25519Decryptor : m_EncryptionKeyType == keyType; } - - + + bool I2CPDestination::SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const + { + return keyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ? (bool)m_ECIESx25519Decryptor : m_EncryptionKeyType == keyType; + } + + void I2CPDestination::HandleDataMessage (const uint8_t * buf, size_t len) { uint32_t length = bufbe32toh (buf); @@ -88,25 +88,25 @@ namespace client { GetService ().post (std::bind (&I2CPDestination::PostCreateNewLeaseSet, this, tunnels)); } - + void I2CPDestination::PostCreateNewLeaseSet (std::vector > tunnels) { if (m_IsCreatingLeaseSet) { LogPrint (eLogInfo, "I2CP: LeaseSet is being created"); return; - } + } uint8_t priv[256] = {0}; i2p::data::LocalLeaseSet ls (m_Identity, priv, tunnels); // we don't care about encryption key, we need leases only m_LeaseSetExpirationTime = ls.GetExpirationTime (); uint8_t * leases = ls.GetLeases (); leases[-1] = tunnels.size (); if (m_Owner) - { + { uint16_t sessionID = m_Owner->GetSessionID (); if (sessionID != 0xFFFF) - { - m_IsCreatingLeaseSet = true; + { + m_IsCreatingLeaseSet = true; htobe16buf (leases - 3, sessionID); size_t l = 2/*sessionID*/ + 1/*num leases*/ + i2p::data::LEASE_SIZE*tunnels.size (); m_Owner->SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l); @@ -120,8 +120,8 @@ namespace client if (s->m_Owner) s->m_Owner->Stop (); } }); - } - } + } + } } void I2CPDestination::LeaseSetCreated (const uint8_t * buf, size_t len) @@ -237,18 +237,18 @@ namespace client } } - RunnableI2CPDestination::RunnableI2CPDestination (std::shared_ptr owner, + RunnableI2CPDestination::RunnableI2CPDestination (std::shared_ptr owner, std::shared_ptr identity, bool isPublic, const std::map& params): RunnableService ("I2CP"), I2CPDestination (GetIOService (), owner, identity, isPublic, params) { - } + } RunnableI2CPDestination::~RunnableI2CPDestination () { if (IsRunning ()) Stop (); - } + } void RunnableI2CPDestination::Start () { @@ -267,9 +267,9 @@ namespace client StopIOService (); } } - + I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr socket): - m_Owner (owner), m_Socket (socket), m_SessionID (0xFFFF), + m_Owner (owner), m_Socket (socket), m_SessionID (0xFFFF), m_MessageID (0), m_IsSendAccepted (true), m_IsSending (false) { } @@ -307,11 +307,11 @@ namespace client void I2CPSession::ReceiveHeader () { - if (!m_Socket) + if (!m_Socket) { LogPrint (eLogError, "I2CP: Can't receive header"); return; - } + } boost::asio::async_read (*m_Socket, boost::asio::buffer (m_Header, I2CP_HEADER_SIZE), boost::asio::transfer_all (), std::bind (&I2CPSession::HandleReceivedHeader, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); @@ -344,11 +344,11 @@ namespace client void I2CPSession::ReceivePayload () { - if (!m_Socket) - { + if (!m_Socket) + { LogPrint (eLogError, "I2CP: Can't receive payload"); return; - } + } boost::asio::async_read (*m_Socket, boost::asio::buffer (m_Payload, m_PayloadLen), boost::asio::transfer_all (), std::bind (&I2CPSession::HandleReceivedPayload, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); @@ -390,11 +390,11 @@ namespace client if (!m_SendQueue.IsEmpty ()) m_SendQueue.CleanUp (); if (m_SessionID != 0xFFFF) - { + { m_Owner.RemoveSession (GetSessionID ()); - LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " terminated"); + LogPrint (eLogDebug, "I2CP: Session ", m_SessionID, " terminated"); m_SessionID = 0xFFFF; - } + } } void I2CPSession::SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len) @@ -404,39 +404,39 @@ namespace client { LogPrint (eLogError, "I2CP: Message to send is too long ", l); return; - } + } auto sendBuf = m_IsSending ? std::make_shared (l) : nullptr; uint8_t * buf = sendBuf ? sendBuf->buf : m_SendBuffer; htobe32buf (buf + I2CP_HEADER_LENGTH_OFFSET, len); buf[I2CP_HEADER_TYPE_OFFSET] = type; memcpy (buf + I2CP_HEADER_SIZE, payload, len); if (sendBuf) - { + { if (m_SendQueue.GetSize () < I2CP_MAX_SEND_QUEUE_SIZE) m_SendQueue.Add (sendBuf); - else - { - LogPrint (eLogWarning, "I2CP: send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE); - return; - } - } + else + { + LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE); + return; + } + } else { auto socket = m_Socket; if (socket) - { + { m_IsSending = true; - boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l), - boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent, + boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l), + boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); - } - } + } + } } void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred) { if (ecode) - { + { if (ecode != boost::asio::error::operation_aborted) Terminate (); } @@ -444,19 +444,19 @@ namespace client { auto socket = m_Socket; if (socket) - { + { auto len = m_SendQueue.Get (m_SendBuffer, I2CP_MAX_MESSAGE_LENGTH); - boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, len), - boost::asio::transfer_all (),std::bind(&I2CPSession::HandleI2CPMessageSent, + boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, len), + boost::asio::transfer_all (),std::bind(&I2CPSession::HandleI2CPMessageSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); - } + } else m_IsSending = false; } else m_IsSending = false; } - + std::string I2CPSession::ExtractString (const uint8_t * buf, size_t len) { uint8_t l = buf[0]; @@ -524,7 +524,7 @@ namespace client size_t offset = identity->FromBuffer (buf, len); if (!offset) { - LogPrint (eLogError, "I2CP: create session malformed identity"); + LogPrint (eLogError, "I2CP: Create session malformed identity"); SendSessionStatusMessage (3); // invalid return; } @@ -532,7 +532,7 @@ namespace client offset += 2; if (optionsSize > len - offset) { - LogPrint (eLogError, "I2CP: options size ", optionsSize, "exceeds message size"); + LogPrint (eLogError, "I2CP: Options size ", optionsSize, "exceeds message size"); SendSessionStatusMessage (3); // invalid return; } @@ -550,18 +550,18 @@ namespace client std::make_shared(m_Owner.GetService (), shared_from_this (), identity, true, params): std::make_shared(shared_from_this (), identity, true, params); SendSessionStatusMessage (1); // created - LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " created"); + LogPrint (eLogDebug, "I2CP: Session ", m_SessionID, " created"); m_Destination->Start (); } else { - LogPrint (eLogError, "I2CP: session already exists"); + LogPrint (eLogError, "I2CP: Session already exists"); SendSessionStatusMessage (4); // refused } } else { - LogPrint (eLogError, "I2CP: create session signature verification failed"); + LogPrint (eLogError, "I2CP: Create session signature verification failed"); SendSessionStatusMessage (3); // invalid } } @@ -569,7 +569,7 @@ namespace client void I2CPSession::DestroySessionMessageHandler (const uint8_t * buf, size_t len) { SendSessionStatusMessage (0); // destroy - LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " destroyed"); + LogPrint (eLogDebug, "I2CP: Session ", m_SessionID, " destroyed"); Terminate (); } @@ -604,29 +604,29 @@ namespace client { if(m_Destination->Reconfigure(opts)) { - LogPrint(eLogInfo, "I2CP: reconfigured destination"); + LogPrint(eLogInfo, "I2CP: Reconfigured destination"); status = 2; // updated } else - LogPrint(eLogWarning, "I2CP: failed to reconfigure destination"); + LogPrint(eLogWarning, "I2CP: Failed to reconfigure destination"); } else - LogPrint(eLogError, "I2CP: invalid reconfigure message signature"); + LogPrint(eLogError, "I2CP: Invalid reconfigure message signature"); } else - LogPrint(eLogError, "I2CP: mapping size mismatch"); + LogPrint(eLogError, "I2CP: Mapping size mismatch"); } else - LogPrint(eLogError, "I2CP: destination mismatch"); + LogPrint(eLogError, "I2CP: Destination mismatch"); } else - LogPrint(eLogError, "I2CP: malfromed destination"); + LogPrint(eLogError, "I2CP: Malformed destination"); } else - LogPrint(eLogError, "I2CP: session mismatch"); + LogPrint(eLogError, "I2CP: Session mismatch"); } else - LogPrint(eLogError, "I2CP: short message"); + LogPrint(eLogError, "I2CP: Truncated message"); SendSessionStatusMessage (status); } @@ -668,7 +668,7 @@ namespace client } } else - LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID); + LogPrint (eLogError, "I2CP: Unexpected sessionID ", sessionID); } void I2CPSession::CreateLeaseSet2MessageHandler (const uint8_t * buf, size_t len) @@ -683,7 +683,7 @@ namespace client i2p::data::LeaseSet2 ls (storeType, buf + offset, len - offset); // outer layer only for encrypted if (!ls.IsValid ()) { - LogPrint (eLogError, "I2CP: invalid LeaseSet2 of type ", storeType); + LogPrint (eLogError, "I2CP: Invalid LeaseSet2 of type ", storeType); return; } offset += ls.GetBufferLen (); @@ -699,17 +699,17 @@ namespace client m_Destination->SetECIESx25519EncryptionPrivateKey (buf + offset); else { - m_Destination->SetEncryptionType (keyType); + m_Destination->SetEncryptionType (keyType); m_Destination->SetEncryptionPrivateKey (buf + offset); } offset += keyLen; } - + m_Destination->LeaseSet2Created (storeType, ls.GetBuffer (), ls.GetBufferLen ()); } } else - LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID); + LogPrint (eLogError, "I2CP: Unexpected sessionID ", sessionID); } void I2CPSession::SendMessageMessageHandler (const uint8_t * buf, size_t len) @@ -735,14 +735,14 @@ namespace client m_Destination->SendMsgTo (buf + offset, payloadLen, identity.GetIdentHash (), nonce); } else - LogPrint(eLogError, "I2CP: cannot send message, too big"); + LogPrint(eLogError, "I2CP: Cannot send message, too big"); } else - LogPrint(eLogError, "I2CP: invalid identity"); + LogPrint(eLogError, "I2CP: Invalid identity"); } } else - LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID); + LogPrint (eLogError, "I2CP: Unexpected sessionID ", sessionID); } void I2CPSession::SendMessageExpiresMessageHandler (const uint8_t * buf, size_t len) @@ -770,7 +770,7 @@ namespace client if (!addr || !addr->IsIdentHash ()) { // TODO: handle blinded addresses - LogPrint (eLogError, "I2CP: address ", name, " not found"); + LogPrint (eLogError, "I2CP: Address ", name, " not found"); SendHostReplyMessage (requestID, nullptr); return; } @@ -779,7 +779,7 @@ namespace client break; } default: - LogPrint (eLogError, "I2CP: request type ", (int)buf[10], " is not supported"); + LogPrint (eLogError, "I2CP: Request type ", (int)buf[10], " is not supported"); SendHostReplyMessage (requestID, nullptr); return; } @@ -805,7 +805,7 @@ namespace client SendHostReplyMessage (requestID, nullptr); } else - LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID); + LogPrint (eLogError, "I2CP: Unexpected sessionID ", sessionID); } void I2CPSession::SendHostReplyMessage (uint32_t requestID, std::shared_ptr identity) @@ -885,7 +885,7 @@ namespace client { LogPrint (eLogError, "I2CP: Message to send is too long ", l); return; - } + } auto sendBuf = m_IsSending ? std::make_shared (l) : nullptr; uint8_t * buf = sendBuf ? sendBuf->buf : m_SendBuffer; htobe32buf (buf + I2CP_HEADER_LENGTH_OFFSET, len + 10); @@ -895,26 +895,26 @@ namespace client htobe32buf (buf + I2CP_HEADER_SIZE + 6, len); memcpy (buf + I2CP_HEADER_SIZE + 10, payload, len); if (sendBuf) - { + { if (m_SendQueue.GetSize () < I2CP_MAX_SEND_QUEUE_SIZE) m_SendQueue.Add (sendBuf); - else - { - LogPrint (eLogWarning, "I2CP: send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE); - return; - } - } + else + { + LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE); + return; + } + } else { auto socket = m_Socket; if (socket) - { + { m_IsSending = true; - boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l), - boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent, + boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l), + boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); - } - } + } + } } I2CPServer::I2CPServer (const std::string& interface, int port, bool isSingleThread): @@ -980,15 +980,15 @@ namespace client auto ep = socket->remote_endpoint (ec); if (!ec) { - LogPrint (eLogDebug, "I2CP: new connection from ", ep); + LogPrint (eLogDebug, "I2CP: New connection from ", ep); auto session = std::make_shared(*this, socket); session->Start (); } else - LogPrint (eLogError, "I2CP: incoming connection error ", ec.message ()); + LogPrint (eLogError, "I2CP: Incoming connection error ", ec.message ()); } else - LogPrint (eLogError, "I2CP: accept error: ", ecode.message ()); + LogPrint (eLogError, "I2CP: Accept error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Accept (); @@ -999,7 +999,7 @@ namespace client if (!session) return false; if (!m_Sessions.insert({session->GetSessionID (), session}).second) { - LogPrint (eLogError, "I2CP: duplicate session id ", session->GetSessionID ()); + LogPrint (eLogError, "I2CP: Duplicate session id ", session->GetSessionID ()); return false; } return true; diff --git a/libi2pd_client/I2PService.cpp b/libi2pd_client/I2PService.cpp index 83838106..f5e4c345 100644 --- a/libi2pd_client/I2PService.cpp +++ b/libi2pd_client/I2PService.cpp @@ -193,7 +193,7 @@ namespace client std::placeholders::_1, std::placeholders::_2)); } else - LogPrint(eLogError, "TCPIPPipe: upstream receive: no socket"); + LogPrint(eLogError, "TCPIPPipe: Upstream receive: no socket"); } void TCPIPPipe::AsyncReceiveDownstream() @@ -204,14 +204,14 @@ namespace client std::placeholders::_1, std::placeholders::_2)); } else - LogPrint(eLogError, "TCPIPPipe: downstream receive: no socket"); + LogPrint(eLogError, "TCPIPPipe: Downstream receive: no socket"); } void TCPIPPipe::UpstreamWrite(size_t len) { if (m_up) { - LogPrint(eLogDebug, "TCPIPPipe: upstream: ", (int) len, " bytes written"); + LogPrint(eLogDebug, "TCPIPPipe: Upstream: ", (int) len, " bytes written"); boost::asio::async_write(*m_up, boost::asio::buffer(m_upstream_buf, len), boost::asio::transfer_all(), std::bind(&TCPIPPipe::HandleUpstreamWrite, @@ -219,14 +219,14 @@ namespace client std::placeholders::_1)); } else - LogPrint(eLogError, "TCPIPPipe: upstream write: no socket"); + LogPrint(eLogError, "TCPIPPipe: Upstream write: no socket"); } void TCPIPPipe::DownstreamWrite(size_t len) { if (m_down) { - LogPrint(eLogDebug, "TCPIPPipe: downstream: ", (int) len, " bytes written"); + LogPrint(eLogDebug, "TCPIPPipe: Downstream: ", (int) len, " bytes written"); boost::asio::async_write(*m_down, boost::asio::buffer(m_downstream_buf, len), boost::asio::transfer_all(), std::bind(&TCPIPPipe::HandleDownstreamWrite, @@ -234,16 +234,16 @@ namespace client std::placeholders::_1)); } else - LogPrint(eLogError, "TCPIPPipe: downstream write: no socket"); + LogPrint(eLogError, "TCPIPPipe: Downstream write: no socket"); } void TCPIPPipe::HandleDownstreamReceived(const boost::system::error_code & ecode, std::size_t bytes_transfered) { - LogPrint(eLogDebug, "TCPIPPipe: downstream: ", (int) bytes_transfered, " bytes received"); + LogPrint(eLogDebug, "TCPIPPipe: Downstream: ", (int) bytes_transfered, " bytes received"); if (ecode) { - LogPrint(eLogError, "TCPIPPipe: downstream read error:" , ecode.message()); + LogPrint(eLogError, "TCPIPPipe: Downstream read error:" , ecode.message()); if (ecode != boost::asio::error::operation_aborted) Terminate(); } else { @@ -256,7 +256,7 @@ namespace client void TCPIPPipe::HandleDownstreamWrite(const boost::system::error_code & ecode) { if (ecode) { - LogPrint(eLogError, "TCPIPPipe: downstream write error:" , ecode.message()); + LogPrint(eLogError, "TCPIPPipe: Downstream write error:" , ecode.message()); if (ecode != boost::asio::error::operation_aborted) Terminate(); } @@ -267,7 +267,7 @@ namespace client void TCPIPPipe::HandleUpstreamWrite(const boost::system::error_code & ecode) { if (ecode) { - LogPrint(eLogError, "TCPIPPipe: upstream write error:" , ecode.message()); + LogPrint(eLogError, "TCPIPPipe: Upstream write error:" , ecode.message()); if (ecode != boost::asio::error::operation_aborted) Terminate(); } @@ -277,10 +277,10 @@ namespace client void TCPIPPipe::HandleUpstreamReceived(const boost::system::error_code & ecode, std::size_t bytes_transfered) { - LogPrint(eLogDebug, "TCPIPPipe: upstream ", (int)bytes_transfered, " bytes received"); + LogPrint(eLogDebug, "TCPIPPipe: Upstream ", (int)bytes_transfered, " bytes received"); if (ecode) { - LogPrint(eLogError, "TCPIPPipe: upstream read error:" , ecode.message()); + LogPrint(eLogError, "TCPIPPipe: Upstream read error:" , ecode.message()); if (ecode != boost::asio::error::operation_aborted) Terminate(); } else { diff --git a/libi2pd_client/I2PTunnel.cpp b/libi2pd_client/I2PTunnel.cpp index e8a66228..f1970c64 100644 --- a/libi2pd_client/I2PTunnel.cpp +++ b/libi2pd_client/I2PTunnel.cpp @@ -87,7 +87,7 @@ namespace client boost::system::error_code ec; sock->bind (boost::asio::ip::tcp::endpoint (ourIP, 0), ec); if (ec) - LogPrint (eLogError, "I2PTunnel: can't bind ourIP to ", ourIP.to_string (), ": ", ec.message ()); + LogPrint (eLogError, "I2PTunnel: Can't bind ourIP to ", ourIP.to_string (), ": ", ec.message ()); } #endif @@ -122,11 +122,11 @@ namespace client boost::system::error_code ec; m_Socket->bind (boost::asio::ip::tcp::endpoint (localAddress, 0), ec); if (ec) - LogPrint (eLogError, "I2PTunnel: can't bind to ", localAddress.to_string (), ": ", ec.message ()); - } + LogPrint (eLogError, "I2PTunnel: Can't bind to ", localAddress.to_string (), ": ", ec.message ()); + } Connect (false); - } - + } + void I2PTunnelConnection::Terminate () { if (Kill()) return; @@ -155,7 +155,7 @@ namespace client { if (ecode != boost::asio::error::operation_aborted) { - LogPrint (eLogError, "I2PTunnel: read error: ", ecode.message ()); + LogPrint (eLogError, "I2PTunnel: Read error: ", ecode.message ()); Terminate (); } } @@ -177,13 +177,13 @@ namespace client s->Terminate (); }); } - } - + } + void I2PTunnelConnection::HandleWrite (const boost::system::error_code& ecode) { if (ecode) { - LogPrint (eLogError, "I2PTunnel: write error: ", ecode.message ()); + LogPrint (eLogError, "I2PTunnel: Write error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate (); } @@ -221,7 +221,7 @@ namespace client { if (ecode != boost::asio::error::operation_aborted) { - LogPrint (eLogError, "I2PTunnel: stream read error: ", ecode.message ()); + LogPrint (eLogError, "I2PTunnel: Stream read error: ", ecode.message ()); if (bytes_transferred > 0) Write (m_StreamBuffer, bytes_transferred); // postpone termination else if (ecode == boost::asio::error::timed_out && m_Stream && m_Stream->IsOpen ()) @@ -246,12 +246,12 @@ namespace client { if (ecode) { - LogPrint (eLogError, "I2PTunnel: connect error: ", ecode.message ()); + LogPrint (eLogError, "I2PTunnel: Connect error: ", ecode.message ()); Terminate (); } else { - LogPrint (eLogDebug, "I2PTunnel: connected"); + LogPrint (eLogDebug, "I2PTunnel: Connected"); if (m_IsQuiet) StreamReceive (); else @@ -326,7 +326,7 @@ namespace client I2PServerTunnelConnectionHTTP::I2PServerTunnelConnectionHTTP (I2PService * owner, std::shared_ptr stream, std::shared_ptr socket, const boost::asio::ip::tcp::endpoint& target, const std::string& host): - I2PTunnelConnection (owner, stream, socket, target), m_Host (host), + I2PTunnelConnection (owner, stream, socket, target), m_Host (host), m_HeaderSent (false), m_ResponseHeaderSent (false), m_From (stream->GetRemoteIdentity ()) { } @@ -368,7 +368,7 @@ namespace client m_OutHeader << X_I2P_DEST_HASH << ": " << m_From->GetIdentHash ().ToBase64 () << "\r\n"; m_OutHeader << X_I2P_DEST_B64 << ": " << m_From->ToBase64 () << "\r\n"; } - + m_OutHeader << "\r\n"; // end of header m_OutHeader << m_InHeader.str ().substr (m_InHeader.tellg ()); // data right after header m_InHeader.str (""); @@ -404,11 +404,11 @@ namespace client }; bool matched = false; for (const auto& it: excluded) - if (!line.compare(0, it.length (), it)) + if (!line.compare(0, it.length (), it)) { matched = true; - break; - } + break; + } if (!matched) m_OutHeader << line << "\n"; } @@ -425,12 +425,12 @@ namespace client m_ResponseHeaderSent = true; I2PTunnelConnection::WriteToStream ((uint8_t *)m_OutHeader.str ().c_str (), m_OutHeader.str ().length ()); m_OutHeader.str (""); - } + } else Receive (); - } + } } - + I2PTunnelConnectionIRC::I2PTunnelConnectionIRC (I2PService * owner, std::shared_ptr stream, std::shared_ptr socket, const boost::asio::ip::tcp::endpoint& target, const std::string& webircpass): @@ -505,7 +505,7 @@ namespace client if (stream) { if (Kill()) return; - LogPrint (eLogDebug, "I2PTunnel: new connection"); + LogPrint (eLogDebug, "I2PTunnel: New connection"); auto connection = std::make_shared(GetOwner(), m_Socket, stream); GetOwner()->AddHandler (connection); connection->I2PConnect (); @@ -608,16 +608,16 @@ namespace client bool found = false; boost::asio::ip::tcp::endpoint ep; if (m_LocalAddress) - { + { boost::asio::ip::tcp::resolver::iterator end; while (it != end) - { + { ep = *it; if (!ep.address ().is_unspecified ()) { if (ep.address ().is_v4 ()) - { - if (m_LocalAddress->is_v4 ()) found = true; + { + if (m_LocalAddress->is_v4 ()) found = true; } else if (ep.address ().is_v6 ()) { @@ -625,28 +625,28 @@ namespace client { if (i2p::util::net::IsYggdrasilAddress (*m_LocalAddress)) found = true; - } - else if (m_LocalAddress->is_v6 ()) + } + else if (m_LocalAddress->is_v6 ()) found = true; } - } + } if (found) break; it++; } - } + } else { found = true; ep = *it; // first available - } + } if (!found) { LogPrint (eLogError, "I2PTunnel: Unable to resolve to compatible address"); return; - } - + } + auto addr = ep.address (); - LogPrint (eLogInfo, "I2PTunnel: server tunnel ", (*it).host_name (), " has been resolved to ", addr); + LogPrint (eLogInfo, "I2PTunnel: Server tunnel ", (*it).host_name (), " has been resolved to ", addr); m_Endpoint.address (addr); Accept (); } @@ -667,9 +667,9 @@ namespace client if (!ec) m_LocalAddress.reset (new boost::asio::ip::address (addr)); else - LogPrint (eLogError, "I2PTunnel: can't set local address ", localAddress); - } - + LogPrint (eLogError, "I2PTunnel: Can't set local address ", localAddress); + } + void I2PServerTunnel::Accept () { if (m_PortDestination) @@ -703,7 +703,7 @@ namespace client AddHandler (conn); if (m_LocalAddress) conn->Connect (*m_LocalAddress); - else + else conn->Connect (m_IsUniqueLocal); } } @@ -758,9 +758,9 @@ namespace client { m_LastSession->IPSocket.send_to(boost::asio::buffer(buf, len), m_RemoteEndpoint); m_LastSession->LastActivity = i2p::util::GetMillisecondsSinceEpoch(); - } - } - + } + } + void I2PUDPServerTunnel::ExpireStale(const uint64_t delta) { std::lock_guard lock(m_SessionsMutex); uint64_t now = i2p::util::GetMillisecondsSinceEpoch(); @@ -794,7 +794,7 @@ namespace client if (s->Identity.GetLL()[0] == ih.GetLL()[0] && remotePort == s->RemotePort) { /** found existing session */ - LogPrint(eLogDebug, "UDPServer: found session ", s->IPSocket.local_endpoint(), " ", ih.ToBase32()); + LogPrint(eLogDebug, "UDPServer: Found session ", s->IPSocket.local_endpoint(), " ", ih.ToBase32()); return s; } } @@ -839,7 +839,7 @@ namespace client { if(!ecode) { - LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint); + LogPrint(eLogDebug, "UDPSession: Forward ", len, "B from ", FromEndpoint); auto ts = i2p::util::GetMillisecondsSinceEpoch(); auto session = m_Destination->GetSession (Identity); if (ts > LastActivity + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL) @@ -848,20 +848,20 @@ namespace client m_Destination->SendRawDatagram(session, m_Buffer, len, LocalPort, RemotePort); size_t numPackets = 0; while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE) - { + { boost::system::error_code ec; size_t moreBytes = IPSocket.available(ec); if (ec || !moreBytes) break; len = IPSocket.receive_from (boost::asio::buffer (m_Buffer, I2P_UDP_MAX_MTU), FromEndpoint, 0, ec); - m_Destination->SendRawDatagram (session, m_Buffer, len, LocalPort, RemotePort); + m_Destination->SendRawDatagram (session, m_Buffer, len, LocalPort, RemotePort); numPackets++; - } + } if (numPackets > 0) - LogPrint(eLogDebug, "UDPSession: forward more ", numPackets, "packets B from ", FromEndpoint); + LogPrint(eLogDebug, "UDPSession: Forward more ", numPackets, "packets B from ", FromEndpoint); m_Destination->FlushSendQueue (session); LastActivity = ts; Receive(); - } + } else LogPrint(eLogError, "UDPSession: ", ecode.message()); } @@ -877,7 +877,7 @@ namespace client m_LocalDest->Start(); auto dgram = m_LocalDest->CreateDatagramDestination(gzip); dgram->SetReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)); - dgram->SetRawReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2PRaw, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); + dgram->SetRawReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2PRaw, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); } I2PUDPServerTunnel::~I2PUDPServerTunnel() @@ -885,7 +885,7 @@ namespace client auto dgram = m_LocalDest->GetDatagramDestination(); if (dgram) dgram->ResetReceiver(); - LogPrint(eLogInfo, "UDPServer: done"); + LogPrint(eLogInfo, "UDPServer: Done"); } void I2PUDPServerTunnel::Start() { @@ -959,7 +959,7 @@ namespace client return; } if(!m_RemoteIdent) { - LogPrint(eLogWarning, "UDP Client: remote endpoint not resolved yet"); + LogPrint(eLogWarning, "UDP Client: Remote endpoint not resolved yet"); RecvFromLocal(); return; // drop, remote not resolved } @@ -973,33 +973,33 @@ namespace client { m_LastSession = std::make_shared(boost::asio::ip::udp::endpoint(m_RecvEndpoint), 0); m_Sessions.emplace (remotePort, m_LastSession); - } + } m_LastPort = remotePort; - } + } // send off to remote i2p destination auto ts = i2p::util::GetMillisecondsSinceEpoch(); - LogPrint(eLogDebug, "UDP Client: send ", transferred, " to ", m_RemoteIdent->ToBase32(), ":", RemotePort); + LogPrint(eLogDebug, "UDP Client: Send ", transferred, " to ", m_RemoteIdent->ToBase32(), ":", RemotePort); auto session = m_LocalDest->GetDatagramDestination()->GetSession (*m_RemoteIdent); - if (ts > m_LastSession->second + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL) + if (ts > m_LastSession->second + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL) m_LocalDest->GetDatagramDestination()->SendDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort); else m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort); size_t numPackets = 0; while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE) - { + { boost::system::error_code ec; size_t moreBytes = m_LocalSocket.available(ec); if (ec || !moreBytes) break; transferred = m_LocalSocket.receive_from (boost::asio::buffer (m_RecvBuff, I2P_UDP_MAX_MTU), m_RecvEndpoint, 0, ec); remotePort = m_RecvEndpoint.port(); // TODO: check remotePort - m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort); + m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort); numPackets++; - } + } if (numPackets) - LogPrint(eLogDebug, "UDP Client: sent ", numPackets, " more packets to ", m_RemoteIdent->ToBase32()); + LogPrint(eLogDebug, "UDP Client: Sent ", numPackets, " more packets to ", m_RemoteIdent->ToBase32()); m_LocalDest->GetDatagramDestination()->FlushSendQueue (session); - + // mark convo as active if (m_LastSession) m_LastSession->second = ts; @@ -1020,12 +1020,12 @@ namespace client std::shared_ptr addr; while(!(addr = context.GetAddressBook().GetAddress(m_RemoteDest)) && !m_cancel_resolve) { - LogPrint(eLogWarning, "UDP Tunnel: failed to lookup ", m_RemoteDest); + LogPrint(eLogWarning, "UDP Tunnel: Failed to lookup ", m_RemoteDest); std::this_thread::sleep_for(std::chrono::seconds(1)); } if(m_cancel_resolve) { - LogPrint(eLogError, "UDP Tunnel: lookup of ", m_RemoteDest, " was cancelled"); + LogPrint(eLogError, "UDP Tunnel: Lookup of ", m_RemoteDest, " was cancelled"); return; } if (!addr || !addr->IsIdentHash ()) @@ -1035,7 +1035,7 @@ namespace client } m_RemoteIdent = new i2p::data::IdentHash; *m_RemoteIdent = addr->identHash; - LogPrint(eLogInfo, "UDP Tunnel: resolved ", m_RemoteDest, " to ", m_RemoteIdent->ToBase32()); + LogPrint(eLogInfo, "UDP Tunnel: Resolved ", m_RemoteDest, " to ", m_RemoteIdent->ToBase32()); } void I2PUDPClientTunnel::HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) @@ -1043,7 +1043,7 @@ namespace client if(m_RemoteIdent && from.GetIdentHash() == *m_RemoteIdent) HandleRecvFromI2PRaw (fromPort, toPort, buf, len); else - LogPrint(eLogWarning, "UDP Client: unwarranted traffic from ", from.GetIdentHash().ToBase32()); + LogPrint(eLogWarning, "UDP Client: Unwarranted traffic from ", from.GetIdentHash().ToBase32()); } void I2PUDPClientTunnel::HandleRecvFromI2PRaw(uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) @@ -1053,18 +1053,18 @@ namespace client if(itr != m_Sessions.end()) { // found convo - if (len > 0) + if (len > 0) { - LogPrint(eLogDebug, "UDP Client: got ", len, "B from ", m_RemoteIdent ? m_RemoteIdent->ToBase32() : ""); + LogPrint(eLogDebug, "UDP Client: Got ", len, "B from ", m_RemoteIdent ? m_RemoteIdent->ToBase32() : ""); m_LocalSocket.send_to(boost::asio::buffer(buf, len), itr->second->first); // mark convo as active itr->second->second = i2p::util::GetMillisecondsSinceEpoch(); } } else - LogPrint(eLogWarning, "UDP Client: not tracking udp session using port ", (int) toPort); + LogPrint(eLogWarning, "UDP Client: Not tracking UDP session using port ", (int) toPort); } - + I2PUDPClientTunnel::~I2PUDPClientTunnel() { auto dgram = m_LocalDest->GetDatagramDestination(); if (dgram) dgram->ResetReceiver(); diff --git a/libi2pd_client/MatchedDestination.cpp b/libi2pd_client/MatchedDestination.cpp index 8d17632b..ce800ecc 100644 --- a/libi2pd_client/MatchedDestination.cpp +++ b/libi2pd_client/MatchedDestination.cpp @@ -33,14 +33,14 @@ namespace client RequestDestination(m_RemoteIdent, std::bind(&MatchedTunnelDestination::HandleFoundCurrentLeaseSet, this, std::placeholders::_1)); } else - LogPrint(eLogWarning, "Destination: failed to resolve ", m_RemoteName); + LogPrint(eLogWarning, "Destination: Failed to resolve ", m_RemoteName); } void MatchedTunnelDestination::HandleFoundCurrentLeaseSet(std::shared_ptr ls) { if(ls) { - LogPrint(eLogDebug, "Destination: resolved remote lease set for ", m_RemoteName); + LogPrint(eLogDebug, "Destination: Resolved remote lease set for ", m_RemoteName); m_RemoteLeaseSet = ls; } else @@ -72,7 +72,7 @@ namespace client bool MatchedTunnelDestination::SelectPeers(i2p::tunnel::Path & path, int hops, bool inbound) { auto pool = GetTunnelPool(); - if(!i2p::tunnel::StandardSelectPeers(path, hops, inbound, + if(!i2p::tunnel::StandardSelectPeers(path, hops, inbound, std::bind(&i2p::tunnel::TunnelPool::SelectNextHop, pool, std::placeholders::_1, std::placeholders::_2))) return false; // more here for outbound tunnels @@ -86,19 +86,19 @@ namespace client auto leases = m_RemoteLeaseSet->GetNonExpiredLeases(); // pick lease std::shared_ptr obep; - while(!obep && leases.size() > 0) + while(!obep && leases.size() > 0) { auto idx = rand() % leases.size(); auto lease = leases[idx]; obep = i2p::data::netdb.FindRouter(lease->tunnelGateway); leases.erase(leases.begin()+idx); } - if(obep) + if(obep) { path.Add (obep); - LogPrint(eLogDebug, "Destination: found OBEP matching IBGW"); + LogPrint(eLogDebug, "Destination: Found OBEP matching IBGW"); } else - LogPrint(eLogWarning, "Destination: could not find proper IBGW for matched outbound tunnel"); + LogPrint(eLogWarning, "Destination: Could not find proper IBGW for matched outbound tunnel"); } } return true; diff --git a/libi2pd_client/SAM.cpp b/libi2pd_client/SAM.cpp index c2983f43..aae80185 100644 --- a/libi2pd_client/SAM.cpp +++ b/libi2pd_client/SAM.cpp @@ -54,7 +54,7 @@ namespace client break; } case eSAMSocketTypeAcceptor: - case eSAMSocketTypeForward: + case eSAMSocketTypeForward: { if (Session) { @@ -101,7 +101,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: handshake read error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Handshake read error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate ("SAM: handshake read error"); } @@ -111,7 +111,7 @@ namespace client char * eol = (char *)memchr (m_Buffer, '\n', bytes_transferred); if (eol) *eol = 0; - LogPrint (eLogDebug, "SAM: handshake ", m_Buffer); + LogPrint (eLogDebug, "SAM: Handshake ", m_Buffer); char * separator = strchr (m_Buffer, ' '); if (separator) { @@ -168,7 +168,7 @@ namespace client } else { - LogPrint (eLogError, "SAM: handshake mismatch"); + LogPrint (eLogError, "SAM: Handshake mismatch"); Terminate ("SAM: handshake mismatch"); } } @@ -183,7 +183,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: handshake reply send error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Handshake reply send error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate ("SAM: handshake reply send error"); } @@ -216,7 +216,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: reply send error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Reply send error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate ("SAM: reply send error"); } @@ -233,7 +233,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: read error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Read error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate ("SAM: read error"); } @@ -295,20 +295,20 @@ namespace client } else { - LogPrint (eLogError, "SAM: unexpected message ", m_Buffer); + LogPrint (eLogError, "SAM: Unexpected message ", m_Buffer); Terminate ("SAM: unexpected message"); } } else { - LogPrint (eLogError, "SAM: malformed message ", m_Buffer); + LogPrint (eLogError, "SAM: Malformed message ", m_Buffer); Terminate ("malformed message"); } } else { - LogPrint (eLogWarning, "SAM: incomplete message ", bytes_transferred); + LogPrint (eLogWarning, "SAM: Incomplete message ", bytes_transferred); m_BufferOffset = bytes_transferred; // try to receive remaining message Receive (); @@ -331,7 +331,7 @@ namespace client void SAMSocket::ProcessSessionCreate (char * buf, size_t len) { - LogPrint (eLogDebug, "SAM: session create: ", buf); + LogPrint (eLogDebug, "SAM: Session create: ", buf); std::map params; ExtractParams (buf, params); std::string& style = params[SAM_PARAM_STYLE]; @@ -476,12 +476,12 @@ namespace client void SAMSocket::ProcessStreamConnect (char * buf, size_t len, size_t rem) { - LogPrint (eLogDebug, "SAM: stream connect: ", buf); + LogPrint (eLogDebug, "SAM: Stream connect: ", buf); if ( m_SocketType != eSAMSocketTypeUnknown) { SendI2PError ("Socket already in use"); return; - } + } std::map params; ExtractParams (buf, params); std::string& id = params[SAM_PARAM_ID]; @@ -502,7 +502,7 @@ namespace client std::shared_ptr addr; if (destination.find(".i2p") != std::string::npos) - addr = context.GetAddressBook().GetAddress (destination); + addr = context.GetAddressBook().GetAddress (destination); else { auto dest = std::make_shared (); @@ -511,13 +511,13 @@ namespace client { context.GetAddressBook().InsertFullAddress(dest); addr = std::make_shared
(dest->GetIdentHash ()); - } - } - + } + } + if (addr && addr->IsValid ()) { if (addr->IsIdentHash ()) - { + { auto leaseSet = session->GetLocalDestination ()->FindLeaseSet(addr->identHash); if (leaseSet) Connect(leaseSet, session); @@ -527,7 +527,7 @@ namespace client std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, shared_from_this(), std::placeholders::_1)); } - } + } else // B33 session->GetLocalDestination ()->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, @@ -548,12 +548,12 @@ namespace client m_SocketType = eSAMSocketTypeStream; m_Stream = session->GetLocalDestination ()->CreateStream (remote); if (m_Stream) - { + { m_Stream->Send ((uint8_t *)m_Buffer, m_BufferOffset); // connect and send m_BufferOffset = 0; I2PReceive (); SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); - } + } else SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true); } @@ -574,12 +574,12 @@ namespace client void SAMSocket::ProcessStreamAccept (char * buf, size_t len) { - LogPrint (eLogDebug, "SAM: stream accept: ", buf); + LogPrint (eLogDebug, "SAM: Stream accept: ", buf); if ( m_SocketType != eSAMSocketTypeUnknown) { SendI2PError ("Socket already in use"); return; - } + } std::map params; ExtractParams (buf, params); std::string& id = params[SAM_PARAM_ID]; @@ -612,45 +612,45 @@ namespace client { SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true); return; - } + } if (session->GetLocalDestination ()->IsAcceptingStreams ()) - { + { SendI2PError ("Already accepting"); return; - } + } auto it = params.find (SAM_PARAM_PORT); if (it == params.end ()) { SendI2PError ("PORT is missing"); return; - } + } auto port = std::stoi (it->second); if (port <= 0 || port >= 0xFFFF) { SendI2PError ("Invalid PORT"); return; - } + } boost::system::error_code ec; auto ep = m_Socket.remote_endpoint (ec); if (ec) { SendI2PError ("Socket error"); return; - } + } ep.port (port); m_SocketType = eSAMSocketTypeForward; m_ID = id; m_IsAccepting = true; std::string& silent = params[SAM_PARAM_SILENT]; if (silent == SAM_VALUE_TRUE) m_IsSilent = true; - session->GetLocalDestination ()->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward, + session->GetLocalDestination ()->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward, shared_from_this (), std::placeholders::_1, ep)); - SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); - } - + SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); + } + size_t SAMSocket::ProcessDatagramSend (char * buf, size_t len, const char * data) { - LogPrint (eLogDebug, "SAM: datagram send: ", buf, " ", len); + LogPrint (eLogDebug, "SAM: Datagram send: ", buf, " ", len); std::map params; ExtractParams (buf, params); size_t size = std::stoi(params[SAM_PARAM_SIZE]), offset = data - buf; @@ -670,14 +670,14 @@ namespace client d->SendRawDatagramTo ((const uint8_t *)data, size, dest.GetIdentHash ()); } else - LogPrint (eLogError, "SAM: missing datagram destination"); + LogPrint (eLogError, "SAM:Mmissing datagram destination"); } else - LogPrint (eLogError, "SAM: session is not created from DATAGRAM SEND"); + LogPrint (eLogError, "SAM: Session is not created from DATAGRAM SEND"); } else { - LogPrint (eLogWarning, "SAM: sent datagram size ", size, " exceeds buffer ", len - offset); + LogPrint (eLogWarning, "SAM: Sent datagram size ", size, " exceeds buffer ", len - offset); return 0; // try to receive more } return offset + size; @@ -685,7 +685,7 @@ namespace client void SAMSocket::ProcessDestGenerate (char * buf, size_t len) { - LogPrint (eLogDebug, "SAM: dest generate"); + LogPrint (eLogDebug, "SAM: Dest generate"); std::map params; ExtractParams (buf, params); // extract signature type @@ -722,7 +722,7 @@ namespace client void SAMSocket::ProcessNamingLookup (char * buf, size_t len) { - LogPrint (eLogDebug, "SAM: naming lookup: ", buf); + LogPrint (eLogDebug, "SAM: Naming lookup: ", buf); std::map params; ExtractParams (buf, params); std::string& name = params[SAM_PARAM_NAME]; @@ -753,7 +753,7 @@ namespace client } else { - LogPrint (eLogError, "SAM: naming failed, unknown address ", name); + LogPrint (eLogError, "SAM: Naming failed, unknown address ", name); #ifdef _MSC_VER size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str()); #else @@ -768,7 +768,7 @@ namespace client auto session = m_Owner.FindSession(m_ID); if (session && session->Type == eSAMSessionTypeMaster) { - LogPrint (eLogDebug, "SAM: subsession add: ", buf); + LogPrint (eLogDebug, "SAM: Subsession add: ", buf); auto masterSession = std::static_pointer_cast(session); std::map params; ExtractParams (buf, params); @@ -778,8 +778,8 @@ namespace client // session exists SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), false); return; - } - std::string& style = params[SAM_PARAM_STYLE]; + } + std::string& style = params[SAM_PARAM_STYLE]; SAMSessionType type = eSAMSessionTypeUnknown; if (style == SAM_VALUE_STREAM) type = eSAMSessionTypeStream; // TODO: implement other styles @@ -800,39 +800,39 @@ namespace client { masterSession->subsessions.insert (id); SendSessionCreateReplyOk (); - } + } else SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), false); - } + } else SendI2PError ("Wrong session type"); } - + void SAMSocket::ProcessSessionRemove (char * buf, size_t len) { auto session = m_Owner.FindSession(m_ID); if (session && session->Type == eSAMSessionTypeMaster) { - LogPrint (eLogDebug, "SAM: subsession remove: ", buf); + LogPrint (eLogDebug, "SAM: Subsession remove: ", buf); auto masterSession = std::static_pointer_cast(session); std::map params; ExtractParams (buf, params); std::string& id = params[SAM_PARAM_ID]; if (!masterSession->subsessions.erase (id)) - { + { SendMessageReply (SAM_SESSION_STATUS_INVALID_KEY, strlen(SAM_SESSION_STATUS_INVALID_KEY), false); return; } m_Owner.CloseSession (id); SendSessionCreateReplyOk (); - } + } else SendI2PError ("Wrong session type"); - } - + } + void SAMSocket::SendI2PError(const std::string & msg) { - LogPrint (eLogError, "SAM: i2p error ", msg); + LogPrint (eLogError, "SAM: I2P error ", msg); #ifdef _MSC_VER size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_SESSION_STATUS_I2P_ERROR, msg.c_str()); #else @@ -850,7 +850,7 @@ namespace client } else { - LogPrint (eLogError, "SAM: naming lookup failed. LeaseSet for ", name, " not found"); + LogPrint (eLogError, "SAM: Naming lookup failed. LeaseSet for ", name, " not found"); #ifdef _MSC_VER size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str()); #else @@ -901,7 +901,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: read error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Read error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate ("read error"); } @@ -978,7 +978,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: stream read error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Stream read error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) { if (bytes_transferred > 0) @@ -1015,7 +1015,7 @@ namespace client { if (ecode) { - LogPrint (eLogError, "SAM: socket write error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Socket write error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Terminate ("socket write error at HandleWriteI2PData"); } @@ -1029,7 +1029,7 @@ namespace client { if (stream) { - LogPrint (eLogDebug, "SAM: incoming I2P connection for session ", m_ID); + LogPrint (eLogDebug, "SAM: Incoming I2P connection for session ", m_ID); m_SocketType = eSAMSocketTypeStream; m_IsAccepting = false; m_Stream = stream; @@ -1067,16 +1067,16 @@ namespace client LogPrint (eLogWarning, "SAM: I2P acceptor has been reset"); } - void SAMSocket::HandleI2PForward (std::shared_ptr stream, + void SAMSocket::HandleI2PForward (std::shared_ptr stream, boost::asio::ip::tcp::endpoint ep) { if (stream) { - LogPrint (eLogDebug, "SAM: incoming forward I2P connection for session ", m_ID); + LogPrint (eLogDebug, "SAM: Incoming forward I2P connection for session ", m_ID); auto newSocket = std::make_shared(m_Owner); newSocket->SetSocketType (eSAMSocketTypeStream); auto s = shared_from_this (); - newSocket->GetSocket ().async_connect (ep, + newSocket->GetSocket ().async_connect (ep, [s, newSocket, stream](const boost::system::error_code& ecode) { if (!ecode) @@ -1098,15 +1098,15 @@ namespace client } else stream->AsyncClose (); - }); + }); } else LogPrint (eLogWarning, "SAM: I2P forward acceptor has been reset"); - } - + } + void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) { - LogPrint (eLogDebug, "SAM: datagram received ", len); + LogPrint (eLogDebug, "SAM: Datagram received ", len); auto base64 = from.ToBase64 (); auto session = m_Owner.FindSession(m_ID); if(session) @@ -1142,14 +1142,14 @@ namespace client WriteI2PData(len + l); } else - LogPrint (eLogWarning, "SAM: received datagram size ", len," exceeds buffer"); + LogPrint (eLogWarning, "SAM: Received datagram size ", len," exceeds buffer"); } } } void SAMSocket::HandleI2PRawDatagramReceive (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) { - LogPrint (eLogDebug, "SAM: raw datagram received ", len); + LogPrint (eLogDebug, "SAM: Raw datagram received ", len); auto session = m_Owner.FindSession(m_ID); if(session) { @@ -1170,7 +1170,7 @@ namespace client WriteI2PData(len + l); } else - LogPrint (eLogWarning, "SAM: received raw datagram size ", len," exceeds buffer"); + LogPrint (eLogWarning, "SAM: Received raw datagram; size ", len," exceeds buffer"); } } } @@ -1198,11 +1198,11 @@ namespace client localDestination (dest) { } - + SAMSingleSession::~SAMSingleSession () { i2p::client::context.DeleteLocalDestination (localDestination); - } + } void SAMSingleSession::StopLocalDestination () { @@ -1220,24 +1220,24 @@ namespace client for (const auto& it: subsessions) m_Bridge.CloseSession (it); subsessions.clear (); - } - + } + SAMSubSession::SAMSubSession (std::shared_ptr master, const std::string& name, SAMSessionType type, int port): SAMSession (master->m_Bridge, name, type), masterSession (master), inPort (port) { if (Type == eSAMSessionTypeStream) - { + { auto d = masterSession->GetLocalDestination ()->CreateStreamingDestination (inPort); if (d) d->Start (); - } - // TODO: implement datagrams - } - + } + // TODO: implement datagrams + } + std::shared_ptr SAMSubSession::GetLocalDestination () { return masterSession ? masterSession->GetLocalDestination () : nullptr; } - + void SAMSubSession::StopLocalDestination () { auto dest = GetLocalDestination (); @@ -1245,10 +1245,10 @@ namespace client { auto d = dest->RemoveStreamingDestination (inPort); if (d) d->Stop (); - } + } // TODO: implement datagrams - } - + } + SAMBridge::SAMBridge (const std::string& address, int port, bool singleThread): RunnableService ("SAM"), m_IsSingleThread (singleThread), m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port)), @@ -1288,7 +1288,7 @@ namespace client } catch (const std::exception& ex) { - LogPrint (eLogError, "SAM: runtime exception: ", ex.what ()); + LogPrint (eLogError, "SAM: Runtime exception: ", ex.what ()); } { @@ -1311,8 +1311,8 @@ namespace client { std::unique_lock lock(m_OpenSocketsMutex); m_OpenSockets.push_back(socket); - } - + } + void SAMBridge::RemoveSocket(const std::shared_ptr & socket) { std::unique_lock lock(m_OpenSocketsMutex); @@ -1327,15 +1327,15 @@ namespace client auto ep = socket->GetSocket ().remote_endpoint (ec); if (!ec) { - LogPrint (eLogDebug, "SAM: new connection from ", ep); + LogPrint (eLogDebug, "SAM: New connection from ", ep); AddSocket (socket); socket->ReceiveHandshake (); } else - LogPrint (eLogError, "SAM: incoming connection error ", ec.message ()); + LogPrint (eLogError, "SAM: Incoming connection error ", ec.message ()); } else - LogPrint (eLogError, "SAM: accept error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Accept error: ", ecode.message ()); if (ecode != boost::asio::error::operation_aborted) Accept (); @@ -1403,7 +1403,7 @@ namespace client auto ret = m_Sessions.emplace (session->Name, session); return ret.second; } - + void SAMBridge::CloseSession (const std::string& id) { std::shared_ptr session; @@ -1479,7 +1479,7 @@ namespace client { *eol = 0; eol++; size_t payloadLen = bytes_transferred - ((uint8_t *)eol - m_DatagramReceiveBuffer); - LogPrint (eLogDebug, "SAM: datagram received ", m_DatagramReceiveBuffer," size=", payloadLen); + LogPrint (eLogDebug, "SAM: Datagram received ", m_DatagramReceiveBuffer," size=", payloadLen); char * sessionID = strchr ((char *)m_DatagramReceiveBuffer, ' '); if (sessionID) { @@ -1510,11 +1510,11 @@ namespace client LogPrint (eLogError, "SAM: Missing sessionID"); } else - LogPrint(eLogError, "SAM: invalid datagram"); + LogPrint(eLogError, "SAM: Invalid datagram"); ReceiveDatagram (); } else - LogPrint (eLogError, "SAM: datagram receive error: ", ecode.message ()); + LogPrint (eLogError, "SAM: Datagram receive error: ", ecode.message ()); } bool SAMBridge::ResolveSignatureType (const std::string& name, i2p::data::SigningKeyType& type) const