Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
Show All 18 Lines | |||||
const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | ||||
static const int DEFAULT_NUM_THREADS = 96; | static const int DEFAULT_NUM_THREADS = 96; | ||||
static const int DEFAULT_PORT = 53; | static const int DEFAULT_PORT = 53; | ||||
static const int DEFAULT_NUM_DNS_THREADS = 4; | static const int DEFAULT_NUM_DNS_THREADS = 4; | ||||
static const bool DEFAULT_TESTNET = false; | static const bool DEFAULT_TESTNET = false; | ||||
static const bool DEFAULT_WIPE_BAN = false; | static const bool DEFAULT_WIPE_BAN = false; | ||||
static const bool DEFAULT_WIPE_IGNORE = false; | static const bool DEFAULT_WIPE_IGNORE = false; | ||||
static const char *DEFAULT_EMAIL = nullptr; | static const std::string DEFAULT_EMAIL = ""; | ||||
static const char *DEFAULT_NAMESERVER = nullptr; | static const std::string DEFAULT_NAMESERVER = ""; | ||||
static const char *DEFAULT_HOST = nullptr; | static const std::string DEFAULT_HOST = ""; | ||||
static const char *DEFAULT_TOR_PROXY = nullptr; | static const std::string DEFAULT_TOR_PROXY = ""; | ||||
static const char *DEFAULT_IPV4_PROXY = nullptr; | static const std::string DEFAULT_IPV4_PROXY = ""; | ||||
static const char *DEFAULT_IPV6_PROXY = nullptr; | static const std::string DEFAULT_IPV6_PROXY = ""; | ||||
class CDnsSeedOpts { | class CDnsSeedOpts { | ||||
public: | public: | ||||
int nThreads; | int nThreads; | ||||
int nPort; | int nPort; | ||||
int nDnsThreads; | int nDnsThreads; | ||||
int fUseTestNet; | int fUseTestNet; | ||||
int fWipeBan; | int fWipeBan; | ||||
int fWipeIgnore; | int fWipeIgnore; | ||||
const char *mbox; | std::string mbox; | ||||
const char *ns; | std::string ns; | ||||
const char *host; | std::string host; | ||||
const char *tor; | std::string tor; | ||||
const char *ipv4_proxy; | std::string ipv4_proxy; | ||||
const char *ipv6_proxy; | std::string ipv6_proxy; | ||||
std::set<uint64_t> filter_whitelist; | std::set<uint64_t> filter_whitelist; | ||||
CDnsSeedOpts() | CDnsSeedOpts() | ||||
: nThreads(DEFAULT_NUM_THREADS), nPort(DEFAULT_PORT), | : nThreads(DEFAULT_NUM_THREADS), nPort(DEFAULT_PORT), | ||||
nDnsThreads(DEFAULT_NUM_DNS_THREADS), fUseTestNet(DEFAULT_TESTNET), | nDnsThreads(DEFAULT_NUM_DNS_THREADS), fUseTestNet(DEFAULT_TESTNET), | ||||
fWipeBan(DEFAULT_WIPE_BAN), fWipeIgnore(DEFAULT_WIPE_IGNORE), | fWipeBan(DEFAULT_WIPE_BAN), fWipeIgnore(DEFAULT_WIPE_IGNORE), | ||||
mbox(DEFAULT_EMAIL), ns(DEFAULT_NAMESERVER), host(DEFAULT_HOST), | mbox(DEFAULT_EMAIL), ns(DEFAULT_NAMESERVER), host(DEFAULT_HOST), | ||||
tor(DEFAULT_TOR_PROXY), ipv4_proxy(DEFAULT_IPV4_PROXY), | tor(DEFAULT_TOR_PROXY), ipv4_proxy(DEFAULT_IPV4_PROXY), | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | void ParseCommandLine(int argc, char **argv) { | ||||
{0, 0, 0, 0}}; | {0, 0, 0, 0}}; | ||||
int option_index = 0; | int option_index = 0; | ||||
int c = | int c = | ||||
getopt_long(argc, argv, "h:n:m:t:p:d:o:i:k:w:", long_options, | getopt_long(argc, argv, "h:n:m:t:p:d:o:i:k:w:", long_options, | ||||
&option_index); | &option_index); | ||||
if (c == -1) break; | if (c == -1) break; | ||||
switch (c) { | switch (c) { | ||||
case 'h': { | case 'h': { | ||||
host = optarg; | host = std::string(optarg); | ||||
break; | break; | ||||
} | } | ||||
case 'm': { | case 'm': { | ||||
mbox = optarg; | mbox = std::string(optarg); | ||||
break; | break; | ||||
} | } | ||||
case 'n': { | case 'n': { | ||||
ns = optarg; | ns = std::string(optarg); | ||||
break; | break; | ||||
} | } | ||||
case 't': { | case 't': { | ||||
int n = strtol(optarg, nullptr, 10); | int n = strtol(optarg, nullptr, 10); | ||||
if (n > 0 && n < 1000) nThreads = n; | if (n > 0 && n < 1000) nThreads = n; | ||||
break; | break; | ||||
} | } | ||||
case 'd': { | case 'd': { | ||||
int n = strtol(optarg, nullptr, 10); | int n = strtol(optarg, nullptr, 10); | ||||
if (n > 0 && n < 1000) nDnsThreads = n; | if (n > 0 && n < 1000) nDnsThreads = n; | ||||
break; | break; | ||||
} | } | ||||
case 'p': { | case 'p': { | ||||
int p = strtol(optarg, nullptr, 10); | int p = strtol(optarg, nullptr, 10); | ||||
if (p > 0 && p < 65536) nPort = p; | if (p > 0 && p < 65536) nPort = p; | ||||
break; | break; | ||||
} | } | ||||
case 'o': { | case 'o': { | ||||
tor = optarg; | tor = std::string(optarg); | ||||
break; | break; | ||||
} | } | ||||
case 'i': { | case 'i': { | ||||
ipv4_proxy = optarg; | ipv4_proxy = std::string(optarg); | ||||
break; | break; | ||||
} | } | ||||
case 'k': { | case 'k': { | ||||
ipv6_proxy = optarg; | ipv6_proxy = std::string(optarg); | ||||
break; | break; | ||||
} | } | ||||
case 'w': { | case 'w': { | ||||
char *ptr = optarg; | char *ptr = optarg; | ||||
while (*ptr != 0) { | while (*ptr != 0) { | ||||
unsigned long l = strtoul(ptr, &ptr, 0); | unsigned long l = strtoul(ptr, &ptr, 0); | ||||
if (*ptr == ',') { | if (*ptr == ',') { | ||||
Show All 13 Lines | void ParseCommandLine(int argc, char **argv) { | ||||
} | } | ||||
} | } | ||||
if (filter_whitelist.empty()) { | if (filter_whitelist.empty()) { | ||||
filter_whitelist.insert(NODE_NETWORK); | filter_whitelist.insert(NODE_NETWORK); | ||||
filter_whitelist.insert(NODE_NETWORK | NODE_BLOOM); | filter_whitelist.insert(NODE_NETWORK | NODE_BLOOM); | ||||
filter_whitelist.insert(NODE_NETWORK | NODE_XTHIN); | filter_whitelist.insert(NODE_NETWORK | NODE_XTHIN); | ||||
filter_whitelist.insert(NODE_NETWORK | NODE_BLOOM | NODE_XTHIN); | filter_whitelist.insert(NODE_NETWORK | NODE_BLOOM | NODE_XTHIN); | ||||
} | } | ||||
if (host != nullptr && ns == nullptr) showHelp = true; | if (!host.empty() && ns.empty()) showHelp = true; | ||||
if (showHelp) fprintf(stderr, help, argv[0]); | if (showHelp) fprintf(stderr, help, argv[0]); | ||||
} | } | ||||
}; | }; | ||||
extern "C" { | extern "C" { | ||||
#include <seeder/dns.h> | #include <seeder/dns.h> | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | void cacheHit(uint64_t requestedFlags, bool force = false) { | ||||
} | } | ||||
} | } | ||||
thisflag.cacheHits = 0; | thisflag.cacheHits = 0; | ||||
thisflag.cacheTime = now; | thisflag.cacheTime = now; | ||||
} | } | ||||
} | } | ||||
CDnsThread(CDnsSeedOpts *opts, int idIn) : id(idIn) { | CDnsThread(CDnsSeedOpts *opts, int idIn) : id(idIn) { | ||||
dns_opt.host = opts->host; | dns_opt.host = opts->host.c_str(); | ||||
dns_opt.ns = opts->ns; | dns_opt.ns = opts->ns.c_str(); | ||||
dns_opt.mbox = opts->mbox; | dns_opt.mbox = opts->mbox.c_str(); | ||||
dns_opt.datattl = 3600; | dns_opt.datattl = 3600; | ||||
dns_opt.nsttl = 40000; | dns_opt.nsttl = 40000; | ||||
dns_opt.cb = GetIPList; | dns_opt.cb = GetIPList; | ||||
dns_opt.port = opts->nPort; | dns_opt.port = opts->nPort; | ||||
dns_opt.nRequests = 0; | dns_opt.nRequests = 0; | ||||
dbQueries = 0; | dbQueries = 0; | ||||
perflag.clear(); | perflag.clear(); | ||||
filterWhitelist = opts->filter_whitelist; | filterWhitelist = opts->filter_whitelist; | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | int main(int argc, char **argv) { | ||||
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()) { | ||||
fprintf(stdout, ","); | fprintf(stdout, ","); | ||||
} | } | ||||
fprintf(stdout, "0x%lx", (unsigned long)*it); | fprintf(stdout, "0x%lx", (unsigned long)*it); | ||||
} | } | ||||
fprintf(stdout, "\n"); | fprintf(stdout, "\n"); | ||||
if (opts.tor) { | if (!opts.tor.empty()) { | ||||
CService service(LookupNumeric(opts.tor, 9050)); | CService service(LookupNumeric(opts.tor.c_str(), 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
fprintf(stdout, "Using Tor proxy at %s\n", | fprintf(stdout, "Using Tor proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | service.ToStringIPPort().c_str()); | ||||
SetProxy(NET_ONION, proxyType(service)); | SetProxy(NET_ONION, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
if (opts.ipv4_proxy) { | if (!opts.ipv4_proxy.empty()) { | ||||
CService service(LookupNumeric(opts.ipv4_proxy, 9050)); | CService service(LookupNumeric(opts.ipv4_proxy.c_str(), 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
fprintf(stdout, "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.empty()) { | ||||
CService service(LookupNumeric(opts.ipv6_proxy, 9050)); | CService service(LookupNumeric(opts.ipv6_proxy.c_str(), 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
fprintf(stdout, "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) { | ||||
fprintf(stdout, "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.empty()) { | ||||
fprintf(stdout, "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.empty()) { | ||||
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.empty()) { | ||||
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) { | ||||
fprintf(stdout, "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) { | if (opts.fWipeBan) { | ||||
db.banned.clear(); | db.banned.clear(); | ||||
fprintf(stdout, "Ban list wiped..."); | fprintf(stdout, "Ban list wiped..."); | ||||
} | } | ||||
if (opts.fWipeIgnore) { | if (opts.fWipeIgnore) { | ||||
db.ResetIgnores(); | db.ResetIgnores(); | ||||
fprintf(stdout, "Ignore list wiped..."); | fprintf(stdout, "Ignore list wiped..."); | ||||
} | } | ||||
fprintf(stdout, "done\n"); | fprintf(stdout, "done\n"); | ||||
} | } | ||||
pthread_t threadDns, threadSeed, threadDump, threadStats; | pthread_t threadDns, threadSeed, threadDump, threadStats; | ||||
if (fDNS) { | if (fDNS) { | ||||
fprintf(stdout, "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.c_str(), opts.ns.c_str(), | ||||
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]); | ||||
fprintf(stdout, "."); | fprintf(stdout, "."); | ||||
Sleep(20); | Sleep(20); | ||||
} | } | ||||
fprintf(stdout, "done\n"); | fprintf(stdout, "done\n"); | ||||
Show All 20 Lines |