2015-08-01 14:48:35 +00:00
|
|
|
#ifndef I2P_CONTROL_SERVER_H__
|
|
|
|
#define I2P_CONTROL_SERVER_H__
|
|
|
|
|
|
|
|
#include "I2PControl.h"
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <thread>
|
|
|
|
#include <memory>
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
|
|
|
|
namespace i2p {
|
|
|
|
namespace client {
|
2015-09-17 14:49:55 +00:00
|
|
|
namespace i2pcontrol {
|
2015-08-01 14:48:35 +00:00
|
|
|
|
|
|
|
const size_t I2P_CONTROL_MAX_REQUEST_SIZE = 1024;
|
|
|
|
typedef std::array<char, I2P_CONTROL_MAX_REQUEST_SIZE> I2PControlBuffer;
|
|
|
|
|
|
|
|
class I2PControlService {
|
|
|
|
public:
|
|
|
|
|
2015-08-02 17:59:16 +00:00
|
|
|
I2PControlService(const std::string& address, int port, const std::string& pass);
|
2015-08-02 20:01:09 +00:00
|
|
|
~I2PControlService();
|
2015-08-01 14:48:35 +00:00
|
|
|
|
2015-08-02 20:01:09 +00:00
|
|
|
void Start();
|
|
|
|
void Stop();
|
2015-08-01 14:48:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-08-02 20:01:09 +00:00
|
|
|
void Run();
|
|
|
|
void Accept();
|
2015-08-01 14:48:35 +00:00
|
|
|
void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
|
2015-08-02 20:01:09 +00:00
|
|
|
void ReadRequest(std::shared_ptr<boost::asio::ip::tcp::socket> socket);
|
|
|
|
void HandleRequestReceived(const boost::system::error_code& ecode, size_t bytes_transferred,
|
2015-08-01 14:48:35 +00:00
|
|
|
std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<I2PControlBuffer> buf);
|
2015-08-02 20:01:09 +00:00
|
|
|
void SendResponse(std::shared_ptr<boost::asio::ip::tcp::socket> socket,
|
2015-08-01 14:48:35 +00:00
|
|
|
std::shared_ptr<I2PControlBuffer> buf, const std::string& response, bool isHtml);
|
2015-08-02 20:01:09 +00:00
|
|
|
void HandleResponseSent(const boost::system::error_code& ecode, std::size_t bytes_transferred,
|
2015-08-01 14:48:35 +00:00
|
|
|
std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<I2PControlBuffer> buf);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-08-30 10:33:09 +00:00
|
|
|
std::shared_ptr<I2PControlSession> m_Session;
|
|
|
|
|
2015-08-01 14:48:35 +00:00
|
|
|
bool m_IsRunning;
|
|
|
|
std::thread * m_Thread;
|
|
|
|
|
|
|
|
boost::asio::io_service m_Service;
|
|
|
|
boost::asio::ip::tcp::acceptor m_Acceptor;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2015-09-17 14:49:55 +00:00
|
|
|
}
|
2015-08-01 14:48:35 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|