From 7ea12ddd6171fc89855586c04d0e83d843d0faa7 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 19 Mar 2015 21:51:18 -0400 Subject: [PATCH] RouterInfo version and status --- I2PControl.cpp | 26 +++++++++++++++++++------- I2PControl.h | 8 ++++++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/I2PControl.cpp b/I2PControl.cpp index 971c6b9f..a3bdd6a0 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -17,6 +17,7 @@ #include "Tunnel.h" #include "Timestamp.h" #include "Transports.h" +#include "version.h" namespace i2p { @@ -36,9 +37,11 @@ namespace client // RouterInfo m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_UPTIME] = &I2PControlService::UptimeHandler; + m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_VERSION] = &I2PControlService::VersionHandler; + m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_STATUS] = &I2PControlService::StatusHandler; m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS] = &I2PControlService::NetDbKnownPeersHandler; m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS] = &I2PControlService::NetDbActivePeersHandler; - m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_STATUS] = &I2PControlService::StatusHandler; + m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_NET_STATUS] = &I2PControlService::NetStatusHandler; m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING] = &I2PControlService::TunnelsParticipatingHandler; m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_BW_IB_1S] = &I2PControlService::InboundBandwidth1S ; m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_BW_OB_1S] = &I2PControlService::OutboundBandwidth1S ; @@ -110,6 +113,7 @@ namespace client if (!ecode) { LogPrint (eLogInfo, "New I2PControl request from ", socket->remote_endpoint ()); + std::this_thread::sleep_for (std::chrono::milliseconds(5)); ReadRequest (socket); } else @@ -168,17 +172,15 @@ namespace client std::map params; for (auto& v: pt.get_child (I2P_CONTROL_PROPERTY_PARAMS)) { - LogPrint (eLogInfo, v.first); if (!v.first.empty()) { if (v.first == I2P_CONTROL_PARAM_TOKEN) { - if (!m_Tokens.count (v.second.data ())) + if (!v.second.empty () && !m_Tokens.count (v.second.data ())) { LogPrint (eLogWarning, "Unknown token ", v.second.data ()); return; - } - + } } else params[v.first] = v.second.data (); @@ -314,6 +316,16 @@ namespace client results[I2P_CONTROL_ROUTER_INFO_UPTIME] = boost::lexical_cast(i2p::context.GetUptime ()*1000); } + void I2PControlService::VersionHandler (std::map& results) + { + results[I2P_CONTROL_ROUTER_INFO_VERSION] = VERSION; + } + + void I2PControlService::StatusHandler (std::map& results) + { + results[I2P_CONTROL_ROUTER_INFO_STATUS] = "???"; // TODO: + } + void I2PControlService::NetDbKnownPeersHandler (std::map& results) { results[I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS] = boost::lexical_cast(i2p::data::netdb.GetNumRouters ()); @@ -324,9 +336,9 @@ namespace client results[I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS] = boost::lexical_cast(i2p::transport::transports.GetPeers ().size ()); } - void I2PControlService::StatusHandler (std::map& results) + void I2PControlService::NetStatusHandler (std::map& results) { - results[I2P_CONTROL_ROUTER_INFO_STATUS] = boost::lexical_cast((int)i2p::context.GetStatus ()); + results[I2P_CONTROL_ROUTER_INFO_NET_STATUS] = boost::lexical_cast((int)i2p::context.GetStatus ()); } void I2PControlService::TunnelsParticipatingHandler (std::map& results) diff --git a/I2PControl.h b/I2PControl.h index 11ab3dc3..daffe53f 100644 --- a/I2PControl.h +++ b/I2PControl.h @@ -46,9 +46,11 @@ namespace client // 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_STATUS[] = "i2p.router.net.status"; + 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"; @@ -100,9 +102,11 @@ namespace client // RouterInfo typedef void (I2PControlService::*RouterInfoRequestHandler)(std::map& results); void UptimeHandler (std::map& results); + void VersionHandler (std::map& results); + void StatusHandler (std::map& results); void NetDbKnownPeersHandler (std::map& results); void NetDbActivePeersHandler (std::map& results); - void StatusHandler (std::map& results); + void NetStatusHandler (std::map& results); void TunnelsParticipatingHandler (std::map& results); void InboundBandwidth1S (std::map& results); void OutboundBandwidth1S (std::map& results);