Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
Show First 20 Lines • Show All 418 Lines • ▼ Show 20 Lines | do { | ||||
char c[256]; | char c[256]; | ||||
time_t tim = time(nullptr); | time_t tim = time(nullptr); | ||||
struct tm *tmp = localtime(&tim); | struct tm *tmp = localtime(&tim); | ||||
strftime(c, 256, "[%y-%m-%d %H:%M:%S]", tmp); | strftime(c, 256, "[%y-%m-%d %H:%M:%S]", tmp); | ||||
CAddrDbStats stats; | CAddrDbStats stats; | ||||
db.GetStats(stats); | db.GetStats(stats); | ||||
if (first) { | if (first) { | ||||
first = false; | first = false; | ||||
printf("\n\n\n\x1b[3A"); | fprintf(stdout, "\n\n\n\x1b[3A"); | ||||
} else | } else | ||||
printf("\x1b[2K\x1b[u"); | fprintf(stdout, "\x1b[2K\x1b[u"); | ||||
printf("\x1b[s"); | fprintf(stdout, "\x1b[s"); | ||||
uint64_t requests = 0; | uint64_t requests = 0; | ||||
uint64_t queries = 0; | uint64_t queries = 0; | ||||
for (unsigned int i = 0; i < dnsThread.size(); i++) { | for (unsigned int i = 0; i < dnsThread.size(); i++) { | ||||
requests += dnsThread[i]->dns_opt.nRequests; | requests += dnsThread[i]->dns_opt.nRequests; | ||||
queries += dnsThread[i]->dbQueries; | queries += dnsThread[i]->dbQueries; | ||||
} | } | ||||
printf("%s %i/%i available (%i tried in %is, %i new, %i active), %i " | fprintf(stdout, | ||||
"%s %i/%i available (%i tried in %is, %i new, %i active), %i " | |||||
"banned; %llu DNS requests, %llu db queries\n", | "banned; %llu DNS requests, %llu db queries\n", | ||||
c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge, | c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge, | ||||
stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, | stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, | ||||
stats.nBanned, (unsigned long long)requests, | stats.nBanned, (unsigned long long)requests, | ||||
(unsigned long long)queries); | (unsigned long long)queries); | ||||
Sleep(1000); | Sleep(1000); | ||||
} while (1); | } while (1); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
static const std::string mainnet_seeds[] = { | static const std::string mainnet_seeds[] = { | ||||
"seed.bitcoinabc.org", "seed-abc.bitcoinforks.org", | "seed.bitcoinabc.org", "seed-abc.bitcoinforks.org", | ||||
"seed.bitprim.org", "seed.deadalnix.me", | "seed.bitprim.org", "seed.deadalnix.me", | ||||
Show All 23 Lines | |||||
int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||||
// The logger dump everything on the console by default. | // The logger dump everything on the console by default. | ||||
GetLogger().m_print_to_console = true; | GetLogger().m_print_to_console = true; | ||||
signal(SIGPIPE, SIG_IGN); | signal(SIGPIPE, SIG_IGN); | ||||
setbuf(stdout, nullptr); | setbuf(stdout, nullptr); | ||||
CDnsSeedOpts opts; | CDnsSeedOpts opts; | ||||
opts.ParseCommandLine(argc, argv); | opts.ParseCommandLine(argc, argv); | ||||
printf("Supporting whitelisted filters: "); | fprintf(stdout, "Supporting whitelisted filters: "); | ||||
for (std::set<uint64_t>::const_iterator it = opts.filter_whitelist.begin(); | for (std::set<uint64_t>::const_iterator it = opts.filter_whitelist.begin(); | ||||
it != opts.filter_whitelist.end(); it++) { | it != opts.filter_whitelist.end(); it++) { | ||||
if (it != opts.filter_whitelist.begin()) { | if (it != opts.filter_whitelist.begin()) { | ||||
printf(","); | fprintf(stdout, ","); | ||||
} | } | ||||
printf("0x%lx", (unsigned long)*it); | fprintf(stdout, "0x%lx", (unsigned long)*it); | ||||
} | } | ||||
printf("\n"); | fprintf(stdout, "\n"); | ||||
if (opts.tor) { | if (opts.tor) { | ||||
CService service(LookupNumeric(opts.tor, 9050)); | CService service(LookupNumeric(opts.tor, 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
printf("Using Tor proxy at %s\n", service.ToStringIPPort().c_str()); | fprintf(stdout, "Using Tor proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | |||||
SetProxy(NET_ONION, proxyType(service)); | SetProxy(NET_ONION, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
if (opts.ipv4_proxy) { | if (opts.ipv4_proxy) { | ||||
CService service(LookupNumeric(opts.ipv4_proxy, 9050)); | CService service(LookupNumeric(opts.ipv4_proxy, 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
printf("Using IPv4 proxy at %s\n", | fprintf(stdout, "Using IPv4 proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | service.ToStringIPPort().c_str()); | ||||
SetProxy(NET_IPV4, proxyType(service)); | SetProxy(NET_IPV4, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
if (opts.ipv6_proxy) { | if (opts.ipv6_proxy) { | ||||
CService service(LookupNumeric(opts.ipv6_proxy, 9050)); | CService service(LookupNumeric(opts.ipv6_proxy, 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
printf("Using IPv6 proxy at %s\n", | fprintf(stdout, "Using IPv6 proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | service.ToStringIPPort().c_str()); | ||||
SetProxy(NET_IPV6, proxyType(service)); | SetProxy(NET_IPV6, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
bool fDNS = true; | bool fDNS = true; | ||||
if (opts.fUseTestNet) { | if (opts.fUseTestNet) { | ||||
printf("Using testnet.\n"); | fprintf(stdout, "Using testnet.\n"); | ||||
netMagic[0] = 0xf4; | netMagic[0] = 0xf4; | ||||
netMagic[1] = 0xe5; | netMagic[1] = 0xe5; | ||||
netMagic[2] = 0xf3; | netMagic[2] = 0xf3; | ||||
netMagic[3] = 0xf4; | netMagic[3] = 0xf4; | ||||
seeds = testnet_seeds; | seeds = testnet_seeds; | ||||
fTestNet = true; | fTestNet = true; | ||||
} | } | ||||
if (!opts.ns) { | if (!opts.ns) { | ||||
printf("No nameserver set. Not starting DNS server.\n"); | fprintf(stdout, "No nameserver set. Not starting DNS server.\n"); | ||||
fDNS = false; | fDNS = false; | ||||
} | } | ||||
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 = fsbridge::fopen("dnsseed.dat", "r"); | FILE *f = fsbridge::fopen("dnsseed.dat", "r"); | ||||
if (f) { | if (f) { | ||||
printf("Loading dnsseed.dat..."); | fprintf(stdout, "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"); | fprintf(stdout, "done\n"); | ||||
} | } | ||||
pthread_t threadDns, threadSeed, threadDump, threadStats; | pthread_t threadDns, threadSeed, threadDump, threadStats; | ||||
if (fDNS) { | if (fDNS) { | ||||
printf("Starting %i DNS threads for %s on %s (port %i)...", | fprintf(stdout, "Starting %i DNS threads for %s on %s (port %i)...", | ||||
opts.nDnsThreads, opts.host, opts.ns, opts.nPort); | opts.nDnsThreads, opts.host, opts.ns, opts.nPort); | ||||
dnsThread.clear(); | dnsThread.clear(); | ||||
for (int i = 0; i < opts.nDnsThreads; i++) { | for (int i = 0; i < opts.nDnsThreads; i++) { | ||||
dnsThread.push_back(new CDnsThread(&opts, i)); | dnsThread.push_back(new CDnsThread(&opts, i)); | ||||
pthread_create(&threadDns, nullptr, ThreadDNS, dnsThread[i]); | pthread_create(&threadDns, nullptr, ThreadDNS, dnsThread[i]); | ||||
printf("."); | fprintf(stdout, "."); | ||||
Sleep(20); | Sleep(20); | ||||
} | } | ||||
printf("done\n"); | fprintf(stdout, "done\n"); | ||||
} | } | ||||
printf("Starting seeder..."); | fprintf(stdout, "Starting seeder..."); | ||||
pthread_create(&threadSeed, nullptr, ThreadSeeder, nullptr); | pthread_create(&threadSeed, nullptr, ThreadSeeder, nullptr); | ||||
printf("done\n"); | fprintf(stdout, "done\n"); | ||||
printf("Starting %i crawler threads...", opts.nThreads); | fprintf(stdout, "Starting %i crawler threads...", opts.nThreads); | ||||
pthread_attr_t attr_crawler; | pthread_attr_t attr_crawler; | ||||
pthread_attr_init(&attr_crawler); | pthread_attr_init(&attr_crawler); | ||||
pthread_attr_setstacksize(&attr_crawler, 0x20000); | pthread_attr_setstacksize(&attr_crawler, 0x20000); | ||||
for (int i = 0; i < opts.nThreads; i++) { | for (int i = 0; i < opts.nThreads; i++) { | ||||
pthread_t thread; | pthread_t thread; | ||||
pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads); | pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads); | ||||
} | } | ||||
pthread_attr_destroy(&attr_crawler); | pthread_attr_destroy(&attr_crawler); | ||||
printf("done\n"); | fprintf(stdout, "done\n"); | ||||
pthread_create(&threadStats, nullptr, ThreadStats, nullptr); | pthread_create(&threadStats, nullptr, ThreadStats, nullptr); | ||||
pthread_create(&threadDump, nullptr, ThreadDumper, nullptr); | pthread_create(&threadDump, nullptr, ThreadDumper, nullptr); | ||||
void *res; | void *res; | ||||
pthread_join(threadDump, &res); | pthread_join(threadDump, &res); | ||||
return 0; | return 0; | ||||
} | } |