RouterInfo version and status

This commit is contained in:
orignal 2015-03-19 21:51:18 -04:00
parent 4e1e47d9e5
commit 7ea12ddd61
2 changed files with 25 additions and 9 deletions

View File

@ -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<std::string, std::string> 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<std::string>(i2p::context.GetUptime ()*1000);
}
void I2PControlService::VersionHandler (std::map<std::string, std::string>& results)
{
results[I2P_CONTROL_ROUTER_INFO_VERSION] = VERSION;
}
void I2PControlService::StatusHandler (std::map<std::string, std::string>& results)
{
results[I2P_CONTROL_ROUTER_INFO_STATUS] = "???"; // TODO:
}
void I2PControlService::NetDbKnownPeersHandler (std::map<std::string, std::string>& results)
{
results[I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS] = boost::lexical_cast<std::string>(i2p::data::netdb.GetNumRouters ());
@ -324,9 +336,9 @@ namespace client
results[I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS] = boost::lexical_cast<std::string>(i2p::transport::transports.GetPeers ().size ());
}
void I2PControlService::StatusHandler (std::map<std::string, std::string>& results)
void I2PControlService::NetStatusHandler (std::map<std::string, std::string>& results)
{
results[I2P_CONTROL_ROUTER_INFO_STATUS] = boost::lexical_cast<std::string>((int)i2p::context.GetStatus ());
results[I2P_CONTROL_ROUTER_INFO_NET_STATUS] = boost::lexical_cast<std::string>((int)i2p::context.GetStatus ());
}
void I2PControlService::TunnelsParticipatingHandler (std::map<std::string, std::string>& results)

View File

@ -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<std::string, std::string>& results);
void UptimeHandler (std::map<std::string, std::string>& results);
void VersionHandler (std::map<std::string, std::string>& results);
void StatusHandler (std::map<std::string, std::string>& results);
void NetDbKnownPeersHandler (std::map<std::string, std::string>& results);
void NetDbActivePeersHandler (std::map<std::string, std::string>& results);
void StatusHandler (std::map<std::string, std::string>& results);
void NetStatusHandler (std::map<std::string, std::string>& results);
void TunnelsParticipatingHandler (std::map<std::string, std::string>& results);
void InboundBandwidth1S (std::map<std::string, std::string>& results);
void OutboundBandwidth1S (std::map<std::string, std::string>& results);