Remove O(n) selection logic
This commit is contained in:
parent
13b26a896d
commit
0270a013fb
2 changed files with 8 additions and 22 deletions
17
db.cpp
17
db.cpp
|
@ -29,25 +29,12 @@ void CAddrInfo::Update(bool good) {
|
|||
bool CAddrDb::Get_(CService &ip, int &wait) {
|
||||
int64 now = time(NULL);
|
||||
int cont = 0;
|
||||
int tot = unkId.size();
|
||||
do {
|
||||
deque<int>::iterator it = ourId.begin();
|
||||
while (it < ourId.end()) {
|
||||
if (now - idToInfo[*it].ourLastTry > MIN_RETRY) {
|
||||
tot++;
|
||||
it++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int tot = unkId.size() + ourId.size();
|
||||
if (tot == 0) {
|
||||
if (ourId.size() > 0) {
|
||||
wait = MIN_RETRY - (now - idToInfo[ourId.front()].ourLastTry);
|
||||
} else {
|
||||
wait = 5;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
int rnd = rand() % tot;
|
||||
int ret;
|
||||
if (rnd < unkId.size()) {
|
||||
|
|
7
main.cpp
7
main.cpp
|
@ -25,7 +25,7 @@ public:
|
|||
const char *host;
|
||||
const char *tor;
|
||||
|
||||
CDnsSeedOpts() : nThreads(50), nDnsThreads(4), nPort(53), mbox(NULL), ns(NULL), host(NULL), tor(NULL) {}
|
||||
CDnsSeedOpts() : nThreads(96), nDnsThreads(4), nPort(53), mbox(NULL), ns(NULL), host(NULL), tor(NULL) {}
|
||||
|
||||
void ParseCommandLine(int argc, char **argv) {
|
||||
static const char *help = "Bitcoin-seeder\n"
|
||||
|
@ -122,14 +122,13 @@ extern "C" void* ThreadCrawler(void* data) {
|
|||
do {
|
||||
std::vector<CServiceResult> ips;
|
||||
int wait = 5;
|
||||
db.GetMany(ips, 100, wait);
|
||||
db.GetMany(ips, 16, wait);
|
||||
if (ips.empty()) {
|
||||
wait *= 1000;
|
||||
wait += rand() % (500 * NTHREADS);
|
||||
Sleep(wait);
|
||||
continue;
|
||||
}
|
||||
printf("Got %i IPs to test!\n", (int)ips.size());
|
||||
vector<CAddress> addr;
|
||||
for (int i=0; i<ips.size(); i++) {
|
||||
CServiceResult &res = ips[i];
|
||||
|
@ -398,8 +397,8 @@ int main(int argc, char **argv) {
|
|||
pthread_create(&thread, NULL, ThreadCrawler, NULL);
|
||||
}
|
||||
printf("done\n");
|
||||
pthread_create(&threadDump, NULL, ThreadDumper, NULL);
|
||||
pthread_create(&threadStats, NULL, ThreadStats, NULL);
|
||||
pthread_create(&threadDump, NULL, ThreadDumper, NULL);
|
||||
void* res;
|
||||
pthread_join(threadDump, &res);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue