Browse Source

CServiceResult and batch scanning

pull/1/head
Pieter Wuille 11 years ago
parent
commit
13b26a896d
  1. 32
      db.h
  2. 27
      main.cpp

32
db.h

@ -162,6 +162,15 @@ public: @@ -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: @@ -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<CServiceResult> &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: @@ -299,6 +309,28 @@ public:
CRITICAL_BLOCK(cs)
return Get_(ip, wait);
}
void GetMany(std::vector<CServiceResult> &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<CServiceResult> &ips) {
CRITICAL_BLOCK(cs) {
for (int i=0; i<ips.size(); i++) {
if (ips[i].fGood) {
Good_(ips[i].service, ips[i].nClientV, ips[i].strClientV, ips[i].nHeight);
} else {
Bad_(ips[i].service, ips[i].nBanTime);
}
}
}
}
void GetIPs(std::set<CNetAddr>& ips, int max, const bool *nets) {
SHARED_CRITICAL_BLOCK(cs)
GetIPs_(ips, max, nets);

27
main.cpp

@ -120,26 +120,27 @@ CAddrDb db; @@ -120,26 +120,27 @@ CAddrDb db;
extern "C" void* ThreadCrawler(void* data) {
do {
CService ip;
std::vector<CServiceResult> 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<CAddress> 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<ips.size(); i++) {
CServiceResult &res = ips[i];
res.nBanTime = 0;
res.nClientV = 0;
res.nHeight = 0;
res.strClientV = "";
res.fGood = TestNode(res.service,res.nBanTime,res.nClientV,res.strClientV,res.nHeight,addr);
}
db.ResultMany(ips);
db.Add(addr);
} while(1);
}
@ -376,6 +377,7 @@ int main(int argc, char **argv) { @@ -376,6 +377,7 @@ int main(int argc, char **argv) {
db.ResetIgnores();
printf("done\n");
}
pthread_t threadDns, threadSeed, threadDump, threadStats;
if (fDNS) {
printf("Starting %i DNS threads for %s on %s (port %i)...", opts.nDnsThreads, opts.host, opts.ns, opts.nPort);
dnsThread.clear();
@ -387,7 +389,6 @@ int main(int argc, char **argv) { @@ -387,7 +389,6 @@ int main(int argc, char **argv) {
}
printf("done\n");
}
pthread_t threadDns, threadSeed, threadDump, threadStats;
printf("Starting seeder...");
pthread_create(&threadSeed, NULL, ThreadSeeder, NULL);
printf("done\n");

Loading…
Cancel
Save