From 8e95f6442a23bf672899d7553077c5a6ad937da8 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 19 Dec 2011 23:45:18 +0100 Subject: [PATCH] debug output --- db.cpp | 37 +++++++++++++++++++++++++++++++------ db.h | 13 +------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/db.cpp b/db.cpp index d390633..9765676 100644 --- a/db.cpp +++ b/db.cpp @@ -3,6 +3,20 @@ using namespace std; +void CAddrInfo::Update(bool good) { + uint32_t now = time(NULL); + double f = exp(-(now-ourLastTry)/TAU); + reliability = reliability * f + (good ? (1.0-f) : 0); + timing = (timing + (now-ourLastTry) * weight) * f; + count = count * f + 1; + weight = weight * f + (1.0-f); + lastTry = now; + ourLastTry = now; + total++; + if (good) success++; + printf("%s: got %s result: weight=%g reliability=%g avgage=%g count=%g success=%i/%i\n", ip.ToString().c_str(), good ? "good" : "bad", weight, reliability/weight, timing/weight, count/weight, success, total); +} + bool CAddrDb::Get_(CIPPort &ip) { int tot = unkId.size() + ourId.size(); if (tot == 0) return false; @@ -30,8 +44,10 @@ void CAddrDb::Good_(const CIPPort &addr) { banned.erase(addr); CAddrInfo &info = idToInfo[id]; info.Update(true); - if (info.IsGood()) - goodId.insert(id); + if (info.IsGood()) { + goodId.insert(id); + printf("%s: good; %i good nodes now\n", addr.ToString().c_str(), (int)goodId.size()); + } ourId.push_back(id); } @@ -42,16 +58,22 @@ void CAddrDb::Bad_(const CIPPort &addr, int ban) unkId.erase(id); CAddrInfo &info = idToInfo[id]; info.Update(false); - if (info.IsTerrible()) - if (ban < 604800) ban = 604800; - if (ban) { + uint32_t now = time(NULL); + if (info.IsTerrible()) { + printf("%s: terrible\n", addr.ToString().c_str()); + if (ban < 604800+now) ban = 604800+now; + } + if (ban > now) { + printf("%s: banned %lu seconds\n", addr.ToString().c_str(), (unsigned long)(ban-now)); banned[info.ip] = ban; ipToId.erase(info.ip); goodId.erase(id); idToInfo.erase(id); } else { - if (!info.IsGood()) + if (!info.IsGood()) { goodId.erase(id); + printf("%s: not good; %i good nodes left\n", addr.ToString().c_str(), (int)goodId.size()); + } ourId.push_back(id); } } @@ -62,6 +84,7 @@ void CAddrDb::Skipped_(const CIPPort &addr) if (id == -1) return; unkId.erase(id); ourId.push_back(id); + printf("%s: skipped\n", addr.ToString().c_str()); } @@ -81,6 +104,7 @@ void CAddrDb::Add_(const CAddress &addr) { if (addr.nTime > ai.lastTry) ai.lastTry = addr.nTime; ai.services |= addr.nServices; + printf("%s: updated\n", addr.ToString().c_str()); return; } CAddrInfo ai; @@ -96,6 +120,7 @@ void CAddrDb::Add_(const CAddress &addr) { idToInfo[id] = ai; ipToId[ipp] = id; unkId.insert(id); + printf("%s: added\n", addr.ToString().c_str()); } void CAddrDb::GetIPs_(set& ips, int max, bool fOnlyIPv4) { diff --git a/db.h b/db.h index 65c0894..ebfe88b 100644 --- a/db.h +++ b/db.h @@ -31,18 +31,7 @@ public: bool IsTerrible() { return (weight > 0.5 & reliability/weight < 0.2 && timing/weight < 86400 && count/weight > 2.0); } - void Update(bool good) { - uint32_t now = time(NULL); - double f = exp(-(now-ourLastTry)/TAU); - reliability = reliability * f + (good ? (1.0-f) : 0); - timing = (timing + (now-ourLastTry) * weight) * f; - count = count * f + 1; - weight = weight * f + (1.0-f); - lastTry = now; - ourLastTry = now; - total++; - if (good) success++; - } + void Update(bool good); friend class CAddrDb; };