| 1311 | } |
| 1312 | |
| 1313 | void ThreadDNSAddressSeed() |
| 1314 | { |
| 1315 | // goal: only query DNS seeds if address need is acute |
| 1316 | if ((addrman.size() > 0) && |
| 1317 | (!GetBoolArg("-forcednsseed", false))) { |
| 1318 | MilliSleep(11 * 1000); |
| 1319 | |
| 1320 | // LOCK(cs_vNodes); |
| 1321 | // Avoid using DNS seeds if unnecessary to improve user privacy & reducing traffic to seed. |
| 1322 | int nRelevant = 0; |
| 1323 | for (auto pnode : vNodes) { nRelevant += pnode->fSuccessfullyConnected && ((pnode->nServices & nRelevantServices) == nRelevantServices); } |
| 1324 | if (nRelevant >= 2) { |
| 1325 | LogPrintf("P2P peers available. Skipped DNS seeding.\n"); |
| 1326 | return; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | const vector<CDNSSeedData>& vSeeds = Params().DNSSeeds(); |
| 1331 | int found = 0; |
| 1332 | |
| 1333 | LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); |
| 1334 | |
| 1335 | for (const CDNSSeedData& seed : vSeeds) { |
| 1336 | if (HaveNameProxy()) { |
| 1337 | AddOneShot(seed.host); |
| 1338 | } else { |
| 1339 | vector<CNetAddr> vIPs; |
| 1340 | vector<CAddress> vAdd; |
| 1341 | ServiceFlags requiredServiceBits = nRelevantServices; |
| 1342 | if (LookupHost(GetDNSHost(seed, &requiredServiceBits).c_str(), vIPs, 0, true)) { |
| 1343 | for (CNetAddr& ip : vIPs) { |
| 1344 | int nOneDay = 24 * 3600; |
| 1345 | CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits); |
| 1346 | addr.nTime = GetTime() - 3 * nOneDay - GetRand(4 * nOneDay); // use a random age between 3 and 7 days old |
| 1347 | vAdd.push_back(addr); |
| 1348 | found++; |
| 1349 | } |
| 1350 | } |
| 1351 | addrman.Add(vAdd, CNetAddr(seed.name, true)); |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | LogPrintf("%d addresses found from DNS seeds\n", found); |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | void DumpAddresses() |
nothing calls this directly
no test coverage detected