|
|
|
@ -1184,7 +1184,9 @@ namespace transport
@@ -1184,7 +1184,9 @@ namespace transport
|
|
|
|
|
conn->Terminate(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(m_ProxyType == eSocksProxy) |
|
|
|
|
switch (m_ProxyType) |
|
|
|
|
{ |
|
|
|
|
case eSocksProxy: |
|
|
|
|
{ |
|
|
|
|
// TODO: support username/password auth etc
|
|
|
|
|
uint8_t buff[3] = {0x05, 0x01, 0x00}; |
|
|
|
@ -1196,7 +1198,8 @@ namespace transport
@@ -1196,7 +1198,8 @@ namespace transport
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
uint8_t readbuff[2]; |
|
|
|
|
boost::asio::async_read(conn->GetSocket(), boost::asio::buffer(readbuff, 2), [=](const boost::system::error_code & ec, std::size_t transferred) |
|
|
|
|
boost::asio::async_read(conn->GetSocket(), boost::asio::buffer(readbuff, 2), |
|
|
|
|
[=](const boost::system::error_code & ec, std::size_t transferred) |
|
|
|
|
{ |
|
|
|
|
LogPrint(eLogError, "NTCP2: ", transferred); |
|
|
|
|
if(ec) |
|
|
|
@ -1226,8 +1229,9 @@ namespace transport
@@ -1226,8 +1229,9 @@ namespace transport
|
|
|
|
|
timer->cancel(); |
|
|
|
|
conn->Terminate(); |
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
else if(m_ProxyType == eHTTPProxy) |
|
|
|
|
case eHTTPProxy: |
|
|
|
|
{ |
|
|
|
|
i2p::http::HTTPReq req; |
|
|
|
|
req.method = "CONNECT"; |
|
|
|
@ -1248,7 +1252,9 @@ namespace transport
@@ -1248,7 +1252,9 @@ namespace transport
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
boost::asio::streambuf * readbuff = new boost::asio::streambuf; |
|
|
|
|
boost::asio::async_read_until(conn->GetSocket(), *readbuff, "\r\n\r\n", [=] (const boost::system::error_code & ec, std::size_t transferred) { |
|
|
|
|
boost::asio::async_read_until(conn->GetSocket(), *readbuff, "\r\n\r\n", |
|
|
|
|
[=] (const boost::system::error_code & ec, std::size_t transferred) |
|
|
|
|
{ |
|
|
|
|
if(ec) |
|
|
|
|
{ |
|
|
|
|
LogPrint(eLogError, "NTCP2: http proxy read error ", ec.message()); |
|
|
|
@ -1280,17 +1286,16 @@ namespace transport
@@ -1280,17 +1286,16 @@ namespace transport
|
|
|
|
|
delete readbuff; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
default: |
|
|
|
|
LogPrint(eLogError, "NTCP2: unknown proxy type, invalid state"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void NTCP2Server::ConnectWithProxy (const std::string& host, uint16_t port, RemoteAddressType addrtype, std::shared_ptr<NTCP2Session> conn) |
|
|
|
|
{ |
|
|
|
|
if(m_ProxyEndpoint == nullptr) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(!m_ProxyEndpoint) return |
|
|
|
|
GetService().post([=]() { |
|
|
|
|
if (this->AddNTCP2Session (conn)) |
|
|
|
|
{ |
|
|
|
@ -1359,9 +1364,8 @@ namespace transport
@@ -1359,9 +1364,8 @@ namespace transport
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NTCP2Server::NTCP2Server (): |
|
|
|
|
RunnableServiceWithWork ("NTCP2"), |
|
|
|
|
m_ProxyType(eNoProxy), m_Resolver(GetService ()), m_ProxyEndpoint(nullptr), |
|
|
|
|
m_TerminationTimer (GetService ()) |
|
|
|
|
RunnableServiceWithWork ("NTCP2"), m_TerminationTimer (GetService ()), |
|
|
|
|
m_Resolver(GetService ()) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1388,11 +1392,9 @@ namespace transport
@@ -1388,11 +1392,9 @@ namespace transport
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
m_ProxyEndpoint = new boost::asio::ip::tcp::endpoint(*itr); |
|
|
|
|
m_ProxyEndpoint.reset (new boost::asio::ip::tcp::endpoint(*itr)); |
|
|
|
|
if (m_ProxyEndpoint) |
|
|
|
|
{ |
|
|
|
|
LogPrint(eLogError, "NTCP2: m_ProxyEndpoint %s", m_ProxyEndpoint); |
|
|
|
|
} |
|
|
|
|
LogPrint(eLogError, "NTCP2: m_ProxyEndpoint ", *m_ProxyEndpoint); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -1461,12 +1463,8 @@ namespace transport
@@ -1461,12 +1463,8 @@ namespace transport
|
|
|
|
|
if (IsRunning ()) |
|
|
|
|
{ |
|
|
|
|
m_TerminationTimer.cancel (); |
|
|
|
|
if(m_ProxyEndpoint) |
|
|
|
|
{ |
|
|
|
|
delete m_ProxyEndpoint; |
|
|
|
|
m_ProxyEndpoint = nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
StopIOService (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|