From 02d90b20973d85d345833d5b81f4e319ce4efea1 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sun, 13 Oct 2013 17:33:07 -0300 Subject: [PATCH] optimizations until we grow older and bigger: getaddr always and return all known ips per dns thread. + enable some debug printfs --- bitcoin.cpp | 6 +++--- db.cpp | 4 ++-- main.cpp | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bitcoin.cpp b/bitcoin.cpp index cf1c016..5100b08 100644 --- a/bitcoin.cpp +++ b/bitcoin.cpp @@ -133,19 +133,19 @@ class CNode { if (strCommand == "addr" && vAddr) { vector vAddrNew; vRecv >> vAddrNew; - // printf("%s: got %i addresses\n", ToString(you).c_str(), (int)vAddrNew.size()); + printf("%s: got %i addresses\n", ToString(you).c_str(), (int)vAddrNew.size()); int64 now = time(NULL); vector::iterator it = vAddrNew.begin(); if (doneAfter == 0 || doneAfter > now + 1) doneAfter = now + 1; while (it != vAddrNew.end()) { CAddress &addr = *it; -// printf("%s: got address %s\n", ToString(you).c_str(), addr.ToString().c_str(), (int)(vAddr->size())); + printf("%s: got address %s\n", ToString(you).c_str(), addr.ToString().c_str(), (int)(vAddr->size())); it++; if (addr.nTime <= 100000000 || addr.nTime > now + 600) addr.nTime = now - 5 * 86400; if (addr.nTime > now - 604800) vAddr->push_back(addr); -// printf("%s: added address %s (#%i)\n", ToString(you).c_str(), addr.ToString().c_str(), (int)(vAddr->size())); + printf("%s: added address %s (#%i)\n", ToString(you).c_str(), addr.ToString().c_str(), (int)(vAddr->size())); if (vAddr->size() > 1000) {doneAfter = 1; return true; } } return false; diff --git a/db.cpp b/db.cpp index f7020f2..b89904a 100644 --- a/db.cpp +++ b/db.cpp @@ -180,8 +180,8 @@ void CAddrDb::GetIPs_(set& ips, int max, const bool* nets) { } return; } - if (max > goodId.size() / 2) - max = goodId.size() / 2; + if (max > goodId.size() / 1) // [MF] /2 + max = goodId.size() / 1; // [MF] /2 if (max < 1) max = 1; int low = *goodId.begin(); diff --git a/main.cpp b/main.cpp index e50038b..e7f9a74 100644 --- a/main.cpp +++ b/main.cpp @@ -143,7 +143,8 @@ extern "C" void* ThreadCrawler(void* data) { res.nClientV = 0; res.nHeight = 0; res.strClientV = ""; - bool getaddr = res.ourLastSuccess + 604800 < now; + //bool getaddr = res.ourLastSuccess + 604800 < now; + bool getaddr = true; // [MF] always getaddr res.fGood = TestNode(res.service,res.nBanTime,res.nClientV,res.strClientV,res.nHeight,getaddr ? &addr : NULL); } db.ResultMany(ips); @@ -232,6 +233,7 @@ extern "C" int GetIPList(void *data, addr_t* addr, int max, int ipv4, int ipv6) thread->cacheHit(); unsigned int size = thread->cache.size(); unsigned int maxmax = (ipv4 ? thread->nIPv4 : 0) + (ipv6 ? thread->nIPv6 : 0); + if (max > size) max = size; if (max > maxmax) @@ -320,6 +322,7 @@ extern "C" void* ThreadStats(void*) { strftime(c, 256, "[%y-%m-%d %H:%M:%S]", tmp); CAddrDbStats stats; db.GetStats(stats); + /* if (first) { first = false; @@ -328,13 +331,14 @@ extern "C" void* ThreadStats(void*) { else printf("\x1b[2K\x1b[u"); printf("\x1b[s"); + */ uint64_t requests = 0; uint64_t queries = 0; for (unsigned int i=0; idns_opt.nRequests; queries += dnsThread[i]->dbQueries; } - printf("%s %i/%i available (%i tried in %is, %i new, %i active), %i banned; %llu DNS requests, %llu db queries", c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge, stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, stats.nBanned, (unsigned long long)requests, (unsigned long long)queries); + printf("%s %i/%i available (%i tried in %is, %i new, %i active), %i banned; %llu DNS requests, %llu db queries\n", c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge, stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, stats.nBanned, (unsigned long long)requests, (unsigned long long)queries); Sleep(1000); } while(1); }