mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-21 16:49:10 +01:00
handle ntcp2.proxy parameter
This commit is contained in:
parent
ae20e3aa95
commit
e969d58689
3 changed files with 80 additions and 75 deletions
|
@ -61,7 +61,6 @@ namespace config {
|
||||||
("ntcp", value<bool>()->default_value(false), "Enable NTCP transport (default: disabled)")
|
("ntcp", value<bool>()->default_value(false), "Enable NTCP transport (default: disabled)")
|
||||||
("ssu", value<bool>()->default_value(true), "Enable SSU transport (default: enabled)")
|
("ssu", value<bool>()->default_value(true), "Enable SSU transport (default: enabled)")
|
||||||
("ntcpproxy", value<std::string>()->default_value(""), "Proxy URL for NTCP transport")
|
("ntcpproxy", value<std::string>()->default_value(""), "Proxy URL for NTCP transport")
|
||||||
("ntcp2proxy", value<std::string>()->default_value(""), "Proxy URL for NTCP2 transport")
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
("svcctl", value<std::string>()->default_value(""), "Windows service management ('install' or 'remove')")
|
("svcctl", value<std::string>()->default_value(""), "Windows service management ('install' or 'remove')")
|
||||||
("insomnia", bool_switch()->default_value(false), "Prevent system from sleeping (default: disabled)")
|
("insomnia", bool_switch()->default_value(false), "Prevent system from sleeping (default: disabled)")
|
||||||
|
@ -240,6 +239,7 @@ namespace config {
|
||||||
("ntcp2.published", value<bool>()->default_value(true), "Publish NTCP2 (default: enabled)")
|
("ntcp2.published", value<bool>()->default_value(true), "Publish NTCP2 (default: enabled)")
|
||||||
("ntcp2.port", value<uint16_t>()->default_value(0), "Port to listen for incoming NTCP2 connections (default: auto)")
|
("ntcp2.port", value<uint16_t>()->default_value(0), "Port to listen for incoming NTCP2 connections (default: auto)")
|
||||||
("ntcp2.addressv6", value<std::string>()->default_value("::"), "Address to bind NTCP2 on")
|
("ntcp2.addressv6", value<std::string>()->default_value("::"), "Address to bind NTCP2 on")
|
||||||
|
("ntcp2.proxy", value<std::string>()->default_value(""), "Proxy URL for NTCP2 transport")
|
||||||
;
|
;
|
||||||
|
|
||||||
options_description nettime("Time sync options");
|
options_description nettime("Time sync options");
|
||||||
|
|
|
@ -1189,17 +1189,19 @@ namespace transport
|
||||||
case eSocksProxy:
|
case eSocksProxy:
|
||||||
{
|
{
|
||||||
// TODO: support username/password auth etc
|
// TODO: support username/password auth etc
|
||||||
uint8_t buff[3] = {0x05, 0x01, 0x00};
|
static const uint8_t buff[3] = {0x05, 0x01, 0x00};
|
||||||
boost::asio::async_write(conn->GetSocket(), boost::asio::buffer(buff, 3), boost::asio::transfer_all(), [=] (const boost::system::error_code & ec, std::size_t transferred) {
|
boost::asio::async_write(conn->GetSocket(), boost::asio::buffer(buff, 3), boost::asio::transfer_all(),
|
||||||
|
[] (const boost::system::error_code & ec, std::size_t transferred)
|
||||||
|
{
|
||||||
(void) transferred;
|
(void) transferred;
|
||||||
if(ec)
|
if(ec)
|
||||||
{
|
{
|
||||||
LogPrint(eLogWarning, "NTCP2: socks5 write error ", ec.message());
|
LogPrint(eLogWarning, "NTCP2: socks5 write error ", ec.message());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
uint8_t readbuff[2];
|
auto readbuff = std::make_shared<std::array<uint8_t, 2> >();
|
||||||
boost::asio::async_read(conn->GetSocket(), boost::asio::buffer(readbuff, 2),
|
boost::asio::async_read(conn->GetSocket(), boost::asio::buffer(*readbuff, 2),
|
||||||
[=](const boost::system::error_code & ec, std::size_t transferred)
|
[this, readbuff, timer, conn, host, port, addrtype](const boost::system::error_code & ec, std::size_t transferred)
|
||||||
{
|
{
|
||||||
LogPrint(eLogError, "NTCP2: ", transferred);
|
LogPrint(eLogError, "NTCP2: ", transferred);
|
||||||
if(ec)
|
if(ec)
|
||||||
|
@ -1211,19 +1213,19 @@ namespace transport
|
||||||
}
|
}
|
||||||
else if(transferred == 2)
|
else if(transferred == 2)
|
||||||
{
|
{
|
||||||
if(readbuff[1] == 0xba)
|
if((*readbuff)[1] == 0xba)
|
||||||
{
|
{
|
||||||
AfterSocksHandshake(conn, timer, host, port, addrtype);
|
AfterSocksHandshake(conn, timer, host, port, addrtype);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
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:", readbuff[1]);
|
LogPrint(eLogError, "NTCP2:", (*readbuff)[1]);
|
||||||
}
|
}
|
||||||
LogPrint(eLogError, "NTCP2: socks5 server gave invalid response");
|
LogPrint(eLogError, "NTCP2: socks5 server gave invalid response");
|
||||||
timer->cancel();
|
timer->cancel();
|
||||||
|
@ -1245,7 +1247,9 @@ namespace transport
|
||||||
std::ostream out(&writebuff);
|
std::ostream out(&writebuff);
|
||||||
out << req.to_string();
|
out << req.to_string();
|
||||||
|
|
||||||
boost::asio::async_write(conn->GetSocket(), writebuff.data(), boost::asio::transfer_all(), [=](const boost::system::error_code & ec, std::size_t transferred) {
|
boost::asio::async_write(conn->GetSocket(), writebuff.data(), boost::asio::transfer_all(),
|
||||||
|
[](const boost::system::error_code & ec, std::size_t transferred)
|
||||||
|
{
|
||||||
(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());
|
||||||
|
@ -1253,7 +1257,7 @@ namespace transport
|
||||||
|
|
||||||
boost::asio::streambuf * readbuff = new boost::asio::streambuf;
|
boost::asio::streambuf * readbuff = new boost::asio::streambuf;
|
||||||
boost::asio::async_read_until(conn->GetSocket(), *readbuff, "\r\n\r\n",
|
boost::asio::async_read_until(conn->GetSocket(), *readbuff, "\r\n\r\n",
|
||||||
[=] (const boost::system::error_code & ec, std::size_t transferred)
|
[this, readbuff, timer, conn] (const boost::system::error_code & ec, std::size_t transferred)
|
||||||
{
|
{
|
||||||
if(ec)
|
if(ec)
|
||||||
{
|
{
|
||||||
|
@ -1275,10 +1279,8 @@ 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();
|
||||||
|
@ -1304,7 +1306,8 @@ namespace transport
|
||||||
auto timeout = NTCP_CONNECT_TIMEOUT * 5;
|
auto timeout = NTCP_CONNECT_TIMEOUT * 5;
|
||||||
conn->SetTerminationTimeout(timeout * 2);
|
conn->SetTerminationTimeout(timeout * 2);
|
||||||
timer->expires_from_now (boost::posix_time::seconds(timeout));
|
timer->expires_from_now (boost::posix_time::seconds(timeout));
|
||||||
timer->async_wait ([conn, timeout](const boost::system::error_code& ecode) {
|
timer->async_wait ([conn, timeout](const boost::system::error_code& ecode)
|
||||||
|
{
|
||||||
if (ecode != boost::asio::error::operation_aborted)
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
{
|
{
|
||||||
LogPrint (eLogInfo, "NTCP2: Not connected in ", timeout, " seconds");
|
LogPrint (eLogInfo, "NTCP2: Not connected in ", timeout, " seconds");
|
||||||
|
|
|
@ -157,7 +157,7 @@ namespace transport
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
m_Thread = new std::thread (std::bind (&Transports::Run, this));
|
m_Thread = new std::thread (std::bind (&Transports::Run, this));
|
||||||
std::string ntcpproxy; i2p::config::GetOption("ntcpproxy", ntcpproxy);
|
std::string ntcpproxy; i2p::config::GetOption("ntcpproxy", ntcpproxy);
|
||||||
std::string ntcp2proxy; i2p::config::GetOption("ntcp2proxy", ntcp2proxy);
|
std::string ntcp2proxy; i2p::config::GetOption("ntcp2.proxy", ntcp2proxy);
|
||||||
i2p::http::URL proxyurl;
|
i2p::http::URL proxyurl;
|
||||||
uint16_t softLimit, hardLimit, threads;
|
uint16_t softLimit, hardLimit, threads;
|
||||||
i2p::config::GetOption("limits.ntcpsoft", softLimit);
|
i2p::config::GetOption("limits.ntcpsoft", softLimit);
|
||||||
|
@ -201,7 +201,7 @@ namespace transport
|
||||||
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
||||||
if (ntcp2)
|
if (ntcp2)
|
||||||
{
|
{
|
||||||
if(ntcp2proxy.size())
|
if(!ntcp2proxy.empty())
|
||||||
{
|
{
|
||||||
if(proxyurl.parse(ntcp2proxy))
|
if(proxyurl.parse(ntcp2proxy))
|
||||||
{
|
{
|
||||||
|
@ -223,9 +223,11 @@ namespace transport
|
||||||
LogPrint(eLogError, "Transports: invalid NTCP2 proxy url ", ntcp2proxy);
|
LogPrint(eLogError, "Transports: invalid NTCP2 proxy url ", ntcp2proxy);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// m_NTCP2Server = new NTCP2Server ();
|
{
|
||||||
// m_NTCP2Server->Start ();
|
m_NTCP2Server = new NTCP2Server ();
|
||||||
|
m_NTCP2Server->Start ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create acceptors
|
// create acceptors
|
||||||
|
|
Loading…
Add table
Reference in a new issue