Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/main.cpp
Show All 27 Lines | public: | ||||
const char *ns; | const char *ns; | ||||
const char *host; | const char *host; | ||||
const char *tor; | const char *tor; | ||||
const char *ipv4_proxy; | const char *ipv4_proxy; | ||||
const char *ipv6_proxy; | const char *ipv6_proxy; | ||||
std::set<uint64_t> filter_whitelist; | std::set<uint64_t> filter_whitelist; | ||||
CDnsSeedOpts() | CDnsSeedOpts() | ||||
: nThreads(96), nDnsThreads(4), nPort(53), mbox(nullptr), ns(nullptr), | : nThreads(96), nPort(53), nDnsThreads(4), fUseTestNet(false), | ||||
host(nullptr), tor(nullptr), fUseTestNet(false), fWipeBan(false), | fWipeBan(false), fWipeIgnore(false), mbox(nullptr), ns(nullptr), | ||||
fWipeIgnore(false), ipv4_proxy(nullptr), ipv6_proxy(nullptr) {} | host(nullptr), tor(nullptr), ipv4_proxy(nullptr), | ||||
ipv6_proxy(nullptr) {} | |||||
void ParseCommandLine(int argc, char **argv) { | void ParseCommandLine(int argc, char **argv) { | ||||
static const char *help = | static const char *help = | ||||
"Bitcoin-cash-seeder\n" | "Bitcoin-cash-seeder\n" | ||||
"Usage: %s -h <host> -n <ns> [-m <mbox>] [-t <threads>] [-p " | "Usage: %s -h <host> -n <ns> [-m <mbox>] [-t <threads>] [-p " | ||||
"<port>]\n" | "<port>]\n" | ||||
"\n" | "\n" | ||||
"Options:\n" | "Options:\n" | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | do { | ||||
db.GetMany(ips, 16, wait); | db.GetMany(ips, 16, wait); | ||||
int64_t now = time(nullptr); | int64_t now = time(nullptr); | ||||
if (ips.empty()) { | if (ips.empty()) { | ||||
wait *= 1000; | wait *= 1000; | ||||
wait += rand() % (500 * *nThreads); | wait += rand() % (500 * *nThreads); | ||||
Sleep(wait); | Sleep(wait); | ||||
continue; | continue; | ||||
} | } | ||||
std::vector<CAddress> addr; | std::vector<CAddress> addr; | ||||
for (int i = 0; i < ips.size(); i++) { | for (size_t i = 0; i < ips.size(); i++) { | ||||
CServiceResult &res = ips[i]; | CServiceResult &res = ips[i]; | ||||
res.nBanTime = 0; | res.nBanTime = 0; | ||||
res.nClientV = 0; | res.nClientV = 0; | ||||
res.nHeight = 0; | res.nHeight = 0; | ||||
res.strClientV = ""; | res.strClientV = ""; | ||||
bool getaddr = res.ourLastSuccess + 86400 < now; | bool getaddr = res.ourLastSuccess + 86400 < now; | ||||
res.fGood = TestNode(res.service, res.nBanTime, res.nClientV, | res.fGood = TestNode(res.service, res.nBanTime, res.nClientV, | ||||
res.strClientV, res.nHeight, | res.strClientV, res.nHeight, | ||||
getaddr ? &addr : nullptr); | getaddr ? &addr : nullptr); | ||||
} | } | ||||
db.ResultMany(ips); | db.ResultMany(ips); | ||||
db.Add(addr); | db.Add(addr); | ||||
} while (1); | } while (1); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
extern "C" int GetIPList(void *thread, char *requestedHostname, addr_t *addr, | extern "C" uint32_t GetIPList(void *thread, char *requestedHostname, | ||||
int max, int ipv4, int ipv6); | addr_t *addr, uint32_t max, uint32_t ipv4, | ||||
uint32_t ipv6); | |||||
class CDnsThread { | class CDnsThread { | ||||
public: | public: | ||||
struct FlagSpecificData { | struct FlagSpecificData { | ||||
int nIPv4, nIPv6; | int nIPv4, nIPv6; | ||||
std::vector<addr_t> cache; | std::vector<addr_t> cache; | ||||
time_t cacheTime; | time_t cacheTime; | ||||
unsigned int cacheHits; | unsigned int cacheHits; | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | CDnsThread(CDnsSeedOpts *opts, int idIn) : id(idIn) { | ||||
dbQueries = 0; | dbQueries = 0; | ||||
perflag.clear(); | perflag.clear(); | ||||
filterWhitelist = opts->filter_whitelist; | filterWhitelist = opts->filter_whitelist; | ||||
} | } | ||||
void run() { dnsserver(&dns_opt); } | void run() { dnsserver(&dns_opt); } | ||||
}; | }; | ||||
extern "C" int GetIPList(void *data, char *requestedHostname, addr_t *addr, | extern "C" uint32_t GetIPList(void *data, char *requestedHostname, addr_t *addr, | ||||
int max, int ipv4, int ipv6) { | uint32_t max, uint32_t ipv4, uint32_t ipv6) { | ||||
CDnsThread *thread = (CDnsThread *)data; | CDnsThread *thread = (CDnsThread *)data; | ||||
uint64_t requestedFlags = 0; | uint64_t requestedFlags = 0; | ||||
int hostlen = strlen(requestedHostname); | int hostlen = strlen(requestedHostname); | ||||
if (hostlen > 1 && requestedHostname[0] == 'x' && | if (hostlen > 1 && requestedHostname[0] == 'x' && | ||||
requestedHostname[1] != '0') { | requestedHostname[1] != '0') { | ||||
char *pEnd; | char *pEnd; | ||||
uint64_t flags = (uint64_t)strtoull(requestedHostname + 1, &pEnd, 16); | uint64_t flags = (uint64_t)strtoull(requestedHostname + 1, &pEnd, 16); | ||||
if (*pEnd == '.' && pEnd <= requestedHostname + 17 && | if (*pEnd == '.' && pEnd <= requestedHostname + 17 && | ||||
std::find(thread->filterWhitelist.begin(), | std::find(thread->filterWhitelist.begin(), | ||||
thread->filterWhitelist.end(), | thread->filterWhitelist.end(), | ||||
flags) != thread->filterWhitelist.end()) | flags) != thread->filterWhitelist.end()) { | ||||
requestedFlags = flags; | requestedFlags = flags; | ||||
else | } else { | ||||
return 0; | return 0; | ||||
} else if (strcasecmp(requestedHostname, thread->dns_opt.host)) | } | ||||
} else if (strcasecmp(requestedHostname, thread->dns_opt.host)) { | |||||
return 0; | return 0; | ||||
} | |||||
thread->cacheHit(requestedFlags); | thread->cacheHit(requestedFlags); | ||||
auto &thisflag = thread->perflag[requestedFlags]; | auto &thisflag = thread->perflag[requestedFlags]; | ||||
unsigned int size = thisflag.cache.size(); | uint32_t size = thisflag.cache.size(); | ||||
unsigned int maxmax = | uint32_t maxmax = (ipv4 ? thisflag.nIPv4 : 0) + (ipv6 ? thisflag.nIPv6 : 0); | ||||
(ipv4 ? thisflag.nIPv4 : 0) + (ipv6 ? thisflag.nIPv6 : 0); | if (max > size) { | ||||
if (max > size) max = size; | max = size; | ||||
if (max > maxmax) max = maxmax; | } | ||||
int i = 0; | if (max > maxmax) { | ||||
max = maxmax; | |||||
} | |||||
uint32_t i = 0; | |||||
while (i < max) { | while (i < max) { | ||||
int j = i + (rand() % (size - i)); | uint32_t j = i + (rand() % (size - i)); | ||||
do { | do { | ||||
bool ok = (ipv4 && thisflag.cache[j].v == 4) || | bool ok = (ipv4 && thisflag.cache[j].v == 4) || | ||||
(ipv6 && thisflag.cache[j].v == 6); | (ipv6 && thisflag.cache[j].v == 6); | ||||
if (ok) break; | if (ok) { | ||||
break; | |||||
} | |||||
j++; | j++; | ||||
if (j == size) j = i; | if (j == size) { | ||||
j = i; | |||||
} | |||||
} while (1); | } while (1); | ||||
addr[i] = thisflag.cache[j]; | addr[i] = thisflag.cache[j]; | ||||
thisflag.cache[j] = thisflag.cache[i]; | thisflag.cache[j] = thisflag.cache[i]; | ||||
thisflag.cache[i] = addr[i]; | thisflag.cache[i] = addr[i]; | ||||
i++; | i++; | ||||
} | } | ||||
return max; | return max; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines |