Bitcoin ABC  0.24.10
P2P Digital Currency
options.cpp
Go to the documentation of this file.
1 // Copyright (c) 2022 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 <seeder/options.h>
6 
7 #include <chainparams.h>
8 #include <clientversion.h>
9 #include <util/system.h>
10 
11 #include <string>
12 
13 namespace seeder {
14 
15 int CDnsSeedOpts::ParseCommandLine(int argc, const char **argv) {
16  assert(argsManager);
17 
18  std::string error;
19  if (!argsManager->ParseParameters(argc, argv, error)) {
20  tfm::format(std::cerr, "Error parsing command line arguments: %s\n",
21  error);
22  return EXIT_FAILURE;
23  }
24  if (HelpRequested(*argsManager) || argsManager->IsArgSet("-version")) {
25  std::string strUsage =
26  PACKAGE_NAME " Seeder " + FormatFullVersion() + "\n";
27  if (HelpRequested(*argsManager)) {
28  strUsage +=
29  "\nUsage: bitcoin-seeder -host=<host> -ns=<ns> "
30  "[-mbox=<mbox>] [-threads=<threads>] [-port=<port>]\n\n" +
32  }
33 
34  tfm::format(std::cout, "%s", strUsage);
35  return EXIT_SUCCESS;
36  }
37 
39  nPort = argsManager->GetArg("-port", DEFAULT_PORT);
43  mbox = argsManager->GetArg("-mbox", DEFAULT_EMAIL);
45  host = argsManager->GetArg("-host", DEFAULT_HOST);
51 
52  // Both IPv4 and IPv6 addresses are valid, but the listening address is
53  // treated as IPv6 internally
54  if (ip_addr.find(':') == std::string::npos) {
55  ip_addr.insert(0, "::FFFF:");
56  }
57 
58  if (argsManager->IsArgSet("-filter")) {
59  // Parse whitelist additions
60  std::string flagString = argsManager->GetArg("-filter", "");
61  size_t flagstartpos = 0;
62  while (flagstartpos < flagString.size()) {
63  size_t flagendpos = flagString.find_first_of(',', flagstartpos);
64  uint64_t flag = atoi64(
65  flagString.substr(flagstartpos, (flagendpos - flagstartpos)));
66  filter_whitelist.insert(flag);
67  if (flagendpos == std::string::npos) {
68  break;
69  }
70  flagstartpos = flagendpos + 1;
71  }
72  }
73  if (filter_whitelist.empty()) {
78  }
79  return CONTINUE_EXECUTION;
80 }
81 
83  assert(argsManager);
86  "-help-debug", "Show all debugging options (usage: --help -help-debug)",
88 
90 
91  argsManager->AddArg("-version", "Print version and exit",
93  argsManager->AddArg("-host=<host>", "Hostname of the DNS seed",
95  argsManager->AddArg("-ns=<ns>", "Hostname of the nameserver",
97  argsManager->AddArg("-mbox=<mbox>",
98  "E-Mail address reported in SOA records",
101  "-threads=<threads>",
102  strprintf("Number of crawlers to run in parallel (default: %d)",
105  argsManager->AddArg("-dnsthreads=<threads>",
106  strprintf("Number of DNS server threads (default: %d)",
109  argsManager->AddArg("-address=<address>",
110  strprintf("Address to listen on (default: '%s')",
114  "-port=<port>",
115  strprintf("UDP port to listen on (default: %d)", DEFAULT_PORT),
117  argsManager->AddArg("-onion=<ip:port>", "Tor proxy IP/Port",
119  argsManager->AddArg("-overridednsseed",
120  "If set, only use the specified DNS seed when "
121  "querying for peer addresses via DNS lookup->",
123  argsManager->AddArg("-proxyipv4=<ip:port>", "IPV4 SOCKS5 proxy IP/Port",
125  argsManager->AddArg("-proxyipv6=<ip:port>", "IPV6 SOCKS5 proxy IP/Port",
127  argsManager->AddArg("-filter=<f1,f2,...>",
128  "Allow these flag combinations as filters",
130  argsManager->AddArg("-wipeban", "Wipe list of banned nodes",
132  argsManager->AddArg("-wipeignore", "Wipe list of ignored nodes",
134 }
135 
136 } // namespace seeder
atoi64
int64_t atoi64(const std::string &str)
Definition: strencodings.cpp:469
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:601
seeder::CDnsSeedOpts::tor
std::string tor
Definition: options.h:41
seeder::DEFAULT_WIPE_BAN
static const bool DEFAULT_WIPE_BAN
Definition: options.h:20
seeder::CDnsSeedOpts::nPort
int nPort
Definition: options.h:34
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
seeder::CDnsSeedOpts::ParseCommandLine
int ParseCommandLine(int argc, const char **argv)
Definition: options.cpp:15
seeder::CDnsSeedOpts::SetupSeederArgs
void SetupSeederArgs()
Definition: options.cpp:82
SetupHelpOptions
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
Definition: system.cpp:760
ArgsManager::ALLOW_ANY
@ ALLOW_ANY
Definition: system.h:155
seeder::CDnsSeedOpts::fWipeBan
bool fWipeBan
Definition: options.h:36
ArgsManager::GetHelpMessage
std::string GetHelpMessage() const
Get the help string.
Definition: system.cpp:682
seeder::DEFAULT_LISTEN_ADDRESS
static const std::string DEFAULT_LISTEN_ADDRESS
Definition: options.h:26
seeder::DEFAULT_TOR_PROXY
static const std::string DEFAULT_TOR_PROXY
Definition: options.h:25
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:1043
ArgsManager::IsArgSet
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:482
seeder::DEFAULT_NUM_THREADS
static const int DEFAULT_NUM_THREADS
Definition: options.h:17
clientversion.h
OptionsCategory::CONNECTION
@ CONNECTION
options.h
NODE_NETWORK_LIMITED
@ NODE_NETWORK_LIMITED
Definition: protocol.h:344
seeder::DEFAULT_IPV6_PROXY
static const std::string DEFAULT_IPV6_PROXY
Definition: options.h:28
NODE_NETWORK
@ NODE_NETWORK
Definition: protocol.h:321
seeder::CDnsSeedOpts::fWipeIgnore
bool fWipeIgnore
Definition: options.h:37
chainparams.h
seeder::DEFAULT_PORT
static const int DEFAULT_PORT
Definition: options.h:18
seeder::CDnsSeedOpts::argsManager
ArgsManager * argsManager
Definition: options.h:32
seeder::DEFAULT_EMAIL
static const std::string DEFAULT_EMAIL
Definition: options.h:22
seeder::DEFAULT_NUM_DNS_THREADS
static const int DEFAULT_NUM_DNS_THREADS
Definition: options.h:19
HelpRequested
bool HelpRequested(const ArgsManager &args)
Definition: system.cpp:755
seeder::CDnsSeedOpts::ip_addr
std::string ip_addr
Definition: options.h:42
seeder::DEFAULT_HOST
static const std::string DEFAULT_HOST
Definition: options.h:24
seeder::CDnsSeedOpts::filter_whitelist
std::set< uint64_t > filter_whitelist
Definition: options.h:45
seeder::DEFAULT_NAMESERVER
static const std::string DEFAULT_NAMESERVER
Definition: options.h:23
ArgsManager::AddArg
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:649
ArgsManager::GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:582
NODE_BLOOM
@ NODE_BLOOM
Definition: protocol.h:331
OptionsCategory::OPTIONS
@ OPTIONS
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
bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: system.cpp:330
seeder::DEFAULT_IPV4_PROXY
static const std::string DEFAULT_IPV4_PROXY
Definition: options.h:27
seeder::CDnsSeedOpts::ns
std::string ns
Definition: options.h:39
seeder::CDnsSeedOpts::ipv6_proxy
std::string ipv6_proxy
Definition: options.h:44
seeder::CONTINUE_EXECUTION
static const int CONTINUE_EXECUTION
Definition: options.h:15
seeder::CDnsSeedOpts::nDnsThreads
int nDnsThreads
Definition: options.h:35
system.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
seeder::CDnsSeedOpts::host
std::string host
Definition: options.h:40
seeder::CDnsSeedOpts::ipv4_proxy
std::string ipv4_proxy
Definition: options.h:43
OptionsCategory::DEBUG_TEST
@ DEBUG_TEST
seeder::CDnsSeedOpts::nThreads
int nThreads
Definition: options.h:33
FormatFullVersion
std::string FormatFullVersion()
Definition: clientversion.cpp:58
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
seeder
Definition: options.cpp:13
seeder::CDnsSeedOpts::mbox
std::string mbox
Definition: options.h:38
seeder::DEFAULT_WIPE_IGNORE
static const bool DEFAULT_WIPE_IGNORE
Definition: options.h:21