mirror of https://github.com/PurpleI2P/i2pd.git
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.
123 lines
5.0 KiB
123 lines
5.0 KiB
![]()
10 years ago
|
#ifndef I2P_CONTROL_H__
|
||
|
#define I2P_CONTROL_H__
|
||
|
|
||
![]()
10 years ago
|
#include <inttypes.h>
|
||
![]()
10 years ago
|
#include <thread>
|
||
![]()
10 years ago
|
#include <memory>
|
||
|
#include <array>
|
||
|
#include <string>
|
||
![]()
10 years ago
|
#include <sstream>
|
||
![]()
10 years ago
|
#include <map>
|
||
![]()
10 years ago
|
#include <set>
|
||
![]()
10 years ago
|
#include <boost/asio.hpp>
|
||
![]()
8 years ago
|
#include <boost/asio/ssl.hpp>
|
||
![]()
10 years ago
|
#include <boost/property_tree/ptree.hpp>
|
||
![]()
10 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace client
|
||
|
{
|
||
![]()
10 years ago
|
const size_t I2P_CONTROL_MAX_REQUEST_SIZE = 1024;
|
||
![]()
9 years ago
|
typedef std::array<char, I2P_CONTROL_MAX_REQUEST_SIZE> I2PControlBuffer;
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
const long I2P_CONTROL_CERTIFICATE_VALIDITY = 365*10; // 10 years
|
||
|
const char I2P_CONTROL_CERTIFICATE_COMMON_NAME[] = "i2pd.i2pcontrol";
|
||
|
const char I2P_CONTROL_CERTIFICATE_ORGANIZATION[] = "Purple I2P";
|
||
|
|
||
![]()
10 years ago
|
class I2PControlService
|
||
|
{
|
||
![]()
9 years ago
|
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
|
||
![]()
10 years ago
|
public:
|
||
|
|
||
![]()
9 years ago
|
I2PControlService (const std::string& address, int port);
|
||
![]()
10 years ago
|
~I2PControlService ();
|
||
|
|
||
|
void Start ();
|
||
|
void Stop ();
|
||
|
|
||
|
private:
|
||
|
|
||
|
void Run ();
|
||
|
void Accept ();
|
||
![]()
9 years ago
|
void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<ssl_socket> socket);
|
||
![]()
9 years ago
|
void Handshake (std::shared_ptr<ssl_socket> socket);
|
||
|
void HandleHandshake (const boost::system::error_code& ecode, std::shared_ptr<ssl_socket> socket);
|
||
![]()
9 years ago
|
void ReadRequest (std::shared_ptr<ssl_socket> socket);
|
||
![]()
9 years ago
|
void HandleRequestReceived (const boost::system::error_code& ecode, size_t bytes_transferred,
|
||
![]()
9 years ago
|
std::shared_ptr<ssl_socket> socket, std::shared_ptr<I2PControlBuffer> buf);
|
||
|
void SendResponse (std::shared_ptr<ssl_socket> socket,
|
||
![]()
8 years ago
|
std::shared_ptr<I2PControlBuffer> buf, std::ostringstream& response, bool isHtml);
|
||
![]()
10 years ago
|
void HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred,
|
||
![]()
9 years ago
|
std::shared_ptr<ssl_socket> socket, std::shared_ptr<I2PControlBuffer> buf);
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
void CreateCertificate (const char *crt_path, const char *key_path);
|
||
![]()
9 years ago
|
|
||
![]()
10 years ago
|
private:
|
||
|
|
||
![]()
10 years ago
|
void InsertParam (std::ostringstream& ss, const std::string& name, int value) const;
|
||
|
void InsertParam (std::ostringstream& ss, const std::string& name, double value) const;
|
||
|
void InsertParam (std::ostringstream& ss, const std::string& name, const std::string& value) const;
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
// methods
|
||
![]()
10 years ago
|
typedef void (I2PControlService::*MethodHandler)(const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
void AuthenticateHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
|
void EchoHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
|
void I2PControlHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
|
void RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
|
void RouterManagerHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
![]()
9 years ago
|
void NetworkSettingHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
// I2PControl
|
||
|
typedef void (I2PControlService::*I2PControlRequestHandler)(const std::string& value);
|
||
![]()
9 years ago
|
void PasswordHandler (const std::string& value);
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
// RouterInfo
|
||
![]()
10 years ago
|
typedef void (I2PControlService::*RouterInfoRequestHandler)(std::ostringstream& results);
|
||
|
void UptimeHandler (std::ostringstream& results);
|
||
|
void VersionHandler (std::ostringstream& results);
|
||
|
void StatusHandler (std::ostringstream& results);
|
||
|
void NetDbKnownPeersHandler (std::ostringstream& results);
|
||
![]()
9 years ago
|
void NetDbActivePeersHandler (std::ostringstream& results);
|
||
|
void NetStatusHandler (std::ostringstream& results);
|
||
![]()
10 years ago
|
void TunnelsParticipatingHandler (std::ostringstream& results);
|
||
![]()
8 years ago
|
void TunnelsSuccessRateHandler (std::ostringstream& results);
|
||
![]()
10 years ago
|
void InboundBandwidth1S (std::ostringstream& results);
|
||
|
void OutboundBandwidth1S (std::ostringstream& results);
|
||
![]()
9 years ago
|
void NetTotalReceivedBytes (std::ostringstream& results);
|
||
|
void NetTotalSentBytes (std::ostringstream& results);
|
||
![]()
10 years ago
|
|
||
|
// RouterManager
|
||
![]()
10 years ago
|
typedef void (I2PControlService::*RouterManagerRequestHandler)(std::ostringstream& results);
|
||
|
void ShutdownHandler (std::ostringstream& results);
|
||
|
void ShutdownGracefulHandler (std::ostringstream& results);
|
||
|
void ReseedHandler (std::ostringstream& results);
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
// NetworkSetting
|
||
![]()
9 years ago
|
typedef void (I2PControlService::*NetworkSettingRequestHandler)(const std::string& value, std::ostringstream& results);
|
||
![]()
9 years ago
|
void InboundBandwidthLimit (const std::string& value, std::ostringstream& results);
|
||
|
void OutboundBandwidthLimit (const std::string& value, std::ostringstream& results);
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
private:
|
||
|
|
||
![]()
10 years ago
|
std::string m_Password;
|
||
![]()
10 years ago
|
bool m_IsRunning;
|
||
![]()
9 years ago
|
std::thread * m_Thread;
|
||
![]()
10 years ago
|
|
||
|
boost::asio::io_service m_Service;
|
||
![]()
10 years ago
|
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||
![]()
9 years ago
|
boost::asio::ssl::context m_SSLContext;
|
||
![]()
10 years ago
|
boost::asio::deadline_timer m_ShutdownTimer;
|
||
![]()
10 years ago
|
std::set<std::string> m_Tokens;
|
||
![]()
9 years ago
|
|
||
![]()
10 years ago
|
std::map<std::string, MethodHandler> m_MethodHandlers;
|
||
![]()
10 years ago
|
std::map<std::string, I2PControlRequestHandler> m_I2PControlHandlers;
|
||
![]()
10 years ago
|
std::map<std::string, RouterInfoRequestHandler> m_RouterInfoHandlers;
|
||
|
std::map<std::string, RouterManagerRequestHandler> m_RouterManagerHandlers;
|
||
![]()
10 years ago
|
std::map<std::string, NetworkSettingRequestHandler> m_NetworkSettingHandlers;
|
||
![]()
10 years ago
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|