Bitcoin ABC 0.30.5
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 <common/args.h>
10
11#include <string>
12
13namespace seeder {
14
15int CDnsSeedOpts::ParseCommandLine(int argc, const char **argv) {
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";
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
38 dumpInterval = std::chrono::seconds(
40 if (dumpInterval.count() <= 0) {
42 std::cerr,
43 "Error: -dumpinterval argument expects only positive integers\n");
44 return EXIT_FAILURE;
45 }
46
48 if (nThreads <= 0) {
50 std::cerr,
51 "Error: -threads argument expects only positive integers\n");
52 return EXIT_FAILURE;
53 }
54
56 if (nPort < 0 || nPort > 65535) {
57 tfm::format(std::cerr, "Error: -port argument expects only positive "
58 "integers in the range 0 - 65535\n");
59 return EXIT_FAILURE;
60 }
61
64 if (nDnsThreads <= 0) {
66 std::cerr,
67 "Error: -dnsthreads argument expects only positive integers\n");
68 return EXIT_FAILURE;
69 }
70
81
82 // Both IPv4 and IPv6 addresses are valid, but the listening address is
83 // treated as IPv6 internally
84 if (ip_addr.find(':') == std::string::npos) {
85 ip_addr.insert(0, "::FFFF:");
86 }
87
88 if (argsManager->IsArgSet("-filter")) {
89 // Parse whitelist additions
90 std::string flagString = argsManager->GetArg("-filter", "");
91 size_t flagstartpos = 0;
92 while (flagstartpos < flagString.size()) {
93 size_t flagendpos = flagString.find_first_of(',', flagstartpos);
94 uint64_t flag = atoi64(
95 flagString.substr(flagstartpos, (flagendpos - flagstartpos)));
96 filter_whitelist.insert(flag);
97 if (flagendpos == std::string::npos) {
98 break;
99 }
100 flagstartpos = flagendpos + 1;
101 }
102 }
103 if (filter_whitelist.empty()) {
108 }
109 return CONTINUE_EXECUTION;
110}
111
116 "-help-debug", "Show all debugging options (usage: --help -help-debug)",
118
120
121 argsManager->AddArg("-version", "Print version and exit",
123 argsManager->AddArg("-host=<host>", "Hostname of the DNS seed",
125 argsManager->AddArg("-ns=<ns>", "Hostname of the nameserver",
127 argsManager->AddArg("-mbox=<mbox>",
128 "E-Mail address reported in SOA records",
131 "-dumpinterval=<seconds>",
132 strprintf("Number of seconds between each database dump (default: %d)",
136 "-threads=<threads>",
137 strprintf("Number of crawlers to run in parallel (default: %d)",
140 argsManager->AddArg("-dnsthreads=<threads>",
141 strprintf("Number of DNS server threads (default: %d)",
144 argsManager->AddArg("-address=<address>",
145 strprintf("Address to listen on (default: '%s')",
149 "-port=<port>",
150 strprintf("UDP port to listen on (default: %d)", DEFAULT_PORT),
152 argsManager->AddArg("-onion=<ip:port>", "Tor proxy IP/Port",
154 argsManager->AddArg("-overridednsseed",
155 "If set, only use the specified DNS seed when "
156 "querying for peer addresses via DNS lookup->",
158 argsManager->AddArg("-proxyipv4=<ip:port>", "IPV4 SOCKS5 proxy IP/Port",
160 argsManager->AddArg("-proxyipv6=<ip:port>", "IPV6 SOCKS5 proxy IP/Port",
162 argsManager->AddArg("-filter=<f1,f2,...>",
163 "Allow these flag combinations as filters",
165 argsManager->AddArg("-wipeban", "Wipe list of banned nodes",
167 argsManager->AddArg("-wipeignore", "Wipe list of ignored nodes",
169}
170
171} // namespace seeder
bool HelpRequested(const ArgsManager &args)
Definition: args.cpp:732
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
Definition: args.cpp:737
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
Definition: chainparams.cpp:51
void SetupChainParamsBaseOptions(ArgsManager &argsman)
Set the arguments for chainparams.
@ ALLOW_ANY
Definition: args.h:103
bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: args.cpp:201
std::string GetHelpMessage() const
Get the help string.
Definition: args.cpp:653
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: args.cpp:381
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:526
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:494
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:556
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: args.cpp:620
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Definition: args.cpp:793
std::string ip_addr
Definition: options.h:45
std::chrono::seconds dumpInterval
Definition: options.h:35
std::string tor
Definition: options.h:44
std::string ipv4_proxy
Definition: options.h:46
std::string ns
Definition: options.h:42
int ParseCommandLine(int argc, const char **argv)
Definition: options.cpp:15
std::string host
Definition: options.h:43
std::string mbox
Definition: options.h:41
std::set< uint64_t > filter_whitelist
Definition: options.h:48
ArgsManager * argsManager
Definition: options.h:34
std::string ipv6_proxy
Definition: options.h:47
std::string FormatFullVersion()
bool error(const char *fmt, const Args &...args)
Definition: logging.h:226
static const bool DEFAULT_WIPE_BAN
Definition: options.h:22
static const int CONTINUE_EXECUTION
Definition: options.h:16
static const std::string DEFAULT_IPV4_PROXY
Definition: options.h:29
static const int DEFAULT_NUM_DNS_THREADS
Definition: options.h:21
static const std::string DEFAULT_IPV6_PROXY
Definition: options.h:30
static const int DEFAULT_DUMP_INTERVAL_SECONDS
Definition: options.h:18
static const std::string DEFAULT_HOST
Definition: options.h:26
static const std::string DEFAULT_LISTEN_ADDRESS
Definition: options.h:28
static const bool DEFAULT_WIPE_IGNORE
Definition: options.h:23
static const int DEFAULT_NUM_THREADS
Definition: options.h:19
static const std::string DEFAULT_EMAIL
Definition: options.h:24
static const std::string DEFAULT_TOR_PROXY
Definition: options.h:27
static const int DEFAULT_PORT
Definition: options.h:20
static const std::string DEFAULT_NAMESERVER
Definition: options.h:25
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:1112
@ NODE_NETWORK_LIMITED
Definition: protocol.h:365
@ NODE_BLOOM
Definition: protocol.h:352
@ NODE_NETWORK
Definition: protocol.h:342
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
int64_t atoi64(const std::string &str)
assert(!tx.IsCoinBase())