Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
// Copyright (c) 2017-2020 The Bitcoin developers | // Copyright (c) 2017-2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <clientversion.h> | #include <clientversion.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <protocol.h> | #include <protocol.h> | ||||
#include <seeder/bitcoin.h> | #include <seeder/bitcoin.h> | ||||
#include <seeder/db.h> | #include <seeder/db.h> | ||||
#include <seeder/dns.h> | #include <seeder/dns.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/time.h> | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <atomic> | #include <atomic> | ||||
#include <cinttypes> | #include <cinttypes> | ||||
#include <csignal> | #include <csignal> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <functional> | #include <functional> | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | |||||
CAddrDb db; | CAddrDb db; | ||||
extern "C" void *ThreadCrawler(void *data) { | extern "C" void *ThreadCrawler(void *data) { | ||||
int *nThreads = (int *)data; | int *nThreads = (int *)data; | ||||
do { | do { | ||||
std::vector<CServiceResult> ips; | std::vector<CServiceResult> ips; | ||||
int wait = 5; | int wait = 5; | ||||
db.GetMany(ips, 16, wait); | db.GetMany(ips, 16, wait); | ||||
int64_t now = time(nullptr); | int64_t now = GetTime(); | ||||
if (ips.empty()) { | if (ips.empty()) { | ||||
wait *= 1000; | wait *= 1000; | ||||
wait += rand() % (500 * *nThreads); | wait += rand() % (500 * *nThreads); | ||||
Sleep(wait); | Sleep(wait); | ||||
continue; | continue; | ||||
} | } | ||||
std::vector<CAddress> addr; | std::vector<CAddress> addr; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public: | ||||
std::set<uint64_t> filterWhitelist; | std::set<uint64_t> filterWhitelist; | ||||
void cacheHit(uint64_t requestedFlags, bool force = false) { | void cacheHit(uint64_t requestedFlags, bool force = false) { | ||||
static bool nets[NET_MAX] = {}; | static bool nets[NET_MAX] = {}; | ||||
if (!nets[NET_IPV4]) { | if (!nets[NET_IPV4]) { | ||||
nets[NET_IPV4] = true; | nets[NET_IPV4] = true; | ||||
nets[NET_IPV6] = true; | nets[NET_IPV6] = true; | ||||
} | } | ||||
time_t now = time(nullptr); | int64_t now = GetTime(); | ||||
FlagSpecificData &thisflag = perflag[requestedFlags]; | FlagSpecificData &thisflag = perflag[requestedFlags]; | ||||
thisflag.cacheHits++; | thisflag.cacheHits++; | ||||
if (force || | if (force || | ||||
thisflag.cacheHits * 400 > | thisflag.cacheHits * 400 > | ||||
(thisflag.cache.size() * thisflag.cache.size()) || | (thisflag.cache.size() * thisflag.cache.size()) || | ||||
(thisflag.cacheHits * thisflag.cacheHits * 20 > | (thisflag.cacheHits * thisflag.cacheHits * 20 > | ||||
thisflag.cache.size() && | thisflag.cache.size() && | ||||
(now - thisflag.cacheTime > 5))) { | (now - thisflag.cacheTime > 5))) { | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | do { | ||||
rep.clientVersion, rep.clientSubVersion); | rep.clientVersion, rep.clientSubVersion); | ||||
stat[0] += rep.uptime[0]; | stat[0] += rep.uptime[0]; | ||||
stat[1] += rep.uptime[1]; | stat[1] += rep.uptime[1]; | ||||
stat[2] += rep.uptime[2]; | stat[2] += rep.uptime[2]; | ||||
stat[3] += rep.uptime[3]; | stat[3] += rep.uptime[3]; | ||||
stat[4] += rep.uptime[4]; | stat[4] += rep.uptime[4]; | ||||
} | } | ||||
fsbridge::ofstream ff{"dnsstats.log", std::ios_base::app}; | fsbridge::ofstream ff{"dnsstats.log", std::ios_base::app}; | ||||
tfm::format(ff, "%llu %g %g %g %g %g\n", | tfm::format(ff, "%llu %g %g %g %g %g\n", GetTime(), stat[0], | ||||
(unsigned long long)(time(nullptr)), stat[0], stat[1], | stat[1], stat[2], stat[3], stat[4]); | ||||
stat[2], stat[3], stat[4]); | |||||
} | } | ||||
} while (1); | } while (1); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
extern "C" void *ThreadStats(void *) { | extern "C" void *ThreadStats(void *) { | ||||
bool first = true; | bool first = true; | ||||
do { | do { | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |