diff --git a/db.h b/db.h index d8ab93c..003e7ec 100644 --- a/db.h +++ b/db.h @@ -162,6 +162,15 @@ public: int nAge; }; +struct CServiceResult { + CService service; + bool fGood; + int nBanTime; + int nHeight; + int nClientV; + std::string strClientV; +}; + // seen nodes // / \ // (a) banned nodes available nodes-------------- @@ -185,6 +194,7 @@ 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) + bool GetMany_(std::vector &ips, int max, int& wait); 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_) @@ -299,6 +309,28 @@ public: CRITICAL_BLOCK(cs) return Get_(ip, wait); } + void GetMany(std::vector &ips, int max, int& wait) { + CRITICAL_BLOCK(cs) { + while (max > 0) { + CServiceResult ip = {}; + if (!Get_(ip.service, wait)) + return; + ips.push_back(ip); + max--; + } + } + } + void ResultMany(const std::vector &ips) { + CRITICAL_BLOCK(cs) { + for (int i=0; i& ips, int max, const bool *nets) { SHARED_CRITICAL_BLOCK(cs) GetIPs_(ips, max, nets); diff --git a/main.cpp b/main.cpp index f13ae35..07713e6 100644 --- a/main.cpp +++ b/main.cpp @@ -120,26 +120,27 @@ CAddrDb db; extern "C" void* ThreadCrawler(void* data) { do { - CService ip; + std::vector ips; int wait = 5; - if (!db.Get(ip, wait)) { + db.GetMany(ips, 100, wait); + if (ips.empty()) { wait *= 1000; wait += rand() % (500 * NTHREADS); Sleep(wait); continue; } - int ban = 0; + printf("Got %i IPs to test!\n", (int)ips.size()); vector addr; - int clientV = 0; - int blocks = 0; - std::string clientSV; - bool ret = TestNode(ip,ban,clientV,clientSV,blocks,addr); - db.Add(addr); - if (ret) { - db.Good(ip, clientV, clientSV, blocks); - } else { - db.Bad(ip, ban); + for (int i=0; i