From f8a529c744ab1819f0a7538645ded839b36e237d Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 31 Dec 2011 00:39:53 +0100 Subject: [PATCH] dump db to text file --- db.h | 33 ++++++++++++++++++++++++++++++--- main.cpp | 7 +++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/db.h b/db.h index bf08524..c379f9e 100644 --- a/db.h +++ b/db.h @@ -42,6 +42,13 @@ public: friend class CAddrInfo; }; +class CAddrReport { +public: + CIPPort ip; + int clientVersion; +}; + + class CAddrInfo { private: CIPPort ip; @@ -59,7 +66,14 @@ private: public: CAddrInfo() : services(0), lastTry(0), ourLastTry(0), ignoreTill(0), clientVersion(0), total(0), success(0) {} - bool IsGood() { + CAddrReport GetReport() const { + CAddrReport ret; + ret.ip = ip; + ret.clientVersion = clientVersion; + return ret; + } + + bool IsGood() const { if (ip.GetPort() != 8333) return false; if (!(services & NODE_NETWORK)) return false; if (!ip.IsRoutable()) return false; @@ -75,14 +89,14 @@ public: return false; } - int GetBanTime() { + int GetBanTime() const { if (IsGood()) return 0; if (clientVersion && clientVersion < 31900) { return 1000000; } if (stat1D.reliability < 0.01 && stat1D.count > 5) { return 500000; } if (stat1W.reliability - stat1W.weight + 1.0 < 0.10 && stat1W.count > 4) { return 240*3600; } return 0; } - int GetIgnoreTime() { + int GetIgnoreTime() const { if (IsGood()) return 0; if (stat2H.reliability - stat2H.weight + 1.0 < 0.2 && stat2H.count > 3) { return 3*3600; } if (stat8H.reliability - stat8H.weight + 1.0 < 0.2 && stat8H.count > 6) { return 12*3600; } @@ -169,6 +183,19 @@ public: } } + std::vector GetAll() { + std::vector ret; + SHARED_CRITICAL_BLOCK(cs) { + for (std::deque::const_iterator it = ourId.begin(); it != ourId.end(); it++) { + const CAddrInfo &info = idToInfo[*it]; + if (info.success > 0) { + ret.push_back(info.GetReport()); + } + } + } + return ret; + } + // serialization code // format: // nVersion (0 for now) diff --git a/main.cpp b/main.cpp index e8be098..406c653 100644 --- a/main.cpp +++ b/main.cpp @@ -114,6 +114,13 @@ int main(void) { if (f) { CAutoFile cf(f); cf >> db; + FILE *d = fopen("dnsseed.dump", "w"); + vector v = db.GetAll(); + for (vector::const_iterator it = v.begin(); it < v.end(); it++) { + CAddrReport rep = *it; + fprintf(d, "%s %i\n", rep.ip.ToString().c_str(), rep.clientVersion); + } + fclose(d); } pthread_t thread[NTHREADS+4]; for (int i=0; i