Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
#include <clientversion.h> | #include <clientversion.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/system.h> | #include <util/system.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <atomic> | #include <atomic> | ||||
#include <cinttypes> | #include <cinttypes> | ||||
#include <csignal> | #include <csignal> | ||||
#include <cstdio> | |||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <getopt.h> | #include <getopt.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | ||||
class CDnsSeedOpts { | class CDnsSeedOpts { | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 344 Lines • ▼ Show 20 Lines | do { | ||||
Sleep(100000 << count); | Sleep(100000 << count); | ||||
if (count < 5) { | if (count < 5) { | ||||
count++; | count++; | ||||
} | } | ||||
{ | { | ||||
std::vector<CAddrReport> v = db.GetAll(); | std::vector<CAddrReport> v = db.GetAll(); | ||||
sort(v.begin(), v.end(), StatCompare); | sort(v.begin(), v.end(), StatCompare); | ||||
FILE *f = fopen("dnsseed.dat.new", "w+"); | FILE *f = fsbridge::fopen("dnsseed.dat.new", "w+"); | ||||
if (f) { | if (f) { | ||||
{ | { | ||||
CAutoFile cf(f, SER_DISK, CLIENT_VERSION); | CAutoFile cf(f, SER_DISK, CLIENT_VERSION); | ||||
cf << db; | cf << db; | ||||
} | } | ||||
rename("dnsseed.dat.new", "dnsseed.dat"); | rename("dnsseed.dat.new", "dnsseed.dat"); | ||||
} | } | ||||
FILE *d = fopen("dnsseed.dump", "w"); | FILE *d = fsbridge::fopen("dnsseed.dump", "w"); | ||||
fprintf(d, "# address good " | fprintf(d, "# address good " | ||||
"lastSuccess %%(2h) %%(8h) %%(1d) %%(7d) " | "lastSuccess %%(2h) %%(8h) %%(1d) %%(7d) " | ||||
"%%(30d) blocks svcs version\n"); | "%%(30d) blocks svcs version\n"); | ||||
double stat[5] = {0, 0, 0, 0, 0}; | double stat[5] = {0, 0, 0, 0, 0}; | ||||
for (CAddrReport rep : v) { | for (CAddrReport rep : v) { | ||||
fprintf( | fprintf( | ||||
d, | d, | ||||
"%-47s %4d %11" PRId64 | "%-47s %4d %11" PRId64 | ||||
" %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6i %08" PRIx64 | " %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6i %08" PRIx64 | ||||
" %5i \"%s\"\n", | " %5i \"%s\"\n", | ||||
rep.ip.ToString().c_str(), (int)rep.fGood, rep.lastSuccess, | rep.ip.ToString().c_str(), (int)rep.fGood, rep.lastSuccess, | ||||
100.0 * rep.uptime[0], 100.0 * rep.uptime[1], | 100.0 * rep.uptime[0], 100.0 * rep.uptime[1], | ||||
100.0 * rep.uptime[2], 100.0 * rep.uptime[3], | 100.0 * rep.uptime[2], 100.0 * rep.uptime[3], | ||||
100.0 * rep.uptime[4], rep.blocks, rep.services, | 100.0 * rep.uptime[4], rep.blocks, rep.services, | ||||
rep.clientVersion, rep.clientSubVersion.c_str()); | rep.clientVersion, rep.clientSubVersion.c_str()); | ||||
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]; | ||||
} | } | ||||
fclose(d); | fclose(d); | ||||
FILE *ff = fopen("dnsstats.log", "a"); | FILE *ff = fsbridge::fopen("dnsstats.log", "a"); | ||||
fprintf(ff, "%llu %g %g %g %g %g\n", | fprintf(ff, "%llu %g %g %g %g %g\n", | ||||
(unsigned long long)(time(nullptr)), stat[0], stat[1], | (unsigned long long)(time(nullptr)), stat[0], stat[1], | ||||
stat[2], stat[3], stat[4]); | stat[2], stat[3], stat[4]); | ||||
fclose(ff); | fclose(ff); | ||||
} | } | ||||
} while (1); | } while (1); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | int main(int argc, char **argv) { | ||||
if (fDNS && !opts.host) { | if (fDNS && !opts.host) { | ||||
fprintf(stderr, "No hostname set. Please use -h.\n"); | fprintf(stderr, "No hostname set. Please use -h.\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
if (fDNS && !opts.mbox) { | if (fDNS && !opts.mbox) { | ||||
fprintf(stderr, "No e-mail address set. Please use -m.\n"); | fprintf(stderr, "No e-mail address set. Please use -m.\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
FILE *f = fopen("dnsseed.dat", "r"); | FILE *f = fsbridge::fopen("dnsseed.dat", "r"); | ||||
if (f) { | if (f) { | ||||
printf("Loading dnsseed.dat..."); | printf("Loading dnsseed.dat..."); | ||||
CAutoFile cf(f, SER_DISK, CLIENT_VERSION); | CAutoFile cf(f, SER_DISK, CLIENT_VERSION); | ||||
cf >> db; | cf >> db; | ||||
if (opts.fWipeBan) db.banned.clear(); | if (opts.fWipeBan) db.banned.clear(); | ||||
if (opts.fWipeIgnore) db.ResetIgnores(); | if (opts.fWipeIgnore) db.ResetIgnores(); | ||||
printf("done\n"); | printf("done\n"); | ||||
} | } | ||||
Show All 32 Lines |