I2P: End-to-End encrypted and anonymous Internet https://i2pd.website/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.2 KiB

10 years ago
#ifndef SOCKS4A_H__
#define SOCKS4A_H__
#include <memory>
#include <boost/asio.hpp>
10 years ago
#include "Identity.h"
#include "Streaming.h"
#include "I2PTunnel.h"
10 years ago
namespace i2p
{
namespace proxy
{
const size_t socks_buffer_size = 8192;
10 years ago
class SOCKS4AServer;
10 years ago
class SOCKS4AHandler {
private:
enum state {
INITIAL,
OKAY,
END
};
void GotClientRequest(boost::system::error_code & ecode, std::string & host, uint16_t port);
void HandleSockRecv(const boost::system::error_code & ecode, std::size_t bytes_transfered);
void Terminate();
void CloseSock();
void CloseStream();
void AsyncSockRead();
void SocksFailed();
void SentSocksFailed(const boost::system::error_code & ecode);
10 years ago
void SentConnectionSuccess(const boost::system::error_code & ecode);
void ConnectionSuccess();
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
10 years ago
uint8_t m_sock_buff[socks_buffer_size];
SOCKS4AServer * m_parent;
10 years ago
boost::asio::ip::tcp::socket * m_sock;
std::shared_ptr<i2p::stream::Stream> m_stream;
10 years ago
state m_state;
public:
SOCKS4AHandler(SOCKS4AServer * parent, boost::asio::ip::tcp::socket * sock) :
m_parent(parent), m_sock(sock), m_stream(nullptr), m_state(INITIAL)
{ AsyncSockRead(); }
10 years ago
~SOCKS4AHandler() { CloseSock(); CloseStream(); }
bool isComplete() { return m_state == END; }
};
class SOCKS4AServer: public i2p::client::I2PTunnel
{
10 years ago
public:
SOCKS4AServer(int port) : I2PTunnel(nullptr),
m_Acceptor (GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Timer (GetService ()) {};
10 years ago
~SOCKS4AServer() { Stop(); }
void Start ();
void Stop ();
10 years ago
private:
10 years ago
void Accept();
void HandleAccept(const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket);
10 years ago
private:
boost::asio::ip::tcp::acceptor m_Acceptor;
boost::asio::deadline_timer m_Timer;
};
10 years ago
typedef SOCKS4AServer SOCKSProxy;
}
}
#endif