RPC: getaddrmaninfo should return online addresses only
authorBalthazar <balthazar@yandex.ru>
Thu, 22 Jan 2015 09:59:10 +0000 (04:59 -0500)
committerBalthazar <balthazar@yandex.ru>
Thu, 22 Jan 2015 09:59:10 +0000 (04:59 -0500)
TODO: Implement statistics collector and return a set of the most reliable nodes.

src/addrman.cpp
src/addrman.h
src/rpcnet.cpp

index 359bfa8..cd80d3b 100644 (file)
@@ -507,6 +507,17 @@ void CAddrMan::GetAddr_(std::vector<CAddress> &vAddr)
     }
 }
 
+void CAddrMan::GetOnlineAddr_(std::vector<CAddress> &vAddr)
+{
+    for (std::map<int, CAddrInfo>::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);
index beb543a..ed35059 100644 (file)
@@ -239,6 +239,7 @@ protected:
 
     // Select several addresses at once.
     void GetAddr_(std::vector<CAddress> &vAddr);
+    void GetOnlineAddr_(std::vector<CAddress> &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<CAddress> GetOnlineAddr()
+    {
+        Check();
+        std::vector<CAddress> vAddr;
+        {
+            LOCK(cs);
+            GetOnlineAddr_(vAddr);
+        }
+        Check();
+        return vAddr;
+    }
+
     // Mark an entry as currently-connected-to.
     void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
     {
index 5404c01..5025d70 100644 (file)
@@ -43,15 +43,13 @@ Value getaddrmaninfo(const Array& params, bool fHelp)
             "getaddrmaninfo\n"
             "Returns a dump of addrman data.");
 
-    vector<CAddress> vAddr = addrman.GetAddr();
+    // Return a full list of "online" address items
+    vector<CAddress> 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;