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