Browse Source

I2PControl method

pull/150/head
orignal 10 years ago
parent
commit
25cc118890
  1. 22
      I2PControl.cpp
  2. 14
      I2PControl.h

22
I2PControl.cpp

@ -17,12 +17,13 @@ namespace i2p
namespace client namespace client
{ {
I2PControlService::I2PControlService (int port): I2PControlService::I2PControlService (int port):
m_IsRunning (false), m_Thread (nullptr), m_Password (I2P_CONTROL_DEFAULT_PASSWORD), m_IsRunning (false), m_Thread (nullptr),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)), m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)),
m_ShutdownTimer (m_Service) m_ShutdownTimer (m_Service)
{ {
m_MethodHandlers[I2P_CONTROL_METHOD_AUTHENTICATE] = &I2PControlService::AuthenticateHandler; m_MethodHandlers[I2P_CONTROL_METHOD_AUTHENTICATE] = &I2PControlService::AuthenticateHandler;
m_MethodHandlers[I2P_CONTROL_METHOD_ECHO] = &I2PControlService::EchoHandler; m_MethodHandlers[I2P_CONTROL_METHOD_ECHO] = &I2PControlService::EchoHandler;
m_MethodHandlers[I2P_CONTROL_METHOD_I2PCONTROL] = &I2PControlService::I2PControlHandler;
m_MethodHandlers[I2P_CONTROL_METHOD_ROUTER_INFO] = &I2PControlService::RouterInfoHandler; m_MethodHandlers[I2P_CONTROL_METHOD_ROUTER_INFO] = &I2PControlService::RouterInfoHandler;
m_MethodHandlers[I2P_CONTROL_METHOD_ROUTER_MANAGER] = &I2PControlService::RouterManagerHandler; m_MethodHandlers[I2P_CONTROL_METHOD_ROUTER_MANAGER] = &I2PControlService::RouterManagerHandler;
m_MethodHandlers[I2P_CONTROL_METHOD_NETWORK_SETTING] = &I2PControlService::NetworkSettingHandler; m_MethodHandlers[I2P_CONTROL_METHOD_NETWORK_SETTING] = &I2PControlService::NetworkSettingHandler;
@ -195,6 +196,8 @@ namespace client
const std::string& api = params.at (I2P_CONTROL_PARAM_API); const std::string& api = params.at (I2P_CONTROL_PARAM_API);
const std::string& password = params.at (I2P_CONTROL_PARAM_PASSWORD); const std::string& password = params.at (I2P_CONTROL_PARAM_PASSWORD);
LogPrint (eLogDebug, "I2PControl Authenticate API=", api, " Password=", password); LogPrint (eLogDebug, "I2PControl Authenticate API=", api, " Password=", password);
if (password != m_Password)
LogPrint (eLogError, "I2PControl Authenticate Invalid password ", password, " expected ", m_Password);
results[I2P_CONTROL_PARAM_API] = api; results[I2P_CONTROL_PARAM_API] = api;
results[I2P_CONTROL_PARAM_TOKEN] = boost::lexical_cast<std::string>(i2p::util::GetSecondsSinceEpoch ()); results[I2P_CONTROL_PARAM_TOKEN] = boost::lexical_cast<std::string>(i2p::util::GetSecondsSinceEpoch ());
} }
@ -206,6 +209,23 @@ namespace client
results[I2P_CONTROL_PARAM_RESULT] = echo; results[I2P_CONTROL_PARAM_RESULT] = echo;
} }
// I2PControl
void I2PControlService::I2PControlHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results)
{
LogPrint (eLogDebug, "I2PControl I2PControl");
for (auto& it: params)
{
LogPrint (eLogDebug, it.first);
auto it1 = m_I2PControlHandlers.find (it.first);
if (it1 != m_I2PControlHandlers.end ())
(this->*(it1->second))(it.second);
else
LogPrint (eLogError, "I2PControl NetworkSetting unknown request ", it.first);
}
}
// RouterInfo // RouterInfo
void I2PControlService::RouterInfoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results) void I2PControlService::RouterInfoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results)

14
I2PControl.h

@ -16,6 +16,8 @@ namespace client
const size_t I2P_CONTROL_MAX_REQUEST_SIZE = 1024; const size_t I2P_CONTROL_MAX_REQUEST_SIZE = 1024;
typedef std::array<char, I2P_CONTROL_MAX_REQUEST_SIZE> I2PControlBuffer; typedef std::array<char, I2P_CONTROL_MAX_REQUEST_SIZE> I2PControlBuffer;
const char I2P_CONTROL_DEFAULT_PASSWORD[] = "itoopie";
const char I2P_CONTROL_PROPERTY_ID[] = "id"; const char I2P_CONTROL_PROPERTY_ID[] = "id";
const char I2P_CONTROL_PROPERTY_METHOD[] = "method"; const char I2P_CONTROL_PROPERTY_METHOD[] = "method";
const char I2P_CONTROL_PROPERTY_PARAMS[] = "params"; const char I2P_CONTROL_PROPERTY_PARAMS[] = "params";
@ -24,6 +26,7 @@ namespace client
// methods // methods
const char I2P_CONTROL_METHOD_AUTHENTICATE[] = "Authenticate"; const char I2P_CONTROL_METHOD_AUTHENTICATE[] = "Authenticate";
const char I2P_CONTROL_METHOD_ECHO[] = "Echo"; const char I2P_CONTROL_METHOD_ECHO[] = "Echo";
const char I2P_CONTROL_METHOD_I2PCONTROL[] = "I2PControl";
const char I2P_CONTROL_METHOD_ROUTER_INFO[] = "RouterInfo"; const char I2P_CONTROL_METHOD_ROUTER_INFO[] = "RouterInfo";
const char I2P_CONTROL_METHOD_ROUTER_MANAGER[] = "RouterManager"; const char I2P_CONTROL_METHOD_ROUTER_MANAGER[] = "RouterManager";
const char I2P_CONTROL_METHOD_NETWORK_SETTING[] = "NetworkSetting"; const char I2P_CONTROL_METHOD_NETWORK_SETTING[] = "NetworkSetting";
@ -35,6 +38,11 @@ namespace client
const char I2P_CONTROL_PARAM_ECHO[] = "Echo"; const char I2P_CONTROL_PARAM_ECHO[] = "Echo";
const char I2P_CONTROL_PARAM_RESULT[] = "Result"; const char I2P_CONTROL_PARAM_RESULT[] = "Result";
// I2PControl
const char I2P_CONTROL_I2PCONTROL_ADDRESS[] = "i2pcontrol.address";
const char I2P_CONTROL_I2PCONTROL_PASSWORD[] = "i2pcontrol.password";
const char I2P_CONTROL_I2PCONTROL_PORT[] = "i2pcontrol.port";
// RouterInfo requests // RouterInfo requests
const char I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS[] = "i2p.router.netdb.knownpeers"; const char I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS[] = "i2p.router.netdb.knownpeers";
const char I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS[] = "i2p.router.netdb.activepeers"; const char I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS[] = "i2p.router.netdb.activepeers";
@ -75,10 +83,14 @@ namespace client
void AuthenticateHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results); void AuthenticateHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results);
void EchoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results); void EchoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results);
void I2PControlHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results);
void RouterInfoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results); void RouterInfoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results);
void RouterManagerHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results); void RouterManagerHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results);
void NetworkSettingHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results); void NetworkSettingHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results);
// I2PControl
typedef void (I2PControlService::*I2PControlRequestHandler)(const std::string& value);
// RouterInfo // RouterInfo
typedef void (I2PControlService::*RouterInfoRequestHandler)(std::map<std::string, std::string>& results); typedef void (I2PControlService::*RouterInfoRequestHandler)(std::map<std::string, std::string>& results);
void NetDbKnownPeersHandler (std::map<std::string, std::string>& results); void NetDbKnownPeersHandler (std::map<std::string, std::string>& results);
@ -95,6 +107,7 @@ namespace client
private: private:
std::string m_Password;
bool m_IsRunning; bool m_IsRunning;
std::thread * m_Thread; std::thread * m_Thread;
@ -103,6 +116,7 @@ namespace client
boost::asio::deadline_timer m_ShutdownTimer; boost::asio::deadline_timer m_ShutdownTimer;
std::map<std::string, MethodHandler> m_MethodHandlers; std::map<std::string, MethodHandler> m_MethodHandlers;
std::map<std::string, I2PControlRequestHandler> m_I2PControlHandlers;
std::map<std::string, RouterInfoRequestHandler> m_RouterInfoHandlers; std::map<std::string, RouterInfoRequestHandler> m_RouterInfoHandlers;
std::map<std::string, RouterManagerRequestHandler> m_RouterManagerHandlers; std::map<std::string, RouterManagerRequestHandler> m_RouterManagerHandlers;
std::map<std::string, NetworkSettingRequestHandler> m_NetworkSettingHandlers; std::map<std::string, NetworkSettingRequestHandler> m_NetworkSettingHandlers;

Loading…
Cancel
Save