mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-24 01:46:36 +02:00
[httpproxy] make addresshelper support configurable for every httpproxy
This commit is contained in:
parent
5e42947fbd
commit
ece140f18c
3 changed files with 63 additions and 57 deletions
|
@ -540,7 +540,8 @@ namespace client
|
||||||
{
|
{
|
||||||
// http proxy
|
// http proxy
|
||||||
std::string outproxy = section.second.get("outproxy", "");
|
std::string outproxy = section.second.get("outproxy", "");
|
||||||
auto tun = std::make_shared<i2p::proxy::HTTPProxy>(name, address, port, outproxy, localDestination);
|
bool addresshelper = section.second.get("addresshelper", true);
|
||||||
|
auto tun = std::make_shared<i2p::proxy::HTTPProxy>(name, address, port, outproxy, addresshelper, localDestination);
|
||||||
clientTunnel = tun;
|
clientTunnel = tun;
|
||||||
clientEndpoint = tun->GetLocalEndpoint ();
|
clientEndpoint = tun->GetLocalEndpoint ();
|
||||||
}
|
}
|
||||||
|
@ -716,6 +717,7 @@ namespace client
|
||||||
uint16_t httpProxyPort; i2p::config::GetOption("httpproxy.port", httpProxyPort);
|
uint16_t httpProxyPort; i2p::config::GetOption("httpproxy.port", httpProxyPort);
|
||||||
i2p::data::SigningKeyType sigType; i2p::config::GetOption("httpproxy.signaturetype", sigType);
|
i2p::data::SigningKeyType sigType; i2p::config::GetOption("httpproxy.signaturetype", sigType);
|
||||||
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);
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -732,7 +734,7 @@ namespace client
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, localDestination);
|
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, httpAddresshelper, localDestination);
|
||||||
m_HttpProxy->Start();
|
m_HttpProxy->Start();
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
|
|
|
@ -64,44 +64,47 @@ namespace proxy {
|
||||||
void HostNotFound(std::string & host);
|
void HostNotFound(std::string & host);
|
||||||
void SendProxyError(std::string & content);
|
void SendProxyError(std::string & content);
|
||||||
|
|
||||||
void ForwardToUpstreamProxy();
|
void ForwardToUpstreamProxy();
|
||||||
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
||||||
void HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec);
|
void HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec);
|
||||||
void HTTPConnect(const std::string & host, uint16_t port);
|
void HTTPConnect(const std::string & host, uint16_t port);
|
||||||
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
|
|
||||||
void HandleSocksProxySendHandshake(const boost::system::error_code & ec, std::size_t bytes_transfered);
|
void HandleSocksProxySendHandshake(const boost::system::error_code & ec, std::size_t bytes_transfered);
|
||||||
void HandleSocksProxyReply(const boost::system::error_code & ec, std::size_t bytes_transfered);
|
void HandleSocksProxyReply(const boost::system::error_code & ec, std::size_t bytes_transfered);
|
||||||
|
|
||||||
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
||||||
|
|
||||||
void HandleUpstreamProxyResolved(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr, ProxyResolvedHandler handler);
|
void HandleUpstreamProxyResolved(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr, ProxyResolvedHandler handler);
|
||||||
|
|
||||||
void SocksProxySuccess();
|
void SocksProxySuccess();
|
||||||
void HandoverToUpstreamProxy();
|
void HandoverToUpstreamProxy();
|
||||||
|
|
||||||
uint8_t m_recv_chunk[8192];
|
uint8_t m_recv_chunk[8192];
|
||||||
std::string m_recv_buf; // from client
|
std::string m_recv_buf; // from client
|
||||||
std::string m_send_buf; // to upstream
|
std::string m_send_buf; // to upstream
|
||||||
std::shared_ptr<boost::asio::ip::tcp::socket> m_sock;
|
std::shared_ptr<boost::asio::ip::tcp::socket> m_sock;
|
||||||
std::shared_ptr<boost::asio::ip::tcp::socket> m_proxysock;
|
std::shared_ptr<boost::asio::ip::tcp::socket> m_proxysock;
|
||||||
boost::asio::ip::tcp::resolver m_proxy_resolver;
|
boost::asio::ip::tcp::resolver m_proxy_resolver;
|
||||||
std::string m_OutproxyUrl;
|
std::string m_OutproxyUrl;
|
||||||
i2p::http::URL m_ProxyURL;
|
bool m_Addresshelper;
|
||||||
i2p::http::URL m_RequestURL;
|
i2p::http::URL m_ProxyURL;
|
||||||
uint8_t m_socks_buf[255+8]; // for socks request/response
|
i2p::http::URL m_RequestURL;
|
||||||
ssize_t m_req_len;
|
uint8_t m_socks_buf[255+8]; // for socks request/response
|
||||||
i2p::http::URL m_ClientRequestURL;
|
ssize_t m_req_len;
|
||||||
i2p::http::HTTPReq m_ClientRequest;
|
i2p::http::URL m_ClientRequestURL;
|
||||||
i2p::http::HTTPRes m_ClientResponse;
|
i2p::http::HTTPReq m_ClientRequest;
|
||||||
std::stringstream m_ClientRequestBuffer;
|
i2p::http::HTTPRes m_ClientResponse;
|
||||||
|
std::stringstream m_ClientRequestBuffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HTTPReqHandler(HTTPProxy * parent, std::shared_ptr<boost::asio::ip::tcp::socket> sock) :
|
HTTPReqHandler(HTTPProxy * parent, std::shared_ptr<boost::asio::ip::tcp::socket> sock) :
|
||||||
I2PServiceHandler(parent), m_sock(sock),
|
I2PServiceHandler(parent), m_sock(sock),
|
||||||
m_proxysock(std::make_shared<boost::asio::ip::tcp::socket>(parent->GetService())),
|
m_proxysock(std::make_shared<boost::asio::ip::tcp::socket>(parent->GetService())),
|
||||||
m_proxy_resolver(parent->GetService()),
|
m_proxy_resolver(parent->GetService()),
|
||||||
m_OutproxyUrl(parent->GetOutproxyURL()) {}
|
m_OutproxyUrl(parent->GetOutproxyURL()),
|
||||||
|
m_Addresshelper(parent->GetHelperSupport()) {}
|
||||||
~HTTPReqHandler() { Terminate(); }
|
~HTTPReqHandler() { Terminate(); }
|
||||||
void Handle () { AsyncSockRead(); } /* overload */
|
void Handle () { AsyncSockRead(); } /* overload */
|
||||||
};
|
};
|
||||||
|
@ -114,8 +117,8 @@ namespace proxy {
|
||||||
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)),
|
||||||
std::bind(&HTTPReqHandler::HandleSockRecv, shared_from_this(),
|
std::bind(&HTTPReqHandler::HandleSockRecv, shared_from_this(),
|
||||||
std::placeholders::_1, std::placeholders::_2));
|
std::placeholders::_1, std::placeholders::_2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::Terminate() {
|
void HTTPReqHandler::Terminate() {
|
||||||
|
@ -253,8 +256,7 @@ namespace proxy {
|
||||||
std::string jump;
|
std::string jump;
|
||||||
if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm))
|
if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm))
|
||||||
{
|
{
|
||||||
bool addresshelper; i2p::config::GetOption("httpproxy.addresshelper", addresshelper);
|
if (!m_Addresshelper)
|
||||||
if (!addresshelper)
|
|
||||||
{
|
{
|
||||||
LogPrint(eLogWarning, "HTTPProxy: addresshelper request rejected");
|
LogPrint(eLogWarning, "HTTPProxy: addresshelper request rejected");
|
||||||
GenericProxyError("Invalid request", "addresshelper is not supported");
|
GenericProxyError("Invalid request", "addresshelper is not supported");
|
||||||
|
@ -509,7 +511,7 @@ namespace proxy {
|
||||||
std::string hostname(host);
|
std::string hostname(host);
|
||||||
if(str_rmatch(hostname, ".i2p"))
|
if(str_rmatch(hostname, ".i2p"))
|
||||||
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
||||||
shared_from_this(), std::placeholders::_1), host, port);
|
shared_from_this(), std::placeholders::_1), host, port);
|
||||||
else
|
else
|
||||||
ForwardToUpstreamProxy();
|
ForwardToUpstreamProxy();
|
||||||
}
|
}
|
||||||
|
@ -621,9 +623,9 @@ namespace proxy {
|
||||||
Done (shared_from_this());
|
Done (shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPProxy::HTTPProxy(const std::string& name, const std::string& address, int port, const std::string & outproxy, std::shared_ptr<i2p::client::ClientDestination> localDestination):
|
HTTPProxy::HTTPProxy(const std::string& name, const std::string& address, int port, const std::string & outproxy, bool addresshelper, std::shared_ptr<i2p::client::ClientDestination> localDestination):
|
||||||
TCPIPAcceptor(address, port, localDestination ? localDestination : i2p::client::context.GetSharedLocalDestination ()),
|
TCPIPAcceptor (address, port, localDestination ? localDestination : i2p::client::context.GetSharedLocalDestination ()),
|
||||||
m_Name (name), m_OutproxyUrl(outproxy)
|
m_Name (name), m_OutproxyUrl (outproxy), m_Addresshelper (addresshelper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,13 @@ namespace proxy {
|
||||||
class HTTPProxy: public i2p::client::TCPIPAcceptor
|
class HTTPProxy: public i2p::client::TCPIPAcceptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HTTPProxy(const std::string& name, const std::string& address, int port, const std::string & outproxy, std::shared_ptr<i2p::client::ClientDestination> localDestination);
|
HTTPProxy(const std::string& name, const std::string& address, int port, const std::string & outproxy, bool addresshelper, std::shared_ptr<i2p::client::ClientDestination> localDestination);
|
||||||
HTTPProxy(const std::string& name, const std::string& address, int port, std::shared_ptr<i2p::client::ClientDestination> localDestination = nullptr) :
|
HTTPProxy(const std::string& name, const std::string& address, int port, std::shared_ptr<i2p::client::ClientDestination> localDestination = nullptr) :
|
||||||
HTTPProxy(name, address, port, "", localDestination) {} ;
|
HTTPProxy(name, address, port, "", true, localDestination) {} ;
|
||||||
~HTTPProxy() {};
|
~HTTPProxy() {};
|
||||||
|
|
||||||
std::string GetOutproxyURL() const { return m_OutproxyUrl; }
|
std::string GetOutproxyURL() const { return m_OutproxyUrl; }
|
||||||
|
bool GetHelperSupport() { return m_Addresshelper; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Implements TCPIPAcceptor
|
// Implements TCPIPAcceptor
|
||||||
|
@ -21,6 +22,7 @@ namespace proxy {
|
||||||
private:
|
private:
|
||||||
std::string m_Name;
|
std::string m_Name;
|
||||||
std::string m_OutproxyUrl;
|
std::string m_OutproxyUrl;
|
||||||
|
bool m_Addresshelper;
|
||||||
};
|
};
|
||||||
} // http
|
} // http
|
||||||
} // i2p
|
} // i2p
|
||||||
|
|
Loading…
Add table
Reference in a new issue