From: Balthazar Date: Thu, 22 Jan 2015 09:59:10 +0000 (-0500) Subject: RPC: getaddrmaninfo should return online addresses only X-Git-Tag: nvc-v0.5.2~4 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=9403596b53aaf9c7a0fd19bfab5463c49abad805 RPC: getaddrmaninfo should return online addresses only TODO: Implement statistics collector and return a set of the most reliable nodes. --- diff --git a/src/addrman.cpp b/src/addrman.cpp index 359bfa8..cd80d3b 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -507,6 +507,17 @@ void CAddrMan::GetAddr_(std::vector &vAddr) } } +void CAddrMan::GetOnlineAddr_(std::vector &vAddr) +{ + for (std::map::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) + { + CAddrInfo addr = it->second; + bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60); + if (fCurrentlyOnline) + vAddr.push_back(addr); + } +} + void CAddrMan::Connected_(const CService &addr, int64_t nTime) { CAddrInfo *pinfo = Find(addr); diff --git a/src/addrman.h b/src/addrman.h index beb543a..ed35059 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -239,6 +239,7 @@ protected: // Select several addresses at once. void GetAddr_(std::vector &vAddr); + void GetOnlineAddr_(std::vector &vAddr); // Mark an entry as currently-connected-to. void Connected_(const CService &addr, int64_t nTime); @@ -665,6 +666,18 @@ public: return vAddr; } + std::vector GetOnlineAddr() + { + Check(); + std::vector vAddr; + { + LOCK(cs); + GetOnlineAddr_(vAddr); + } + Check(); + return vAddr; + } + // Mark an entry as currently-connected-to. void Connected(const CService &addr, int64_t nTime = GetAdjustedTime()) { diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 5404c01..5025d70 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -43,15 +43,13 @@ Value getaddrmaninfo(const Array& params, bool fHelp) "getaddrmaninfo\n" "Returns a dump of addrman data."); - vector vAddr = addrman.GetAddr(); + // Return a full list of "online" address items + vector vAddr = addrman.GetOnlineAddr(); Array ret; BOOST_FOREACH(const CAddress &addr, vAddr) { - // Don't return addresses older than nCutOff timestamp - int64_t nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60); - - if (!addr.IsRoutable() || addr.IsLocal() || addr.nTime > nCutOff) + if (!addr.IsRoutable() || addr.IsLocal()) continue; Object addrManItem;