From 2b29f0a76021eefced0edb7df35060203f13e228 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 25 May 2012 16:05:14 +0200 Subject: [PATCH] add startingheight to output --- bitcoin.cpp | 7 ++++++- bitcoin.h | 2 +- db.cpp | 3 ++- db.h | 17 +++++++++++------ main.cpp | 9 +++++---- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/bitcoin.cpp b/bitcoin.cpp index 50b002d..ac5a79e 100644 --- a/bitcoin.cpp +++ b/bitcoin.cpp @@ -258,9 +258,13 @@ public: std::string GetClientSubVersion() { return strSubVer; } + + int GetStartingHeight() { + return nStartingHeight; + } }; -bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV, vector& vAddr) { +bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV, int &blocks, vector& vAddr) { try { CNode node(cip, vAddr); bool ret = node.Run(); @@ -271,6 +275,7 @@ bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV } clientV = node.GetClientVersion(); clientSV = node.GetClientSubVersion(); + blocks = node.GetStartingHeight(); // printf("%s: %s!!!\n", cip.ToString().c_str(), ret ? "GOOD" : "BAD"); return ret; } catch(std::ios_base::failure& e) { diff --git a/bitcoin.h b/bitcoin.h index 6db8543..609caa3 100644 --- a/bitcoin.h +++ b/bitcoin.h @@ -3,6 +3,6 @@ #include "protocol.h" -bool TestNode(const CService &cip, int &ban, int &client, std::string &clientSV, std::vector& vAddr); +bool TestNode(const CService &cip, int &ban, int &client, std::string &clientSV, int &blocks, std::vector& vAddr); #endif diff --git a/db.cpp b/db.cpp index 66023fb..98b467d 100644 --- a/db.cpp +++ b/db.cpp @@ -84,7 +84,7 @@ int CAddrDb::Lookup_(const CService &ip) { return -1; } -void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV) { +void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, int blocks) { int id = Lookup_(addr); if (id == -1) return; unkId.erase(id); @@ -92,6 +92,7 @@ void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV) { CAddrInfo &info = idToInfo[id]; info.clientVersion = clientV; info.clientSubVersion = clientSV; + info.blocks = blocks; info.Update(true); if (info.IsGood() && goodId.count(id)==0) { goodId.insert(id); diff --git a/db.h b/db.h index 0e948d1..d5b5f6d 100644 --- a/db.h +++ b/db.h @@ -46,6 +46,7 @@ class CAddrReport { public: CService ip; int clientVersion; + int blocks; double uptime[5]; std::string clientSubVersion; }; @@ -64,17 +65,19 @@ private: CAddrStat stat1W; CAddrStat stat1M; int clientVersion; + int blocks; int total; int success; std::string clientSubVersion; public: - CAddrInfo() : services(0), lastTry(0), ourLastTry(0), ignoreTill(0), clientVersion(0), total(0), success(0) {} + CAddrInfo() : services(0), lastTry(0), ourLastTry(0), ignoreTill(0), clientVersion(0), blocks(0), total(0), success(0) {} CAddrReport GetReport() const { CAddrReport ret; ret.ip = ip; ret.clientVersion = clientVersion; ret.clientSubVersion = clientSubVersion; + ret.blocks = blocks; ret.uptime[0] = stat2H.reliability; ret.uptime[1] = stat8H.reliability; ret.uptime[2] = stat1D.reliability; @@ -118,7 +121,7 @@ public: friend class CAddrDb; IMPLEMENT_SERIALIZE ( - unsigned char version = 2; + unsigned char version = 3; READWRITE(version); READWRITE(ip); READWRITE(services); @@ -142,6 +145,8 @@ public: READWRITE(clientVersion); if (version >= 2) READWRITE(clientSubVersion); + if (version >= 3) + READWRITE(blocks); } ) }; @@ -179,11 +184,11 @@ protected: // internal routines that assume proper locks are acquired void Add_(const CAddress &addr, bool force); // add an address bool Get_(CService &ip, int& wait); // get an IP to test (must call Good_, Bad_, or Skipped_ on result afterwards) - void Good_(const CService &ip, int clientV, std::string clientSV); // mark an IP as good (must have been returned by Get_) + void Good_(const CService &ip, int clientV, std::string clientSV, int blocks); // mark an IP as good (must have been returned by Get_) void Bad_(const CService &ip, int ban); // mark an IP as bad (and optionally ban it) (must have been returned by Get_) void Skipped_(const CService &ip); // mark an IP as skipped (must have been returned by Get_) int Lookup_(const CService &ip); // look up id of an IP - void GetIPs_(std::set& ips, int max, const bool* nets); // get a random set of IPs (shared lock only) + void GetIPs_(std::set& ips, int max, const bool *nets); // get a random set of IPs (shared lock only) public: std::map banned; // nodes that are banned, with their unban time (a) @@ -271,9 +276,9 @@ public: for (int i=0; i addr; int clientV = 0; + int blocks = 0; std::string clientSV; - bool ret = TestNode(ip,ban,clientV,clientSV,addr); + bool ret = TestNode(ip,ban,clientV,clientSV,blocks,addr); db.Add(addr); if (ret) { - db.Good(ip, clientV, clientSV); + db.Good(ip, clientV, clientSV, blocks); } else { db.Bad(ip, ban); } @@ -256,11 +257,11 @@ extern "C" void* ThreadDumper(void*) { FILE *d = fopen("dnsseed.dump", "w"); vector v = db.GetAll(); sort(v.begin(), v.end(), StatCompare); - fprintf(d, "# address \t%%(2h)\t%%(8h)\t%%(1d)\t%%(7d)\t%%(30d)\tversion\n"); + fprintf(d, "# address \t%%(2h)\t%%(8h)\t%%(1d)\t%%(7d)\t%%(30d)\tblocks\tversion\n"); double stat[5]={0,0,0,0,0}; for (vector::const_iterator it = v.begin(); it < v.end(); it++) { CAddrReport rep = *it; - fprintf(d, "%s\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%i \"%s\"\n", rep.ip.ToString().c_str(), 100.0*rep.uptime[0], 100.0*rep.uptime[1], 100.0*rep.uptime[2], 100.0*rep.uptime[3], 100.0*rep.uptime[4], rep.clientVersion, rep.clientSubVersion.c_str()); + fprintf(d, "%s\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%i\t%i \"%s\"\n", rep.ip.ToString().c_str(), 100.0*rep.uptime[0], 100.0*rep.uptime[1], 100.0*rep.uptime[2], 100.0*rep.uptime[3], 100.0*rep.uptime[4], rep.blocks, rep.clientVersion, rep.clientSubVersion.c_str()); stat[0] += rep.uptime[0]; stat[1] += rep.uptime[1]; stat[2] += rep.uptime[2];