From 9890bf98e4ed76ac39da580c9c1cbe4fc79103b6 Mon Sep 17 00:00:00 2001 From: EinMByte Date: Thu, 17 Sep 2015 16:49:55 +0200 Subject: [PATCH] Add more information to webui. --- client/ClientContext.cpp | 6 +- client/ClientContext.h | 2 +- client/HTTPServer.cpp | 6 +- client/HTTPServer.h | 6 +- client/i2pcontrol/I2PControl.cpp | 138 ++++++++++++++++--------- client/i2pcontrol/I2PControl.h | 82 +++++++++------ client/i2pcontrol/I2PControlServer.cpp | 2 + client/i2pcontrol/I2PControlServer.h | 2 + webui/footer.html | 6 ++ webui/help.html | 8 +- webui/index.html | 26 +++-- webui/menu.html | 3 + webui/netdb.html | 59 +++++++++++ 13 files changed, 239 insertions(+), 107 deletions(-) create mode 100644 webui/footer.html create mode 100644 webui/netdb.html diff --git a/client/ClientContext.cpp b/client/ClientContext.cpp index 2cc46ae6..442b5929 100644 --- a/client/ClientContext.cpp +++ b/client/ClientContext.cpp @@ -114,10 +114,12 @@ namespace client // I2P Control int i2pcontrolPort = i2p::util::config::GetArg("-i2pcontrolport", 0); if(i2pcontrolPort) { - m_I2PControlService = new I2PControlService( + m_I2PControlService = new i2pcontrol::I2PControlService( i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"), i2pcontrolPort, - i2p::util::config::GetArg("-i2pcontrolpassword", I2P_CONTROL_DEFAULT_PASSWORD) + i2p::util::config::GetArg( + "-i2pcontrolpassword", i2pcontrol::constants::DEFAULT_PASSWORD + ) ); m_I2PControlService->Start(); LogPrint("I2PControl started"); diff --git a/client/ClientContext.h b/client/ClientContext.h index 33d1960f..d552fa8a 100644 --- a/client/ClientContext.h +++ b/client/ClientContext.h @@ -72,7 +72,7 @@ namespace client std::map > m_ServerTunnels; // destination->tunnel SAMBridge * m_SamBridge; BOBCommandChannel * m_BOBCommandChannel; - I2PControlService * m_I2PControlService; + i2pcontrol::I2PControlService * m_I2PControlService; public: // for HTTP diff --git a/client/HTTPServer.cpp b/client/HTTPServer.cpp index 1a73272c..448695cd 100644 --- a/client/HTTPServer.cpp +++ b/client/HTTPServer.cpp @@ -36,7 +36,7 @@ const char HTTP_COMMAND_SAM_SESSION[] = "sam_session"; const char HTTP_PARAM_SAM_SESSION_ID[] = "id"; HTTPConnection::HTTPConnection(boost::asio::ip::tcp::socket* socket, - std::shared_ptr session) + std::shared_ptr session) : m_Socket(socket), m_Timer(socket->get_io_service()), m_BufferLen(0), m_Session(session) { @@ -159,7 +159,7 @@ void HTTPConnection::HandleRequest() void HTTPConnection::HandleI2PControlRequest() { std::stringstream ss(m_Request.getContent()); - const client::I2PControlSession::Response rsp = m_Session->handleRequest(ss); + const client::i2pcontrol::I2PControlSession::Response rsp = m_Session->handleRequest(ss); m_Reply = i2p::util::http::Response(200, rsp.toJsonString()); m_Reply.setHeader("Content-Type", "application/json"); SendReply(); @@ -197,7 +197,7 @@ HTTPServer::HTTPServer(const std::string& address, int port): boost::asio::ip::address::from_string(address), port) ), m_NewSocket(nullptr), - m_Session(std::make_shared(m_Service)) + m_Session(std::make_shared(m_Service)) { } diff --git a/client/HTTPServer.h b/client/HTTPServer.h index 412f05fd..f8cd81d9 100644 --- a/client/HTTPServer.h +++ b/client/HTTPServer.h @@ -19,7 +19,7 @@ class HTTPConnection: public std::enable_shared_from_this { public: HTTPConnection(boost::asio::ip::tcp::socket* socket, - std::shared_ptr session); + std::shared_ptr session); ~HTTPConnection() { delete m_Socket; } void Receive(); @@ -44,7 +44,7 @@ private: size_t m_BufferLen; util::http::Request m_Request; util::http::Response m_Reply; - std::shared_ptr m_Session; + std::shared_ptr m_Session; }; class HTTPServer { @@ -69,7 +69,7 @@ private: boost::asio::io_service::work m_Work; boost::asio::ip::tcp::acceptor m_Acceptor; boost::asio::ip::tcp::socket * m_NewSocket; - std::shared_ptr m_Session; + std::shared_ptr m_Session; protected: void CreateConnection(boost::asio::ip::tcp::socket* m_NewSocket); diff --git a/client/i2pcontrol/I2PControl.cpp b/client/i2pcontrol/I2PControl.cpp index d6b7a066..2c09e2a0 100644 --- a/client/i2pcontrol/I2PControl.cpp +++ b/client/i2pcontrol/I2PControl.cpp @@ -11,6 +11,7 @@ #include #include +#include "util/util.h" #include "util/Log.h" #include "util/Timestamp.h" #include "transport/Transports.h" @@ -21,6 +22,7 @@ namespace i2p { namespace client { +namespace i2pcontrol { I2PControlSession::Response::Response(const std::string& version) : id(), version(version), error(ErrorCode::None), parameters() @@ -104,28 +106,33 @@ I2PControlSession::I2PControlSession(boost::asio::io_service& ios, const std::st : password(pass), tokens(), tokensMutex(), service(ios), shutdownTimer(ios), expireTokensTimer(ios) { + using namespace i2p::client::i2pcontrol::constants; // Method handlers - methodHandlers[I2P_CONTROL_METHOD_AUTHENTICATE] = &I2PControlSession::handleAuthenticate; - methodHandlers[I2P_CONTROL_METHOD_ECHO] = &I2PControlSession::handleEcho; - methodHandlers[I2P_CONTROL_METHOD_I2PCONTROL] = &I2PControlSession::handleI2PControl; - methodHandlers[I2P_CONTROL_METHOD_ROUTER_INFO] = &I2PControlSession::handleRouterInfo; - methodHandlers[I2P_CONTROL_METHOD_ROUTER_MANAGER] = &I2PControlSession::handleRouterManager; - methodHandlers[I2P_CONTROL_METHOD_NETWORK_SETTING] = &I2PControlSession::handleNetworkSetting; + methodHandlers[METHOD_AUTHENTICATE] = &I2PControlSession::handleAuthenticate; + methodHandlers[METHOD_ECHO] = &I2PControlSession::handleEcho; + methodHandlers[METHOD_I2PCONTROL] = &I2PControlSession::handleI2PControl; + methodHandlers[METHOD_ROUTER_INFO] = &I2PControlSession::handleRouterInfo; + methodHandlers[METHOD_ROUTER_MANAGER] = &I2PControlSession::handleRouterManager; + methodHandlers[METHOD_NETWORK_SETTING] = &I2PControlSession::handleNetworkSetting; // RouterInfo handlers - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_UPTIME] = &I2PControlSession::handleUptime; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_VERSION] = &I2PControlSession::handleVersion; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_STATUS] = &I2PControlSession::handleStatus; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS]= &I2PControlSession::handleNetDbKnownPeers; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS] = &I2PControlSession::handleNetDbActivePeers; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_NET_STATUS] = &I2PControlSession::handleNetStatus; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING] = &I2PControlSession::handleTunnelsParticipating; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_BW_IB_1S] = &I2PControlSession::handleInBandwidth1S; - routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_BW_OB_1S] = &I2PControlSession::handleOutBandwidth1S; + routerInfoHandlers[ROUTER_INFO_UPTIME] = &I2PControlSession::handleUptime; + routerInfoHandlers[ROUTER_INFO_VERSION] = &I2PControlSession::handleVersion; + routerInfoHandlers[ROUTER_INFO_STATUS] = &I2PControlSession::handleStatus; + routerInfoHandlers[ROUTER_INFO_DATAPATH] = &I2PControlSession::handleDatapath; + routerInfoHandlers[ROUTER_INFO_NETDB_KNOWNPEERS]= &I2PControlSession::handleNetDbKnownPeers; + routerInfoHandlers[ROUTER_INFO_NETDB_ACTIVEPEERS] = &I2PControlSession::handleNetDbActivePeers; + routerInfoHandlers[ROUTER_INFO_NETDB_LEASESETS] = &I2PControlSession::handleNetDbLeaseSets; + routerInfoHandlers[ROUTER_INFO_NETDB_FLOODFILLS] = &I2PControlSession::handleNetDbFloodfills; + routerInfoHandlers[ROUTER_INFO_NET_STATUS] = &I2PControlSession::handleNetStatus; + routerInfoHandlers[ROUTER_INFO_TUNNELS_PARTICIPATING] = &I2PControlSession::handleTunnelsParticipating; + routerInfoHandlers[ROUTER_INFO_TUNNELS_CREATION_SUCCESS] = &I2PControlSession::handleTunnelsCreationSuccess; + routerInfoHandlers[ROUTER_INFO_BW_IB_1S] = &I2PControlSession::handleInBandwidth1S; + routerInfoHandlers[ROUTER_INFO_BW_OB_1S] = &I2PControlSession::handleOutBandwidth1S; // RouterManager handlers - routerManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN] = &I2PControlSession::handleShutdown; - routerManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL] = &I2PControlSession::handleShutdownGraceful; - routerManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_RESEED] = &I2PControlSession::handleReseed; + routerManagerHandlers[ROUTER_MANAGER_SHUTDOWN] = &I2PControlSession::handleShutdown; + routerManagerHandlers[ROUTER_MANAGER_SHUTDOWN_GRACEFUL] = &I2PControlSession::handleShutdownGraceful; + routerManagerHandlers[ROUTER_MANAGER_RESEED] = &I2PControlSession::handleReseed; } void I2PControlSession::start() @@ -147,9 +154,9 @@ I2PControlSession::Response I2PControlSession::handleRequest(std::stringstream& Response response; try { - response.setId(pt.get(I2P_CONTROL_PROPERTY_ID)); + response.setId(pt.get(constants::PROPERTY_ID)); - std::string method = pt.get(I2P_CONTROL_PROPERTY_METHOD); + std::string method = pt.get(constants::PROPERTY_METHOD); auto it = methodHandlers.find(method); if(it == methodHandlers.end()) { // Not found LogPrint(eLogWarning, "Unknown I2PControl method ", method); @@ -157,8 +164,8 @@ I2PControlSession::Response I2PControlSession::handleRequest(std::stringstream& return response; } - PropertyTree params = pt.get_child(I2P_CONTROL_PROPERTY_PARAMS); - if(method != I2P_CONTROL_METHOD_AUTHENTICATE && !authenticate(params, response)) { + PropertyTree params = pt.get_child(constants::PROPERTY_PARAMS); + if(method != constants::METHOD_AUTHENTICATE && !authenticate(params, response)) { LogPrint(eLogWarning, "I2PControl invalid token presented"); return response; } @@ -177,14 +184,14 @@ I2PControlSession::Response I2PControlSession::handleRequest(std::stringstream& bool I2PControlSession::authenticate(const PropertyTree& pt, Response& response) { try { - std::string token = pt.get(I2P_CONTROL_PARAM_TOKEN); + std::string token = pt.get(constants::PARAM_TOKEN); std::lock_guard lock(tokensMutex); auto it = tokens.find(token); if(it == tokens.end()) { response.setError(ErrorCode::NonexistentToken); return false; - } else if(util::GetSecondsSinceEpoch() - it->second > I2P_CONTROL_TOKEN_LIFETIME) { + } else if(util::GetSecondsSinceEpoch() - it->second > constants::TOKEN_LIFETIME) { response.setError(ErrorCode::ExpiredToken); return false; } @@ -199,12 +206,12 @@ bool I2PControlSession::authenticate(const PropertyTree& pt, Response& response) std::string I2PControlSession::generateToken() const { - byte random_data[I2P_CONTROL_TOKEN_SIZE] = {}; + byte random_data[constants::TOKEN_SIZE] = {}; CryptoPP::AutoSeededRandomPool rng; - rng.GenerateBlock(random_data, I2P_CONTROL_TOKEN_SIZE); + rng.GenerateBlock(random_data, constants::TOKEN_SIZE); std::string token; CryptoPP::StringSource ss( - random_data, I2P_CONTROL_TOKEN_SIZE, true, + random_data, constants::TOKEN_SIZE, true, new CryptoPP::HexEncoder(new CryptoPP::StringSink(token)) ); return token; @@ -212,8 +219,8 @@ std::string I2PControlSession::generateToken() const void I2PControlSession::handleAuthenticate(const PropertyTree& pt, Response& response) { - const int api = pt.get(I2P_CONTROL_PARAM_API); - const std::string given_pass = pt.get(I2P_CONTROL_PARAM_PASSWORD); + const int api = pt.get(constants::PARAM_API); + const std::string given_pass = pt.get(constants::PARAM_PASSWORD); LogPrint(eLogDebug, "I2PControl Authenticate API = ", api, " Password = ", given_pass); if(given_pass != password) { LogPrint( @@ -224,8 +231,8 @@ void I2PControlSession::handleAuthenticate(const PropertyTree& pt, Response& res return; } const std::string token = generateToken(); - response.setParam(I2P_CONTROL_PARAM_API, api); - response.setParam(I2P_CONTROL_PARAM_TOKEN, token); + response.setParam(constants::PARAM_API, api); + response.setParam(constants::PARAM_TOKEN, token); std::lock_guard lock(tokensMutex); tokens.insert(std::make_pair(token, util::GetSecondsSinceEpoch())); @@ -233,9 +240,9 @@ void I2PControlSession::handleAuthenticate(const PropertyTree& pt, Response& res void I2PControlSession::handleEcho(const PropertyTree& pt, Response& response) { - const std::string echo = pt.get(I2P_CONTROL_PARAM_ECHO); + const std::string echo = pt.get(constants::PARAM_ECHO); LogPrint(eLogDebug, "I2PControl Echo Echo = ", echo); - response.setParam(I2P_CONTROL_PARAM_RESULT, echo); + response.setParam(constants::PARAM_RESULT, echo); } void I2PControlSession::handleI2PControl(const PropertyTree&, Response&) @@ -249,7 +256,7 @@ void I2PControlSession::handleRouterInfo(const PropertyTree& pt, Response& respo { LogPrint(eLogDebug, "I2PControl RouterInfo"); for(const auto& pair : pt) { - if(pair.first == I2P_CONTROL_PARAM_TOKEN) + if(pair.first == constants::PARAM_TOKEN) continue; LogPrint(eLogDebug, pair.first); auto it = routerInfoHandlers.find(pair.first); @@ -266,7 +273,7 @@ void I2PControlSession::handleRouterManager(const PropertyTree& pt, Response& re { LogPrint(eLogDebug, "I2PControl RouterManager"); for(const auto& pair : pt) { - if(pair.first == I2P_CONTROL_PARAM_TOKEN) + if(pair.first == constants::PARAM_TOKEN) continue; LogPrint(eLogDebug, pair.first); auto it = routerManagerHandlers.find(pair.first); @@ -286,53 +293,85 @@ void I2PControlSession::handleNetworkSetting(const PropertyTree&, Response&) void I2PControlSession::handleUptime(Response& response) { - response.setParam(I2P_CONTROL_ROUTER_INFO_UPTIME, (int)i2p::context.GetUptime()*1000); + response.setParam(constants::ROUTER_INFO_UPTIME, (int)i2p::context.GetUptime()*1000); } void I2PControlSession::handleVersion(Response& response) { - response.setParam(I2P_CONTROL_ROUTER_INFO_VERSION, VERSION); + response.setParam(constants::ROUTER_INFO_VERSION, VERSION); } void I2PControlSession::handleStatus(Response& response) { - response.setParam(I2P_CONTROL_ROUTER_INFO_STATUS, "???"); // TODO: + response.setParam(constants::ROUTER_INFO_STATUS, "???"); // TODO: +} + +void I2PControlSession::handleDatapath(Response& response) +{ + response.setParam( + constants::ROUTER_INFO_DATAPATH, + i2p::util::filesystem::GetDefaultDataDir().string() + ); } void I2PControlSession::handleNetDbKnownPeers(Response& response) { response.setParam( - I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS, i2p::data::netdb.GetNumRouters() + constants::ROUTER_INFO_NETDB_KNOWNPEERS, i2p::data::netdb.GetNumRouters() ); } void I2PControlSession::handleNetDbActivePeers(Response& response) { response.setParam( - I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS, + constants::ROUTER_INFO_NETDB_ACTIVEPEERS, (int)i2p::transport::transports.GetPeers().size() ); } +void I2PControlSession::handleNetDbFloodfills(Response& response) +{ + response.setParam( + constants::ROUTER_INFO_NETDB_FLOODFILLS, + (int)i2p::data::netdb.GetNumFloodfills() + ); +} + +void I2PControlSession::handleNetDbLeaseSets(Response& response) +{ + response.setParam( + constants::ROUTER_INFO_NETDB_LEASESETS, + (int)i2p::data::netdb.GetNumLeaseSets() + ); +} + void I2PControlSession::handleNetStatus(Response& response) { response.setParam( - I2P_CONTROL_ROUTER_INFO_NET_STATUS, (int)i2p::context.GetStatus() + constants::ROUTER_INFO_NET_STATUS, (int)i2p::context.GetStatus() ); } void I2PControlSession::handleTunnelsParticipating(Response& response) { response.setParam( - I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING, + constants::ROUTER_INFO_TUNNELS_PARTICIPATING, (int)i2p::tunnel::tunnels.GetTransitTunnels().size() ); } +void I2PControlSession::handleTunnelsCreationSuccess(Response& response) +{ + response.setParam( + constants::ROUTER_INFO_TUNNELS_CREATION_SUCCESS, + i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() + ); +} + void I2PControlSession::handleInBandwidth1S(Response& response) { response.setParam( - I2P_CONTROL_ROUTER_INFO_BW_IB_1S, + constants::ROUTER_INFO_BW_IB_1S, (double)i2p::transport::transports.GetInBandwidth() ); } @@ -340,7 +379,7 @@ void I2PControlSession::handleInBandwidth1S(Response& response) void I2PControlSession::handleOutBandwidth1S(Response& response) { response.setParam( - I2P_CONTROL_ROUTER_INFO_BW_OB_1S, + constants::ROUTER_INFO_BW_OB_1S, (double)i2p::transport::transports.GetOutBandwidth() ); } @@ -348,7 +387,7 @@ void I2PControlSession::handleOutBandwidth1S(Response& response) void I2PControlSession::handleShutdown(Response& response) { LogPrint(eLogInfo, "Shutdown requested"); - response.setParam(I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN, ""); + response.setParam(constants::ROUTER_MANAGER_SHUTDOWN, ""); // 1 second to make sure response has been sent shutdownTimer.expires_from_now(boost::posix_time::seconds(1)); shutdownTimer.async_wait([](const boost::system::error_code&) { @@ -361,7 +400,7 @@ void I2PControlSession::handleShutdownGraceful(Response& response) i2p::context.SetAcceptsTunnels(false); int timeout = i2p::tunnel::tunnels.GetTransitTunnelsExpirationTimeout(); LogPrint(eLogInfo, "Graceful shutdown requested. Will shutdown after ", timeout, " seconds"); - response.setParam(I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL, ""); + response.setParam(constants::ROUTER_MANAGER_SHUTDOWN_GRACEFUL, ""); shutdownTimer.expires_from_now(boost::posix_time::seconds(timeout + 1)); shutdownTimer.async_wait([](const boost::system::error_code&) { Daemon.running = 0; @@ -371,7 +410,7 @@ void I2PControlSession::handleShutdownGraceful(Response& response) void I2PControlSession::handleReseed(Response& response) { LogPrint(eLogInfo, "Reseed requested"); - response.setParam(I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN, ""); + response.setParam(constants::ROUTER_MANAGER_SHUTDOWN, ""); i2p::data::netdb.Reseed(); } @@ -385,7 +424,7 @@ void I2PControlSession::expireTokens(const boost::system::error_code& error) const uint64_t now = util::GetSecondsSinceEpoch(); std::lock_guard lock(tokensMutex); for(auto it = tokens.begin(); it != tokens.end(); ) { - if(now - it->second > I2P_CONTROL_TOKEN_LIFETIME) + if(now - it->second > constants::TOKEN_LIFETIME) it = tokens.erase(it); else ++it; @@ -394,7 +433,7 @@ void I2PControlSession::expireTokens(const boost::system::error_code& error) void I2PControlSession::startExpireTokensJob() { - expireTokensTimer.expires_from_now(boost::posix_time::seconds(I2P_CONTROL_TOKEN_LIFETIME)); + expireTokensTimer.expires_from_now(boost::posix_time::seconds(constants::TOKEN_LIFETIME)); expireTokensTimer.async_wait(std::bind( &I2PControlSession::expireTokens, shared_from_this(), std::placeholders::_1 )); @@ -402,3 +441,4 @@ void I2PControlSession::startExpireTokensJob() } } +} diff --git a/client/i2pcontrol/I2PControl.h b/client/i2pcontrol/I2PControl.h index eb9b3eab..3bcc947e 100644 --- a/client/i2pcontrol/I2PControl.h +++ b/client/i2pcontrol/I2PControl.h @@ -10,51 +10,60 @@ namespace i2p { namespace client { +namespace i2pcontrol { -const char I2P_CONTROL_DEFAULT_PASSWORD[] = "itoopie"; -const uint64_t I2P_CONTROL_TOKEN_LIFETIME = 600; // Token lifetime in seconds -const std::size_t I2P_CONTROL_TOKEN_SIZE = 8; // Token size in bytes +namespace constants { -const char I2P_CONTROL_PROPERTY_ID[] = "id"; -const char I2P_CONTROL_PROPERTY_METHOD[] = "method"; -const char I2P_CONTROL_PROPERTY_PARAMS[] = "params"; -const char I2P_CONTROL_PROPERTY_RESULT[] = "result"; +const char DEFAULT_PASSWORD[] = "itoopie"; +const uint64_t TOKEN_LIFETIME = 600; // Token lifetime in seconds +const std::size_t TOKEN_SIZE = 8; // Token size in bytes + +const char PROPERTY_ID[] = "id"; +const char PROPERTY_METHOD[] = "method"; +const char PROPERTY_PARAMS[] = "params"; +const char PROPERTY_RESULT[] = "result"; // methods -const char I2P_CONTROL_METHOD_AUTHENTICATE[] = "Authenticate"; -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_MANAGER[] = "RouterManager"; -const char I2P_CONTROL_METHOD_NETWORK_SETTING[] = "NetworkSetting"; +const char METHOD_AUTHENTICATE[] = "Authenticate"; +const char METHOD_ECHO[] = "Echo"; +const char METHOD_I2PCONTROL[] = "I2PControl"; +const char METHOD_ROUTER_INFO[] = "RouterInfo"; +const char METHOD_ROUTER_MANAGER[] = "RouterManager"; +const char METHOD_NETWORK_SETTING[] = "NetworkSetting"; // params -const char I2P_CONTROL_PARAM_API[] = "API"; -const char I2P_CONTROL_PARAM_PASSWORD[] = "Password"; -const char I2P_CONTROL_PARAM_TOKEN[] = "Token"; -const char I2P_CONTROL_PARAM_ECHO[] = "Echo"; -const char I2P_CONTROL_PARAM_RESULT[] = "Result"; +const char PARAM_API[] = "API"; +const char PARAM_PASSWORD[] = "Password"; +const char PARAM_TOKEN[] = "Token"; +const char PARAM_ECHO[] = "Echo"; +const char 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"; +const char I2PCONTROL_ADDRESS[] = "i2pcontrol.address"; +const char I2PCONTROL_PASSWORD[] = "i2pcontrol.password"; +const char I2PCONTROL_PORT[] = "i2pcontrol.port"; // RouterInfo requests -const char I2P_CONTROL_ROUTER_INFO_UPTIME[] = "i2p.router.uptime"; -const char I2P_CONTROL_ROUTER_INFO_VERSION[] = "i2p.router.version"; -const char I2P_CONTROL_ROUTER_INFO_STATUS[] = "i2p.router.status"; -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_NET_STATUS[] = "i2p.router.net.status"; -const char I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING[] = "i2p.router.net.tunnels.participating"; -const char I2P_CONTROL_ROUTER_INFO_BW_IB_1S[] = "i2p.router.net.bw.inbound.1s"; -const char I2P_CONTROL_ROUTER_INFO_BW_OB_1S[] = "i2p.router.net.bw.outbound.1s"; +const char ROUTER_INFO_UPTIME[] = "i2p.router.uptime"; +const char ROUTER_INFO_VERSION[] = "i2p.router.version"; +const char ROUTER_INFO_STATUS[] = "i2p.router.status"; +const char ROUTER_INFO_DATAPATH[] = "i2p.router.datapath"; +const char ROUTER_INFO_NETDB_KNOWNPEERS[] = "i2p.router.netdb.knownpeers"; +const char ROUTER_INFO_NETDB_ACTIVEPEERS[] = "i2p.router.netdb.activepeers"; +const char ROUTER_INFO_NETDB_FLOODFILLS[] = "i2p.router.netdb.floodfills"; +const char ROUTER_INFO_NETDB_LEASESETS[] = "i2p.router.netdb.leasesets"; +const char ROUTER_INFO_NET_STATUS[] = "i2p.router.net.status"; +const char ROUTER_INFO_TUNNELS_PARTICIPATING[] = "i2p.router.net.tunnels.participating"; +const char ROUTER_INFO_TUNNELS_CREATION_SUCCESS[] = "i2p.router.net.tunnels.creationsuccessrate"; +const char ROUTER_INFO_BW_IB_1S[] = "i2p.router.net.bw.inbound.1s"; +const char ROUTER_INFO_BW_OB_1S[] = "i2p.router.net.bw.outbound.1s"; // RouterManager requests -const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN[] = "Shutdown"; -const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL[] = "ShutdownGraceful"; -const char I2P_CONTROL_ROUTER_MANAGER_RESEED[] = "Reseed"; +const char ROUTER_MANAGER_SHUTDOWN[] = "Shutdown"; +const char ROUTER_MANAGER_SHUTDOWN_GRACEFUL[] = "ShutdownGraceful"; +const char ROUTER_MANAGER_RESEED[] = "Reseed"; + +} // constants /** * "Null" I2P control implementation, does not do actual networking. @@ -113,7 +122,7 @@ public: * the lifetime of this I2PControlSession. */ I2PControlSession(boost::asio::io_service& ios, - const std::string& pass = I2P_CONTROL_DEFAULT_PASSWORD); + const std::string& pass = constants::DEFAULT_PASSWORD); /** * Starts the I2PControlSession. @@ -172,10 +181,14 @@ private: void handleUptime(Response& response); void handleVersion(Response& response); void handleStatus(Response& response); + void handleDatapath(Response& response); void handleNetDbKnownPeers(Response& response); void handleNetDbActivePeers(Response& response); + void handleNetDbFloodfills(Response& response); + void handleNetDbLeaseSets(Response& response); void handleNetStatus(Response& response); void handleTunnelsParticipating(Response& response); + void handleTunnelsCreationSuccess(Response& response); void handleInBandwidth1S(Response& response); void handleOutBandwidth1S(Response& response); @@ -198,6 +211,7 @@ private: boost::asio::deadline_timer expireTokensTimer; }; +} } } diff --git a/client/i2pcontrol/I2PControlServer.cpp b/client/i2pcontrol/I2PControlServer.cpp index 88017e25..92277747 100644 --- a/client/i2pcontrol/I2PControlServer.cpp +++ b/client/i2pcontrol/I2PControlServer.cpp @@ -8,6 +8,7 @@ namespace i2p { namespace client { +namespace i2pcontrol { I2PControlService::I2PControlService(const std::string& address, int port, const std::string& pass) : m_Session(std::make_shared(m_Service, pass)), @@ -168,3 +169,4 @@ void I2PControlService::HandleResponseSent(const boost::system::error_code& ecod } } +} diff --git a/client/i2pcontrol/I2PControlServer.h b/client/i2pcontrol/I2PControlServer.h index e60ee862..ad09af30 100644 --- a/client/i2pcontrol/I2PControlServer.h +++ b/client/i2pcontrol/I2PControlServer.h @@ -12,6 +12,7 @@ namespace i2p { namespace client { +namespace i2pcontrol { const size_t I2P_CONTROL_MAX_REQUEST_SIZE = 1024; typedef std::array I2PControlBuffer; @@ -51,6 +52,7 @@ private: }; } } +} #endif diff --git a/webui/footer.html b/webui/footer.html new file mode 100644 index 00000000..0f372832 --- /dev/null +++ b/webui/footer.html @@ -0,0 +1,6 @@ +
+ +
+ diff --git a/webui/help.html b/webui/help.html index 6949ae1b..d626ec16 100644 --- a/webui/help.html +++ b/webui/help.html @@ -22,11 +22,7 @@ + -
- -
- + diff --git a/webui/index.html b/webui/index.html index 8517ce0f..01fd8231 100644 --- a/webui/index.html +++ b/webui/index.html @@ -19,6 +19,7 @@ function updateRouterInfo(result, session) { "knownpeers" : result["i2p.router.netdb.knownpeers"], "activepeers" : result["i2p.router.netdb.activepeers"], "tunnels-participating" : result["i2p.router.net.tunnels.participating"], + "tunnels-successrate" : result["i2p.router.net.tunnels.creationsuccessrate"] + "%", "bw-in" : result["i2p.router.net.bw.inbound.1s"], "bw-out" : result["i2p.router.net.bw.outbound.1s"] }); @@ -34,6 +35,7 @@ function requestRouterInfo(session) { "i2p.router.netdb.knownpeers" : "", "i2p.router.netdb.activepeers" : "", "i2p.router.net.tunnels.participating" : "", + "i2p.router.net.tunnels.creationsuccessrate" : "", "i2p.router.net.bw.inbound.1s" : "", "i2p.router.net.bw.outbound.1s" : "" }, updateRouterInfo); @@ -60,21 +62,27 @@ window.onload = function() {
-

Tunnels participating:

-

Active peers:

-

Known peers:

-

Bandwidth: +

+ Tunnels participating: +

+

+ Tunnel create success rate: +

+

+ Active peers: +

+

+ Known peers: +

+

+ Bandwidth: in Bps / out Bps

+ -
- -
diff --git a/webui/menu.html b/webui/menu.html index b5c7d83b..47c7e8b0 100644 --- a/webui/menu.html +++ b/webui/menu.html @@ -4,6 +4,9 @@ + diff --git a/webui/netdb.html b/webui/netdb.html new file mode 100644 index 00000000..2ac2147a --- /dev/null +++ b/webui/netdb.html @@ -0,0 +1,59 @@ + + + +Purple I2P 0.10.0 Webconsole + + + + + + + + +
+

i2pd router console

+

Network Database Information

+
+ +
+

Active peers:

+

Known peers:

+

Floodfills:

+
+

LeaseSets:

+
+ + + + + +