Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | CDnsSeedOpts() | ||||
ns(DEFAULT_NAMESERVER), host(DEFAULT_HOST), tor(DEFAULT_TOR_PROXY), | ns(DEFAULT_NAMESERVER), host(DEFAULT_HOST), tor(DEFAULT_TOR_PROXY), | ||||
ipv4_proxy(DEFAULT_IPV4_PROXY), ipv6_proxy(DEFAULT_IPV6_PROXY) {} | ipv4_proxy(DEFAULT_IPV4_PROXY), ipv6_proxy(DEFAULT_IPV6_PROXY) {} | ||||
int ParseCommandLine(int argc, char **argv) { | int ParseCommandLine(int argc, char **argv) { | ||||
SetupSeederArgs(); | SetupSeederArgs(); | ||||
std::string error; | std::string error; | ||||
if (!gArgs.ParseParameters(argc, argv, error)) { | if (!gArgs.ParseParameters(argc, argv, error)) { | ||||
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", | tfm::format(std::cerr, "Error parsing command line arguments: %s\n", | ||||
error.c_str()); | error); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | ||||
std::string strUsage = | std::string strUsage = | ||||
PACKAGE_NAME " Seeder " + FormatFullVersion() + "\n"; | PACKAGE_NAME " Seeder " + FormatFullVersion() + "\n"; | ||||
if (HelpRequested(gArgs)) { | if (HelpRequested(gArgs)) { | ||||
strUsage += | strUsage += | ||||
"\nUsage: bitcoin-seeder -host=<host> -ns=<ns> " | "\nUsage: bitcoin-seeder -host=<host> -ns=<ns> " | ||||
"[-mbox=<mbox>] [-threads=<threads>] [-port=<port>]\n\n" + | "[-mbox=<mbox>] [-threads=<threads>] [-port=<port>]\n\n" + | ||||
gArgs.GetHelpMessage(); | gArgs.GetHelpMessage(); | ||||
} | } | ||||
tfm::format(std::cout, "%s", strUsage.c_str()); | tfm::format(std::cout, "%s", strUsage); | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
} | } | ||||
nThreads = gArgs.GetArg("-threads", DEFAULT_NUM_THREADS); | nThreads = gArgs.GetArg("-threads", DEFAULT_NUM_THREADS); | ||||
nPort = gArgs.GetArg("-port", DEFAULT_PORT); | nPort = gArgs.GetArg("-port", DEFAULT_PORT); | ||||
nDnsThreads = gArgs.GetArg("-dnsthreads", DEFAULT_NUM_DNS_THREADS); | nDnsThreads = gArgs.GetArg("-dnsthreads", DEFAULT_NUM_DNS_THREADS); | ||||
fWipeBan = gArgs.GetBoolArg("-wipeban", DEFAULT_WIPE_BAN); | fWipeBan = gArgs.GetBoolArg("-wipeban", DEFAULT_WIPE_BAN); | ||||
fWipeIgnore = gArgs.GetBoolArg("-wipeignore", DEFAULT_WIPE_IGNORE); | fWipeIgnore = gArgs.GetBoolArg("-wipeignore", DEFAULT_WIPE_IGNORE); | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | do { | ||||
if (!ret) { | if (!ret) { | ||||
res.nBanTime = node.GetBan(); | res.nBanTime = node.GetBan(); | ||||
} else { | } else { | ||||
res.nBanTime = 0; | res.nBanTime = 0; | ||||
} | } | ||||
res.nClientV = node.GetClientVersion(); | res.nClientV = node.GetClientVersion(); | ||||
res.strClientV = node.GetClientSubVersion(); | res.strClientV = node.GetClientSubVersion(); | ||||
res.nHeight = node.GetStartingHeight(); | res.nHeight = node.GetStartingHeight(); | ||||
// tfm::format(std::cout, "%s: %s!!!\n", cip.ToString().c_str(), | // tfm::format(std::cout, "%s: %s!!!\n", cip.ToString(), | ||||
// ret ? "GOOD" : "BAD"); | // ret ? "GOOD" : "BAD"); | ||||
res.fGood = ret; | res.fGood = ret; | ||||
} catch (std::ios_base::failure &e) { | } catch (std::ios_base::failure &e) { | ||||
res.nBanTime = 0; | res.nBanTime = 0; | ||||
res.fGood = false; | res.fGood = false; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | do { | ||||
"%%(30d) blocks svcs version\n"); | "%%(30d) blocks svcs version\n"); | ||||
double stat[5] = {0, 0, 0, 0, 0}; | double stat[5] = {0, 0, 0, 0, 0}; | ||||
for (CAddrReport rep : v) { | for (CAddrReport rep : v) { | ||||
tfm::format( | tfm::format( | ||||
d, | d, | ||||
"%-47s %4d %11" PRId64 | "%-47s %4d %11" PRId64 | ||||
" %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6i %08" PRIx64 | " %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6i %08" PRIx64 | ||||
" %5i \"%s\"\n", | " %5i \"%s\"\n", | ||||
rep.ip.ToString().c_str(), (int)rep.fGood, rep.lastSuccess, | rep.ip.ToString(), (int)rep.fGood, rep.lastSuccess, | ||||
100.0 * rep.uptime[0], 100.0 * rep.uptime[1], | 100.0 * rep.uptime[0], 100.0 * rep.uptime[1], | ||||
100.0 * rep.uptime[2], 100.0 * rep.uptime[3], | 100.0 * rep.uptime[2], 100.0 * rep.uptime[3], | ||||
100.0 * rep.uptime[4], rep.blocks, rep.services, | 100.0 * rep.uptime[4], rep.blocks, rep.services, | ||||
rep.clientVersion, rep.clientSubVersion.c_str()); | rep.clientVersion, rep.clientSubVersion); | ||||
stat[0] += rep.uptime[0]; | stat[0] += rep.uptime[0]; | ||||
stat[1] += rep.uptime[1]; | stat[1] += rep.uptime[1]; | ||||
stat[2] += rep.uptime[2]; | stat[2] += rep.uptime[2]; | ||||
stat[3] += rep.uptime[3]; | stat[3] += rep.uptime[3]; | ||||
stat[4] += rep.uptime[4]; | stat[4] += rep.uptime[4]; | ||||
} | } | ||||
fsbridge::ofstream ff{"dnsstats.log", std::ios_base::app}; | fsbridge::ofstream ff{"dnsstats.log", std::ios_base::app}; | ||||
tfm::format(ff, "%llu %g %g %g %g %g\n", | tfm::format(ff, "%llu %g %g %g %g %g\n", | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | for (std::set<uint64_t>::const_iterator it = opts.filter_whitelist.begin(); | ||||
} | } | ||||
tfm::format(std::cout, "0x%lx", (unsigned long)*it); | tfm::format(std::cout, "0x%lx", (unsigned long)*it); | ||||
} | } | ||||
tfm::format(std::cout, "\n"); | tfm::format(std::cout, "\n"); | ||||
if (!opts.tor.empty()) { | if (!opts.tor.empty()) { | ||||
CService service(LookupNumeric(opts.tor.c_str(), 9050)); | CService service(LookupNumeric(opts.tor.c_str(), 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
tfm::format(std::cout, "Using Tor proxy at %s\n", | tfm::format(std::cout, "Using Tor proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | service.ToStringIPPort()); | ||||
SetProxy(NET_ONION, proxyType(service)); | SetProxy(NET_ONION, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
if (!opts.ipv4_proxy.empty()) { | if (!opts.ipv4_proxy.empty()) { | ||||
CService service(LookupNumeric(opts.ipv4_proxy.c_str(), 9050)); | CService service(LookupNumeric(opts.ipv4_proxy.c_str(), 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
tfm::format(std::cout, "Using IPv4 proxy at %s\n", | tfm::format(std::cout, "Using IPv4 proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | service.ToStringIPPort()); | ||||
SetProxy(NET_IPV4, proxyType(service)); | SetProxy(NET_IPV4, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
if (!opts.ipv6_proxy.empty()) { | if (!opts.ipv6_proxy.empty()) { | ||||
CService service(LookupNumeric(opts.ipv6_proxy.c_str(), 9050)); | CService service(LookupNumeric(opts.ipv6_proxy.c_str(), 9050)); | ||||
if (service.IsValid()) { | if (service.IsValid()) { | ||||
tfm::format(std::cout, "Using IPv6 proxy at %s\n", | tfm::format(std::cout, "Using IPv6 proxy at %s\n", | ||||
service.ToStringIPPort().c_str()); | service.ToStringIPPort()); | ||||
SetProxy(NET_IPV6, proxyType(service)); | SetProxy(NET_IPV6, proxyType(service)); | ||||
} | } | ||||
} | } | ||||
bool fDNS = true; | bool fDNS = true; | ||||
tfm::format(std::cout, "Using %s.\n", gArgs.GetChainName().c_str()); | tfm::format(std::cout, "Using %s.\n", gArgs.GetChainName()); | ||||
netMagic = Params().NetMagic(); | netMagic = Params().NetMagic(); | ||||
if (opts.ns.empty()) { | if (opts.ns.empty()) { | ||||
tfm::format(std::cout, "No nameserver set. Not starting DNS server.\n"); | tfm::format(std::cout, "No nameserver set. Not starting DNS server.\n"); | ||||
fDNS = false; | fDNS = false; | ||||
} | } | ||||
if (fDNS && opts.host.empty()) { | if (fDNS && opts.host.empty()) { | ||||
tfm::format(std::cerr, "No hostname set. Please use -h.\n"); | tfm::format(std::cerr, "No hostname set. Please use -h.\n"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
Show All 14 Lines | if (f) { | ||||
if (opts.fWipeIgnore) { | if (opts.fWipeIgnore) { | ||||
db.ResetIgnores(); | db.ResetIgnores(); | ||||
tfm::format(std::cout, "Ignore list wiped..."); | tfm::format(std::cout, "Ignore list wiped..."); | ||||
} | } | ||||
tfm::format(std::cout, "done\n"); | tfm::format(std::cout, "done\n"); | ||||
} | } | ||||
pthread_t threadDns, threadSeed, threadDump, threadStats; | pthread_t threadDns, threadSeed, threadDump, threadStats; | ||||
if (fDNS) { | if (fDNS) { | ||||
tfm::format( | tfm::format(std::cout, | ||||
std::cout, "Starting %i DNS threads for %s on %s (port %i)...", | "Starting %i DNS threads for %s on %s (port %i)...", | ||||
opts.nDnsThreads, opts.host.c_str(), opts.ns.c_str(), 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]); | ||||
tfm::format(std::cout, "."); | tfm::format(std::cout, "."); | ||||
Sleep(20); | Sleep(20); | ||||
} | } | ||||
tfm::format(std::cout, "done\n"); | tfm::format(std::cout, "done\n"); | ||||
Show All 20 Lines |