Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
Show First 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | void SetupSeederArgs() { | ||||
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | ||||
gArgs.AddArg("-help-debug", | gArgs.AddArg("-help-debug", | ||||
"Show all debugging options (usage: --help -help-debug)", | "Show all debugging options (usage: --help -help-debug)", | ||||
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); | ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); | ||||
gArgs.AddArg("-seederdir=<dir>", | gArgs.AddArg("-seederdir=<dir>", | ||||
"Specify directory to hold the subdirectory for files the " | "Specify directory to hold the subdirectory for files the " | ||||
"seeder writes to and reads from (default: ~/.bitcoin/)", | "seeder writes to and reads from (default: ~/.bitcoin/)", | ||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||||
gArgs.AddArg("-printtoconsole", | |||||
"Send trace/debug info to console (default: 1)", | |||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | |||||
gArgs.AddArg( | |||||
"-logtofile", | |||||
"Write trace/debug info to seederdebug.log file. This option does " | |||||
"not affect dnsseed.dat, dnsseed.dump, or dnsstat.log (default: 0)", | |||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | |||||
SetupChainParamsBaseOptions(); | SetupChainParamsBaseOptions(); | ||||
gArgs.AddArg("-help", "", ArgsManager::ALLOW_ANY, | gArgs.AddArg("-help", "", ArgsManager::ALLOW_ANY, | ||||
OptionsCategory::HIDDEN); | OptionsCategory::HIDDEN); | ||||
gArgs.AddArg("-h", "", ArgsManager::ALLOW_ANY, OptionsCategory::HIDDEN); | gArgs.AddArg("-h", "", ArgsManager::ALLOW_ANY, OptionsCategory::HIDDEN); | ||||
} | } | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | do { | ||||
} | } | ||||
} | } | ||||
Sleep(1800000); | Sleep(1800000); | ||||
} while (1); | } while (1); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||||
// The logger dump everything on the console by default. | |||||
LogInstance().m_print_to_console = true; | |||||
signal(SIGPIPE, SIG_IGN); | signal(SIGPIPE, SIG_IGN); | ||||
setbuf(stdout, nullptr); | setbuf(stdout, nullptr); | ||||
CDnsSeedOpts opts; | CDnsSeedOpts opts; | ||||
int parseResults = opts.ParseCommandLine(argc, argv); | int parseResults = opts.ParseCommandLine(argc, argv); | ||||
if (parseResults != CONTINUE_EXECUTION) { | if (parseResults != CONTINUE_EXECUTION) { | ||||
return parseResults; | return parseResults; | ||||
} | } | ||||
tfm::format(std::cout, "Supporting whitelisted filters: "); | // Set up logger | ||||
BCLog::Logger &logger = LogInstance(); | |||||
logger.m_print_to_console = gArgs.GetBoolArg("-printtoconsole", true); | |||||
logger.m_print_to_file = gArgs.GetBoolArg("-logtofile", false); | |||||
logger.m_file_path = | |||||
AbsPathForConfigVal(GetSeederDir() / "seederdebug.log"); | |||||
logger.m_log_timestamps = DEFAULT_LOGTIMESTAMPS; | |||||
logger.m_log_time_micros = DEFAULT_LOGTIMEMICROS; | |||||
logger.m_log_threadnames = DEFAULT_LOGTHREADNAMES; | |||||
if (!logger.StartLogging()) { | |||||
tfm::format(std::cout, "Could not open debug log file %s\n", | |||||
logger.m_file_path.string()); | |||||
tfm::format(std::cout, "Logging only to console\n"); | |||||
logger.m_print_to_file = false; | |||||
} | |||||
if (!logger.m_log_timestamps) { | |||||
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime())); | |||||
} | |||||
LogPrintf("%s Seeder version %s\n", PACKAGE_NAME, FormatFullVersion()); | |||||
LogPrintfToBeContinued("Supporting whitelisted filters: "); | |||||
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()) { | ||||
tfm::format(std::cout, ","); | LogPrintfToBeContinued(","); | ||||
} | } | ||||
tfm::format(std::cout, "0x%lx", (unsigned long)*it); | LogPrintfToBeContinued("0x%lx", (unsigned long)*it); | ||||
} | } | ||||
tfm::format(std::cout, "\n"); | LogPrintf("\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", | LogPrintf("Using Tor proxy at %s\n", service.ToStringIPPort()); | ||||
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", | LogPrintf("Using IPv4 proxy at %s\n", service.ToStringIPPort()); | ||||
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", | LogPrintf("Using IPv6 proxy at %s\n", service.ToStringIPPort()); | ||||
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()); | 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"); | LogPrintf("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"); | LogPrintf("No hostname set. Please use -h.\n"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
if (fDNS && opts.mbox.empty()) { | if (fDNS && opts.mbox.empty()) { | ||||
tfm::format(std::cerr, "No e-mail address set. Please use -m.\n"); | LogPrintf("No e-mail address set. Please use -m.\n"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
FILE *f = fsbridge::fopen(GetSeederDir() / "dnsseed.dat", "r"); | FILE *f = fsbridge::fopen(GetSeederDir() / "dnsseed.dat", "r"); | ||||
if (f) { | if (f) { | ||||
tfm::format(std::cout, "Loading dnsseed.dat..."); | LogPrintfToBeContinued("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(); | ||||
tfm::format(std::cout, "Ban list wiped..."); | LogPrintfToBeContinued("Ban list wiped..."); | ||||
} | } | ||||
if (opts.fWipeIgnore) { | if (opts.fWipeIgnore) { | ||||
db.ResetIgnores(); | db.ResetIgnores(); | ||||
tfm::format(std::cout, "Ignore list wiped..."); | LogPrintfToBeContinued("Ignore list wiped..."); | ||||
} | } | ||||
tfm::format(std::cout, "done\n"); | LogPrintf("done\n"); | ||||
} | } | ||||
pthread_t threadDns, threadSeed, threadDump, threadStats; | pthread_t threadDns, threadSeed, threadDump, threadStats; | ||||
if (fDNS) { | if (fDNS) { | ||||
tfm::format(std::cout, | LogPrintfToBeContinued( | ||||
"Starting %i DNS threads for %s on %s (port %i)...", | "Starting %i DNS threads for %s on %s (port %i)...", | ||||
opts.nDnsThreads, opts.host, opts.ns, 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"); | LogPrintf("done\n"); | ||||
} | } | ||||
tfm::format(std::cout, "Starting seeder..."); | LogPrintfToBeContinued("Starting seeder..."); | ||||
pthread_create(&threadSeed, nullptr, ThreadSeeder, nullptr); | pthread_create(&threadSeed, nullptr, ThreadSeeder, nullptr); | ||||
tfm::format(std::cout, "done\n"); | LogPrintf("done\n"); | ||||
tfm::format(std::cout, "Starting %i crawler threads...", opts.nThreads); | LogPrintfToBeContinued("Starting %i crawler threads...", opts.nThreads); | ||||
pthread_attr_t attr_crawler; | pthread_attr_t attr_crawler; | ||||
pthread_attr_init(&attr_crawler); | pthread_attr_init(&attr_crawler); | ||||
pthread_attr_setstacksize(&attr_crawler, 0x20000); | pthread_attr_setstacksize(&attr_crawler, 0x20000); | ||||
for (int i = 0; i < opts.nThreads; i++) { | for (int i = 0; i < opts.nThreads; i++) { | ||||
pthread_t thread; | pthread_t thread; | ||||
pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads); | pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads); | ||||
} | } | ||||
pthread_attr_destroy(&attr_crawler); | pthread_attr_destroy(&attr_crawler); | ||||
tfm::format(std::cout, "done\n"); | LogPrintf("done\n"); | ||||
pthread_create(&threadStats, nullptr, ThreadStats, nullptr); | pthread_create(&threadStats, nullptr, ThreadStats, nullptr); | ||||
pthread_create(&threadDump, nullptr, ThreadDumper, nullptr); | pthread_create(&threadDump, nullptr, ThreadDumper, nullptr); | ||||
void *res; | void *res; | ||||
pthread_join(threadDump, &res); | pthread_join(threadDump, &res); | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
} | } |