Bitcoin ABC  0.24.7
P2P Digital Currency
main.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <chainparams.h>
6 #include <clientversion.h>
7 #include <dnsseeds.h>
8 #include <fs.h>
9 #include <logging.h>
10 #include <protocol.h>
11 #include <seeder/bitcoin.h>
12 #include <seeder/db.h>
13 #include <seeder/dns.h>
14 #include <streams.h>
15 #include <util/strencodings.h>
16 #include <util/system.h>
17 #include <util/time.h>
18 #include <util/translation.h>
19 
20 #include <algorithm>
21 #include <atomic>
22 #include <cinttypes>
23 #include <csignal>
24 #include <cstdlib>
25 #include <functional>
26 #include <pthread.h>
27 
28 const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr;
29 
30 static const int CONTINUE_EXECUTION = -1;
31 
32 static const int DEFAULT_NUM_THREADS = 96;
33 static const int DEFAULT_PORT = 53;
34 static const int DEFAULT_NUM_DNS_THREADS = 4;
35 static const bool DEFAULT_WIPE_BAN = false;
36 static const bool DEFAULT_WIPE_IGNORE = false;
37 static const std::string DEFAULT_EMAIL = "";
38 static const std::string DEFAULT_NAMESERVER = "";
39 static const std::string DEFAULT_HOST = "";
40 static const std::string DEFAULT_TOR_PROXY = "";
41 static const std::string DEFAULT_LISTEN_ADDRESS = "::";
42 static const std::string DEFAULT_IPV4_PROXY = "";
43 static const std::string DEFAULT_IPV6_PROXY = "";
44 
45 class CDnsSeedOpts {
46 public:
47  int nThreads;
48  int nPort;
50  bool fWipeBan;
52  std::string mbox;
53  std::string ns;
54  std::string host;
55  std::string tor;
56  std::string ip_addr;
57  std::string ipv4_proxy;
58  std::string ipv6_proxy;
59  std::set<uint64_t> filter_whitelist;
60 
68 
69  int ParseCommandLine(int argc, char **argv) {
71  std::string error;
72  if (!gArgs.ParseParameters(argc, argv, error)) {
73  tfm::format(std::cerr, "Error parsing command line arguments: %s\n",
74  error);
75  return EXIT_FAILURE;
76  }
77  if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
78  std::string strUsage =
79  PACKAGE_NAME " Seeder " + FormatFullVersion() + "\n";
80  if (HelpRequested(gArgs)) {
81  strUsage +=
82  "\nUsage: bitcoin-seeder -host=<host> -ns=<ns> "
83  "[-mbox=<mbox>] [-threads=<threads>] [-port=<port>]\n\n" +
85  }
86 
87  tfm::format(std::cout, "%s", strUsage);
88  return EXIT_SUCCESS;
89  }
90 
92  nPort = gArgs.GetArg("-port", DEFAULT_PORT);
96  mbox = gArgs.GetArg("-mbox", DEFAULT_EMAIL);
98  host = gArgs.GetArg("-host", DEFAULT_HOST);
99  tor = gArgs.GetArg("-onion", DEFAULT_TOR_PROXY);
101  ipv4_proxy = gArgs.GetArg("-proxyipv4", DEFAULT_IPV4_PROXY);
102  ipv6_proxy = gArgs.GetArg("-proxyipv6", DEFAULT_IPV6_PROXY);
104 
105  // Both IPv4 and IPv6 addresses are valid, but the listening address is
106  // treated as IPv6 internally
107  if (ip_addr.find(':') == std::string::npos) {
108  ip_addr.insert(0, "::FFFF:");
109  }
110 
111  if (gArgs.IsArgSet("-filter")) {
112  // Parse whitelist additions
113  std::string flagString = gArgs.GetArg("-filter", "");
114  size_t flagstartpos = 0;
115  while (flagstartpos < flagString.size()) {
116  size_t flagendpos = flagString.find_first_of(',', flagstartpos);
117  uint64_t flag = atoi64(flagString.substr(
118  flagstartpos, (flagendpos - flagstartpos)));
119  filter_whitelist.insert(flag);
120  if (flagendpos == std::string::npos) {
121  break;
122  }
123  flagstartpos = flagendpos + 1;
124  }
125  }
126  if (filter_whitelist.empty()) {
131  }
132  return CONTINUE_EXECUTION;
133  }
134 
135 private:
136  void SetupSeederArgs(ArgsManager &argsman) {
137  SetupHelpOptions(argsman);
138  argsman.AddArg("-help-debug",
139  "Show all debugging options (usage: --help -help-debug)",
141 
143 
144  argsman.AddArg("-version", "Print version and exit",
146  argsman.AddArg("-host=<host>", "Hostname of the DNS seed",
148  argsman.AddArg("-ns=<ns>", "Hostname of the nameserver",
150  argsman.AddArg("-mbox=<mbox>", "E-Mail address reported in SOA records",
152  argsman.AddArg(
153  "-threads=<threads>",
154  strprintf("Number of crawlers to run in parallel (default: %d)",
157  argsman.AddArg("-dnsthreads=<threads>",
158  strprintf("Number of DNS server threads (default: %d)",
161  argsman.AddArg("-address=<address>",
162  strprintf("Address to listen on (default: '%s')",
165  argsman.AddArg(
166  "-port=<port>",
167  strprintf("UDP port to listen on (default: %d)", DEFAULT_PORT),
169  argsman.AddArg("-onion=<ip:port>", "Tor proxy IP/Port",
171  argsman.AddArg("-overridednsseed",
172  "If set, only use the specified DNS seed when "
173  "querying for peer addresses via DNS lookup.",
175  argsman.AddArg("-proxyipv4=<ip:port>", "IPV4 SOCKS5 proxy IP/Port",
177  argsman.AddArg("-proxyipv6=<ip:port>", "IPV6 SOCKS5 proxy IP/Port",
179  argsman.AddArg("-filter=<f1,f2,...>",
180  "Allow these flag combinations as filters",
182  argsman.AddArg("-wipeban", "Wipe list of banned nodes",
184  argsman.AddArg("-wipeignore", "Wipe list of ignored nodes",
186  }
187 };
188 
189 extern "C" {
190 #include <seeder/dns.h>
191 }
192 
194 
195 extern "C" void *ThreadCrawler(void *data) {
196  int *nThreads = (int *)data;
197  do {
198  std::vector<CServiceResult> ips;
199  int wait = 5;
200  db.GetMany(ips, 16, wait);
201  int64_t now = GetTime();
202  if (ips.empty()) {
203  wait *= 1000;
204  wait += rand() % (500 * *nThreads);
205  Sleep(wait);
206  continue;
207  }
208 
209  std::vector<CAddress> addr;
210  for (size_t i = 0; i < ips.size(); i++) {
211  CServiceResult &res = ips[i];
212  res.nBanTime = 0;
213  res.nClientV = 0;
214  res.nHeight = 0;
215  res.strClientV = "";
216  res.services = 0;
217  bool getaddr = res.ourLastSuccess + 86400 < now;
218  try {
219  CSeederNode node(res.service, getaddr ? &addr : nullptr);
220  bool ret = node.Run();
221  if (!ret) {
222  res.nBanTime = node.GetBan();
223  } else {
224  res.nBanTime = 0;
225  }
226  res.nClientV = node.GetClientVersion();
227  res.strClientV = node.GetClientSubVersion();
228  res.nHeight = node.GetStartingHeight();
229  res.services = node.GetServices();
230  // tfm::format(std::cout, "%s: %s!!!\n", cip.ToString(),
231  // ret ? "GOOD" : "BAD");
232  res.fGood = ret;
233  } catch (std::ios_base::failure &e) {
234  res.nBanTime = 0;
235  res.fGood = false;
236  }
237  }
238 
239  db.ResultMany(ips);
240  db.Add(addr);
241  } while (1);
242  return nullptr;
243 }
244 
245 extern "C" uint32_t GetIPList(void *thread, char *requestedHostname,
246  addr_t *addr, uint32_t max, uint32_t ipv4,
247  uint32_t ipv6);
248 
249 class CDnsThread {
250 public:
252  int nIPv4, nIPv6;
253  std::vector<addr_t> cache;
254  time_t cacheTime;
255  unsigned int cacheHits;
257  };
258 
259  dns_opt_t dns_opt; // must be first
260  const int id;
261  std::map<uint64_t, FlagSpecificData> perflag;
262  std::atomic<uint64_t> dbQueries;
263  std::set<uint64_t> filterWhitelist;
264 
265  void cacheHit(uint64_t requestedFlags, bool force = false) {
266  static bool nets[NET_MAX] = {};
267  if (!nets[NET_IPV4]) {
268  nets[NET_IPV4] = true;
269  nets[NET_IPV6] = true;
270  }
271  int64_t now = GetTime();
272  FlagSpecificData &thisflag = perflag[requestedFlags];
273  thisflag.cacheHits++;
274  if (force ||
275  thisflag.cacheHits * 400 >
276  (thisflag.cache.size() * thisflag.cache.size()) ||
277  (thisflag.cacheHits * thisflag.cacheHits * 20 >
278  thisflag.cache.size() &&
279  (now - thisflag.cacheTime > 5))) {
280  std::set<CNetAddr> ips;
281  db.GetIPs(ips, requestedFlags, 1000, nets);
282  dbQueries++;
283  thisflag.cache.clear();
284  thisflag.nIPv4 = 0;
285  thisflag.nIPv6 = 0;
286  thisflag.cache.reserve(ips.size());
287  for (auto &ip : ips) {
288  struct in_addr addr;
289  struct in6_addr addr6;
290  if (ip.GetInAddr(&addr)) {
291  addr_t a;
292  a.v = 4;
293  memcpy(&a.data.v4, &addr, 4);
294  thisflag.cache.push_back(a);
295  thisflag.nIPv4++;
296  } else if (ip.GetIn6Addr(&addr6)) {
297  addr_t a;
298  a.v = 6;
299  memcpy(&a.data.v6, &addr6, 16);
300  thisflag.cache.push_back(a);
301  thisflag.nIPv6++;
302  }
303  }
304  thisflag.cacheHits = 0;
305  thisflag.cacheTime = now;
306  }
307  }
308 
309  CDnsThread(CDnsSeedOpts *opts, int idIn) : id(idIn) {
310  dns_opt.host = opts->host.c_str();
311  dns_opt.ns = opts->ns.c_str();
312  dns_opt.mbox = opts->mbox.c_str();
313  dns_opt.datattl = 3600;
314  dns_opt.nsttl = 40000;
315  dns_opt.cb = GetIPList;
316  dns_opt.addr = opts->ip_addr.c_str();
317  dns_opt.port = opts->nPort;
318  dns_opt.nRequests = 0;
319  dbQueries = 0;
320  perflag.clear();
322  }
323 
324  void run() { dnsserver(&dns_opt); }
325 };
326 
327 extern "C" uint32_t GetIPList(void *data, char *requestedHostname, addr_t *addr,
328  uint32_t max, uint32_t ipv4, uint32_t ipv6) {
329  CDnsThread *thread = (CDnsThread *)data;
330 
331  uint64_t requestedFlags = 0;
332  int hostlen = strlen(requestedHostname);
333  if (hostlen > 1 && requestedHostname[0] == 'x' &&
334  requestedHostname[1] != '0') {
335  char *pEnd;
336  uint64_t flags = (uint64_t)strtoull(requestedHostname + 1, &pEnd, 16);
337  if (*pEnd == '.' && pEnd <= requestedHostname + 17 &&
338  std::find(thread->filterWhitelist.begin(),
339  thread->filterWhitelist.end(),
340  flags) != thread->filterWhitelist.end()) {
341  requestedFlags = flags;
342  } else {
343  return 0;
344  }
345  } else if (strcasecmp(requestedHostname, thread->dns_opt.host)) {
346  return 0;
347  }
348  thread->cacheHit(requestedFlags);
349  auto &thisflag = thread->perflag[requestedFlags];
350  uint32_t size = thisflag.cache.size();
351  uint32_t maxmax = (ipv4 ? thisflag.nIPv4 : 0) + (ipv6 ? thisflag.nIPv6 : 0);
352  if (max > size) {
353  max = size;
354  }
355  if (max > maxmax) {
356  max = maxmax;
357  }
358  uint32_t i = 0;
359  while (i < max) {
360  uint32_t j = i + (rand() % (size - i));
361  do {
362  bool ok = (ipv4 && thisflag.cache[j].v == 4) ||
363  (ipv6 && thisflag.cache[j].v == 6);
364  if (ok) {
365  break;
366  }
367  j++;
368  if (j == size) {
369  j = i;
370  }
371  } while (1);
372  addr[i] = thisflag.cache[j];
373  thisflag.cache[j] = thisflag.cache[i];
374  thisflag.cache[i] = addr[i];
375  i++;
376  }
377  return max;
378 }
379 
380 std::vector<CDnsThread *> dnsThread;
381 
382 extern "C" void *ThreadDNS(void *arg) {
383  CDnsThread *thread = (CDnsThread *)arg;
384  thread->run();
385  return nullptr;
386 }
387 
388 int StatCompare(const CAddrReport &a, const CAddrReport &b) {
389  if (a.uptime[4] == b.uptime[4]) {
390  if (a.uptime[3] == b.uptime[3]) {
391  return a.clientVersion > b.clientVersion;
392  } else {
393  return a.uptime[3] > b.uptime[3];
394  }
395  } else {
396  return a.uptime[4] > b.uptime[4];
397  }
398 }
399 
400 extern "C" void *ThreadDumper(void *) {
401  int count = 0;
402  do {
403  // First 100s, than 200s, 400s, 800s, 1600s, and then 3200s forever
404  Sleep(100000 << count);
405  if (count < 5) {
406  count++;
407  }
408 
409  {
410  std::vector<CAddrReport> v = db.GetAll();
411  sort(v.begin(), v.end(), StatCompare);
412  FILE *f = fsbridge::fopen("dnsseed.dat.new", "w+");
413  if (f) {
414  {
416  cf << db;
417  }
418  rename("dnsseed.dat.new", "dnsseed.dat");
419  }
420  fsbridge::ofstream d{"dnsseed.dump"};
421  tfm::format(
422  d, "# address good "
423  "lastSuccess %%(2h) %%(8h) %%(1d) %%(7d) "
424  "%%(30d) blocks svcs version\n");
425  double stat[5] = {0, 0, 0, 0, 0};
426  for (CAddrReport rep : v) {
427  tfm::format(
428  d,
429  "%-47s %4d %11" PRId64
430  " %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6i %08" PRIx64
431  " %5i \"%s\"\n",
432  rep.ip.ToString(), (int)rep.fGood, rep.lastSuccess,
433  100.0 * rep.uptime[0], 100.0 * rep.uptime[1],
434  100.0 * rep.uptime[2], 100.0 * rep.uptime[3],
435  100.0 * rep.uptime[4], rep.blocks, rep.services,
436  rep.clientVersion, rep.clientSubVersion);
437  stat[0] += rep.uptime[0];
438  stat[1] += rep.uptime[1];
439  stat[2] += rep.uptime[2];
440  stat[3] += rep.uptime[3];
441  stat[4] += rep.uptime[4];
442  }
443  fsbridge::ofstream ff{"dnsstats.log", std::ios_base::app};
444  tfm::format(ff, "%llu %g %g %g %g %g\n", GetTime(), stat[0],
445  stat[1], stat[2], stat[3], stat[4]);
446  }
447  } while (1);
448  return nullptr;
449 }
450 
451 extern "C" void *ThreadStats(void *) {
452  bool first = true;
453  do {
454  char c[256];
455  time_t tim = time(nullptr);
456  struct tm *tmp = localtime(&tim);
457  strftime(c, 256, "[%y-%m-%d %H:%M:%S]", tmp);
458  CAddrDbStats stats;
459  db.GetStats(stats);
460  if (first) {
461  first = false;
462  tfm::format(std::cout, "\n\n\n\x1b[3A");
463  } else {
464  tfm::format(std::cout, "\x1b[2K\x1b[u");
465  }
466  tfm::format(std::cout, "\x1b[s");
467  uint64_t requests = 0;
468  uint64_t queries = 0;
469  for (unsigned int i = 0; i < dnsThread.size(); i++) {
470  requests += dnsThread[i]->dns_opt.nRequests;
471  queries += dnsThread[i]->dbQueries;
472  }
473  tfm::format(
474  std::cout,
475  "%s %i/%i available (%i tried in %is, %i new, %i active), %i "
476  "banned; %llu DNS requests, %llu db queries\n",
477  c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge,
478  stats.nNew, stats.nAvail - stats.nTracked - stats.nNew,
479  stats.nBanned, (unsigned long long)requests,
480  (unsigned long long)queries);
481  Sleep(1000);
482  } while (1);
483  return nullptr;
484 }
485 
486 const static unsigned int MAX_HOSTS_PER_SEED = 128;
487 
488 extern "C" void *ThreadSeeder(void *) {
489  do {
490  for (const std::string &seed : GetRandomizedDNSSeeds(Params())) {
491  std::vector<CNetAddr> ips;
492  LookupHost(seed.c_str(), ips, MAX_HOSTS_PER_SEED, true);
493  for (auto &ip : ips) {
495  true);
496  }
497  }
498  Sleep(1800000);
499  } while (1);
500  return nullptr;
501 }
502 
503 int main(int argc, char **argv) {
504  // The logger dump everything on the console by default.
506 
507  signal(SIGPIPE, SIG_IGN);
508  setbuf(stdout, nullptr);
509  CDnsSeedOpts opts;
510  int parseResults = opts.ParseCommandLine(argc, argv);
511  if (parseResults != CONTINUE_EXECUTION) {
512  return parseResults;
513  }
514 
515  tfm::format(std::cout, "Supporting whitelisted filters: ");
516  for (std::set<uint64_t>::const_iterator it = opts.filter_whitelist.begin();
517  it != opts.filter_whitelist.end(); it++) {
518  if (it != opts.filter_whitelist.begin()) {
519  tfm::format(std::cout, ",");
520  }
521  tfm::format(std::cout, "0x%lx", (unsigned long)*it);
522  }
523  tfm::format(std::cout, "\n");
524  if (!opts.tor.empty()) {
525  CService service(LookupNumeric(opts.tor.c_str(), 9050));
526  if (service.IsValid()) {
527  tfm::format(std::cout, "Using Tor proxy at %s\n",
528  service.ToStringIPPort());
529  SetProxy(NET_ONION, proxyType(service));
530  }
531  }
532  if (!opts.ipv4_proxy.empty()) {
533  CService service(LookupNumeric(opts.ipv4_proxy.c_str(), 9050));
534  if (service.IsValid()) {
535  tfm::format(std::cout, "Using IPv4 proxy at %s\n",
536  service.ToStringIPPort());
537  SetProxy(NET_IPV4, proxyType(service));
538  }
539  }
540  if (!opts.ipv6_proxy.empty()) {
541  CService service(LookupNumeric(opts.ipv6_proxy.c_str(), 9050));
542  if (service.IsValid()) {
543  tfm::format(std::cout, "Using IPv6 proxy at %s\n",
544  service.ToStringIPPort());
545  SetProxy(NET_IPV6, proxyType(service));
546  }
547  }
548  bool fDNS = true;
549  tfm::format(std::cout, "Using %s.\n", gArgs.GetChainName());
550  if (opts.ns.empty()) {
551  tfm::format(std::cout, "No nameserver set. Not starting DNS server.\n");
552  fDNS = false;
553  }
554  if (fDNS && opts.host.empty()) {
555  tfm::format(std::cerr, "No hostname set. Please use -h.\n");
556  return EXIT_FAILURE;
557  }
558  if (fDNS && opts.mbox.empty()) {
559  tfm::format(std::cerr, "No e-mail address set. Please use -m.\n");
560  return EXIT_FAILURE;
561  }
562  FILE *f = fsbridge::fopen("dnsseed.dat", "r");
563  if (f) {
564  tfm::format(std::cout, "Loading dnsseed.dat...");
566  cf >> db;
567  if (opts.fWipeBan) {
568  db.banned.clear();
569  tfm::format(std::cout, "Ban list wiped...");
570  }
571  if (opts.fWipeIgnore) {
572  db.ResetIgnores();
573  tfm::format(std::cout, "Ignore list wiped...");
574  }
575  tfm::format(std::cout, "done\n");
576  }
577  pthread_t threadDns, threadSeed, threadDump, threadStats;
578  if (fDNS) {
579  tfm::format(std::cout,
580  "Starting %i DNS threads for %s on %s (port %i)...",
581  opts.nDnsThreads, opts.host, opts.ns, opts.nPort);
582  dnsThread.clear();
583  for (int i = 0; i < opts.nDnsThreads; i++) {
584  dnsThread.push_back(new CDnsThread(&opts, i));
585  pthread_create(&threadDns, nullptr, ThreadDNS, dnsThread[i]);
586  tfm::format(std::cout, ".");
587  Sleep(20);
588  }
589  tfm::format(std::cout, "done\n");
590  }
591  tfm::format(std::cout, "Starting seeder...");
592  pthread_create(&threadSeed, nullptr, ThreadSeeder, nullptr);
593  tfm::format(std::cout, "done\n");
594  tfm::format(std::cout, "Starting %i crawler threads...", opts.nThreads);
595  pthread_attr_t attr_crawler;
596  pthread_attr_init(&attr_crawler);
597  pthread_attr_setstacksize(&attr_crawler, 0x20000);
598  for (int i = 0; i < opts.nThreads; i++) {
599  pthread_t thread;
600  pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads);
601  }
602  pthread_attr_destroy(&attr_crawler);
603  tfm::format(std::cout, "done\n");
604  pthread_create(&threadStats, nullptr, ThreadStats, nullptr);
605  pthread_create(&threadDump, nullptr, ThreadDumper, nullptr);
606  void *res;
607  pthread_join(threadDump, &res);
608  return EXIT_SUCCESS;
609 }
atoi64
int64_t atoi64(const std::string &str)
Definition: strencodings.cpp:469
CDnsSeedOpts::ipv6_proxy
std::string ipv6_proxy
Definition: main.cpp:58
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:514
DEFAULT_NAMESERVER
static const std::string DEFAULT_NAMESERVER
Definition: main.cpp:38
ThreadStats
void * ThreadStats(void *)
Definition: main.cpp:451
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:517
CDnsThread::run
void run()
Definition: main.cpp:324
CServiceResult::nBanTime
int nBanTime
Definition: db.h:248
CAddrDbStats::nNew
int nNew
Definition: db.h:239
count
static int count
Definition: tests.c:41
tinyformat::format
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1111
CAddrDbStats::nAge
int nAge
Definition: db.h:241
ThreadDNS
void * ThreadDNS(void *arg)
Definition: main.cpp:382
NET_IPV4
@ NET_IPV4
IPv4.
Definition: netaddress.h:49
CServiceResult::nHeight
int nHeight
Definition: db.h:249
fs.h
dns_opt_t::nsttl
int nsttl
Definition: dns.h:27
CAddrDbStats
Definition: db.h:234
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:24
CAddrDb::ResetIgnores
void ResetIgnores()
Definition: db.h:317
flags
int flags
Definition: bitcoin-tx.cpp:532
streams.h
SetupHelpOptions
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
Definition: system.cpp:676
ArgsManager::ALLOW_ANY
@ ALLOW_ANY
Definition: system.h:159
ArgsManager::GetHelpMessage
std::string GetHelpMessage() const
Get the help string.
Definition: system.cpp:598
ThreadCrawler
void * ThreadCrawler(void *data)
Definition: main.cpp:195
NET_MAX
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:68
SetupChainParamsBaseOptions
void SetupChainParamsBaseOptions(ArgsManager &argsman)
Set the arguments for chainparams.
Definition: chainparamsbase.cpp:17
ArgsManager::GetChainName
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Definition: system.cpp:1033
DEFAULT_IPV4_PROXY
static const std::string DEFAULT_IPV4_PROXY
Definition: main.cpp:42
CAddrReport
Definition: db.h:63
ArgsManager::IsArgSet
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:400
Sleep
static void Sleep(int nMilliSec)
Definition: util.h:13
CServiceResult::nClientV
int nClientV
Definition: db.h:250
CDnsThread::dns_opt
dns_opt_t dns_opt
Definition: main.cpp:259
CDnsSeedOpts::host
std::string host
Definition: main.cpp:54
CDnsSeedOpts::fWipeBan
bool fWipeBan
Definition: main.cpp:50
GetTime
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:27
clientversion.h
CDnsThread::FlagSpecificData::cacheHits
unsigned int cacheHits
Definition: main.cpp:255
dns_opt_t::mbox
const char * mbox
Definition: dns.h:31
ServiceFlags
ServiceFlags
nServices flags.
Definition: protocol.h:314
CDnsThread::FlagSpecificData::cache
std::vector< addr_t > cache
Definition: main.cpp:253
CDnsSeedOpts::ns
std::string ns
Definition: main.cpp:53
CDnsThread::FlagSpecificData::nIPv4
int nIPv4
Definition: main.cpp:252
OptionsCategory::CONNECTION
@ CONNECTION
NODE_NETWORK_LIMITED
@ NODE_NETWORK_LIMITED
Definition: protocol.h:344
DEFAULT_EMAIL
static const std::string DEFAULT_EMAIL
Definition: main.cpp:37
DEFAULT_PORT
static const int DEFAULT_PORT
Definition: main.cpp:33
CDnsSeedOpts::mbox
std::string mbox
Definition: main.cpp:52
addr_t::v6
uint8_t v6[16]
Definition: dns.h:20
CDnsThread::perflag
std::map< uint64_t, FlagSpecificData > perflag
Definition: main.cpp:261
DEFAULT_LISTEN_ADDRESS
static const std::string DEFAULT_LISTEN_ADDRESS
Definition: main.cpp:41
NODE_NETWORK
@ NODE_NETWORK
Definition: protocol.h:321
chainparams.h
dns_opt_t::host
const char * host
Definition: dns.h:28
CSeederNode::GetStartingHeight
int GetStartingHeight()
Definition: bitcoin.h:79
proxyType
Definition: netbase.h:28
CService::ToStringIPPort
std::string ToStringIPPort() const
Definition: netaddress.cpp:1012
CAddrDb::GetStats
void GetStats(CAddrDbStats &stats) const
Definition: db.h:303
CDnsThread::filterWhitelist
std::set< uint64_t > filterWhitelist
Definition: main.cpp:263
CSeederNode::Run
bool Run()
Definition: bitcoin.cpp:186
db.h
CDnsSeedOpts::nPort
int nPort
Definition: main.cpp:48
CONTINUE_EXECUTION
static const int CONTINUE_EXECUTION
Definition: main.cpp:30
CSeederNode::GetBan
int GetBan()
Definition: bitcoin.h:73
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:581
fsbridge::ofstream
fs::ofstream ofstream
Definition: fs.h:99
HelpRequested
bool HelpRequested(const ArgsManager &args)
Definition: system.cpp:671
strencodings.h
CServiceResult::strClientV
std::string strClientV
Definition: db.h:251
CAddrDb::GetIPs
void GetIPs(std::set< CNetAddr > &ips, uint64_t requestedFlags, uint32_t max, const bool *nets)
Definition: db.h:436
CDnsThread::FlagSpecificData::nIPv6
int nIPv6
Definition: main.cpp:252
CAddrDb::GetAll
std::vector< CAddrReport > GetAll()
Definition: db.h:324
CDnsSeedOpts
Definition: main.cpp:45
dns_opt_t::port
int port
Definition: dns.h:25
CAddrDb::Add
void Add(const CAddress &addr, bool fForce=false)
Definition: db.h:400
CDnsSeedOpts::nThreads
int nThreads
Definition: main.cpp:47
ThreadSeeder
void * ThreadSeeder(void *)
Definition: main.cpp:488
main
int main(int argc, char *argv[])
Definition: main.cpp:20
dnsThread
std::vector< CDnsThread * > dnsThread
Definition: main.cpp:380
CDnsThread::CDnsThread
CDnsThread(CDnsSeedOpts *opts, int idIn)
Definition: main.cpp:309
bitcoin.h
CSeederNode::GetClientSubVersion
std::string GetClientSubVersion()
Definition: bitcoin.h:77
CDnsThread::id
const int id
Definition: main.cpp:260
ArgsManager::AddArg
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:565
addr_t::v4
uint8_t v4[4]
Definition: dns.h:19
StatCompare
int StatCompare(const CAddrReport &a, const CAddrReport &b)
Definition: main.cpp:388
MAX_HOSTS_PER_SEED
const static unsigned int MAX_HOSTS_PER_SEED
Definition: main.cpp:486
GetRandomizedDNSSeeds
const std::vector< std::string > GetRandomizedDNSSeeds(const CChainParams &params)
Return the list of hostnames to look up for DNS seeds.
Definition: dnsseeds.cpp:11
time.h
CDnsSeedOpts::filter_whitelist
std::set< uint64_t > filter_whitelist
Definition: main.cpp:59
ArgsManager::GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:498
NODE_BLOOM
@ NODE_BLOOM
Definition: protocol.h:331
OptionsCategory::OPTIONS
@ OPTIONS
dns_opt_t::nRequests
uint64_t nRequests
Definition: dns.h:35
CNetAddr::IsValid
bool IsValid() const
Definition: netaddress.cpp:438
CAddrReport::uptime
double uptime[5]
Definition: db.h:68
CAddrDbStats::nTracked
int nTracked
Definition: db.h:238
SelectParams
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
Definition: chainparams.cpp:530
ArgsManager::ParseParameters
NODISCARD bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: system.cpp:317
G_TRANSLATION_FUN
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate string to current locale using Qt.
Definition: bitcoin-cli.cpp:34
CServiceResult::fGood
bool fGood
Definition: db.h:247
db
CAddrDb db
Definition: main.cpp:193
dnsserver
int dnsserver(dns_opt_t *opt)
Definition: dns.cpp:596
ThreadDumper
void * ThreadDumper(void *)
Definition: main.cpp:400
addr_t::data
union addr_t::@17 data
CAddrReport::clientVersion
int clientVersion
Definition: db.h:66
DEFAULT_WIPE_BAN
static const bool DEFAULT_WIPE_BAN
Definition: main.cpp:35
CServiceResult
Definition: db.h:244
system.h
SetProxy
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:773
CLIENT_VERSION
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:44
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
dns_opt_t::addr
const char * addr
Definition: dns.h:29
CAddress
A CService with information about it as peer.
Definition: protocol.h:421
LookupHost
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
Resolve a host string to its corresponding network addresses.
Definition: netbase.cpp:165
DEFAULT_NUM_DNS_THREADS
static const int DEFAULT_NUM_DNS_THREADS
Definition: main.cpp:34
DEFAULT_WIPE_IGNORE
static const bool DEFAULT_WIPE_IGNORE
Definition: main.cpp:36
ArgsManager
Definition: system.h:152
translation.h
CDnsThread
Definition: main.cpp:249
CDnsSeedOpts::ip_addr
std::string ip_addr
Definition: main.cpp:56
BCLog::Logger::m_print_to_console
bool m_print_to_console
Definition: logging.h:93
CAddrDbStats::nAvail
int nAvail
Definition: db.h:237
CDnsThread::dbQueries
std::atomic< uint64_t > dbQueries
Definition: main.cpp:262
gArgs
ArgsManager gArgs
Definition: system.cpp:75
GetDefaultPort
static uint16_t GetDefaultPort()
Definition: bitcoin.h:16
CAddrDb::banned
std::map< CService, int64_t > banned
Definition: db.h:301
NET_ONION
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:55
CDnsSeedOpts::CDnsSeedOpts
CDnsSeedOpts()
Definition: main.cpp:61
dns_opt_t
Definition: dns.h:24
CAddrDb::ResultMany
void ResultMany(const std::vector< CServiceResult > &ips)
Definition: db.h:424
CServiceResult::services
uint64_t services
Definition: db.h:246
CDnsSeedOpts::fWipeIgnore
bool fWipeIgnore
Definition: main.cpp:51
CDnsSeedOpts::ipv4_proxy
std::string ipv4_proxy
Definition: main.cpp:57
CServiceResult::ourLastSuccess
int64_t ourLastSuccess
Definition: db.h:252
logging.h
CAddrDb
Definition: db.h:264
CDnsThread::cacheHit
void cacheHit(uint64_t requestedFlags, bool force=false)
Definition: main.cpp:265
CSeederNode
Definition: bitcoin.h:33
LogInstance
BCLog::Logger & LogInstance()
Definition: logging.cpp:15
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:508
OptionsCategory::DEBUG_TEST
@ DEBUG_TEST
SER_DISK
@ SER_DISK
Definition: serialize.h:166
DEFAULT_TOR_PROXY
static const std::string DEFAULT_TOR_PROXY
Definition: main.cpp:40
CAddrDb::GetMany
void GetMany(std::vector< CServiceResult > &ips, int max, int &wait)
Definition: db.h:412
CDnsSeedOpts::ParseCommandLine
int ParseCommandLine(int argc, char **argv)
Definition: main.cpp:69
CAddrDbStats::nBanned
int nBanned
Definition: db.h:236
NET_IPV6
@ NET_IPV6
IPv6.
Definition: netaddress.h:52
CDnsSeedOpts::tor
std::string tor
Definition: main.cpp:55
DEFAULT_IPV6_PROXY
static const std::string DEFAULT_IPV6_PROXY
Definition: main.cpp:43
LookupNumeric
CService LookupNumeric(const std::string &name, int portDefault)
Resolve a service string with a numeric IP to its first corresponding service.
Definition: netbase.cpp:271
CDnsSeedOpts::SetupSeederArgs
void SetupSeederArgs(ArgsManager &argsman)
Definition: main.cpp:136
GetIPList
uint32_t GetIPList(void *thread, char *requestedHostname, addr_t *addr, uint32_t max, uint32_t ipv4, uint32_t ipv6)
Definition: main.cpp:327
dnsseeds.h
addr_t
Definition: dns.h:16
FormatFullVersion
std::string FormatFullVersion()
Definition: clientversion.cpp:58
CSeederNode::GetServices
uint64_t GetServices()
Definition: bitcoin.h:81
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
DEFAULT_HOST
static const std::string DEFAULT_HOST
Definition: main.cpp:39
dns_opt_t::datattl
int datattl
Definition: dns.h:26
dns.h
CDnsThread::FlagSpecificData::FlagSpecificData
FlagSpecificData()
Definition: main.cpp:256
CDnsThread::FlagSpecificData::cacheTime
time_t cacheTime
Definition: main.cpp:254
DEFAULT_NUM_THREADS
static const int DEFAULT_NUM_THREADS
Definition: main.cpp:32
CDnsSeedOpts::nDnsThreads
int nDnsThreads
Definition: main.cpp:49
CDnsThread::FlagSpecificData
Definition: main.cpp:251
CServiceResult::service
CService service
Definition: db.h:245
addr_t::v
int v
Definition: dns.h:17
CSeederNode::GetClientVersion
int GetClientVersion()
Definition: bitcoin.h:75
dns_opt_t::cb
uint32_t(* cb)(void *opt, char *requested_hostname, addr_t *addr, uint32_t max, uint32_t ipv4, uint32_t ipv6)
Definition: dns.h:32
CAddrDbStats::nGood
int nGood
Definition: db.h:240
dns_opt_t::ns
const char * ns
Definition: dns.h:30