mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-13 01:20:22 +03:00
Make the HTTP Proxy use TCPIPAcceptor
This commit is contained in:
parent
114022d18a
commit
8a6bea64bc
@ -231,41 +231,9 @@ namespace proxy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPProxyServer::Start ()
|
std::shared_ptr<i2p::client::I2PServiceHandler> HTTPProxyServer::CreateHandler(boost::asio::ip::tcp::socket * socket)
|
||||||
{
|
{
|
||||||
m_Acceptor.listen ();
|
return std::make_shared<HTTPProxyHandler> (this, socket);
|
||||||
Accept ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HTTPProxyServer::Stop ()
|
|
||||||
{
|
|
||||||
m_Acceptor.close();
|
|
||||||
m_Timer.cancel ();
|
|
||||||
ClearHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HTTPProxyServer::Accept ()
|
|
||||||
{
|
|
||||||
auto newSocket = new boost::asio::ip::tcp::socket (GetService ());
|
|
||||||
m_Acceptor.async_accept (*newSocket, std::bind (&HTTPProxyServer::HandleAccept, this,
|
|
||||||
std::placeholders::_1, newSocket));
|
|
||||||
}
|
|
||||||
|
|
||||||
void HTTPProxyServer::HandleAccept (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket)
|
|
||||||
{
|
|
||||||
if (!ecode)
|
|
||||||
{
|
|
||||||
LogPrint(eLogDebug,"--- HTTP Proxy accepted");
|
|
||||||
auto handler = std::make_shared<HTTPProxyHandler> (this, socket);
|
|
||||||
AddHandler(handler);
|
|
||||||
handler->Handle();
|
|
||||||
Accept();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogPrint (eLogError,"--- HTTP Proxy Closing socket on accept because: ", ecode.message ());
|
|
||||||
delete socket;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
25
HTTPProxy.h
25
HTTPProxy.h
@ -12,27 +12,16 @@ namespace i2p
|
|||||||
namespace proxy
|
namespace proxy
|
||||||
{
|
{
|
||||||
class HTTPProxyHandler;
|
class HTTPProxyHandler;
|
||||||
class HTTPProxyServer: public i2p::client::I2PService
|
class HTTPProxyServer: public i2p::client::TCPIPAcceptor
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
std::set<std::shared_ptr<HTTPProxyHandler> > m_Handlers;
|
// Implements TCPIPAcceptor
|
||||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
std::shared_ptr<i2p::client::I2PServiceHandler> CreateHandler(boost::asio::ip::tcp::socket * socket);
|
||||||
boost::asio::deadline_timer m_Timer;
|
const char* GetName() { return "HTTP Proxy"; }
|
||||||
std::mutex m_HandlersMutex;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void Accept();
|
|
||||||
void HandleAccept(const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HTTPProxyServer(int port) : I2PService(i2p::data::SIGNING_KEY_TYPE_DSA_SHA1),
|
HTTPProxyServer(int port) : TCPIPAcceptor(port, i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) {}
|
||||||
m_Acceptor (GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
|
~HTTPProxyServer() {}
|
||||||
m_Timer (GetService ()) {};
|
|
||||||
~HTTPProxyServer() { Stop(); }
|
|
||||||
|
|
||||||
void Start ();
|
|
||||||
void Stop ();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef HTTPProxyServer HTTPProxy;
|
typedef HTTPProxyServer HTTPProxy;
|
||||||
|
Loading…
Reference in New Issue
Block a user