| 1601 | |
| 1602 | |
| 1603 | void CConnman::ThreadDNSAddressSeed() |
| 1604 | { |
| 1605 | // goal: only query DNS seeds if address need is acute |
| 1606 | // Avoiding DNS seeds when we don't need them improves user privacy by |
| 1607 | // creating fewer identifying DNS requests, reduces trust by giving seeds |
| 1608 | // less influence on the network topology, and reduces traffic to the seeds. |
| 1609 | if ((addrman.size() > 0) && |
| 1610 | (!gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED))) { |
| 1611 | if (!interruptNet.sleep_for(std::chrono::seconds(11))) |
| 1612 | return; |
| 1613 | |
| 1614 | LOCK(cs_vNodes); |
| 1615 | int nRelevant = 0; |
| 1616 | for (auto pnode : vNodes) { |
| 1617 | nRelevant += pnode->fSuccessfullyConnected && !pnode->fFeeler && !pnode->fOneShot && !pnode->m_manual_connection && !pnode->fInbound; |
| 1618 | } |
| 1619 | if (nRelevant >= 2) { |
| 1620 | LogPrintf("P2P peers available. Skipped DNS seeding.\n"); |
| 1621 | return; |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | const std::vector<std::string> &vSeeds = Params().DNSSeeds(); |
| 1626 | int found = 0; |
| 1627 | |
| 1628 | LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); |
| 1629 | |
| 1630 | for (const std::string &seed : vSeeds) { |
| 1631 | if (interruptNet) { |
| 1632 | return; |
| 1633 | } |
| 1634 | if (HaveNameProxy()) { |
| 1635 | AddOneShot(seed); |
| 1636 | } else { |
| 1637 | std::vector<CNetAddr> vIPs; |
| 1638 | std::vector<CAddress> vAdd; |
| 1639 | ServiceFlags requiredServiceBits = GetDesirableServiceFlags(NODE_NONE); |
| 1640 | std::string host = strprintf("x%x.%s", requiredServiceBits, seed); |
| 1641 | CNetAddr resolveSource; |
| 1642 | if (!resolveSource.SetInternal(host)) { |
| 1643 | continue; |
| 1644 | } |
| 1645 | unsigned int nMaxIPs = 256; // Limits number of IPs learned from a DNS seed |
| 1646 | if (LookupHost(host.c_str(), vIPs, nMaxIPs, true)) |
| 1647 | { |
| 1648 | for (const CNetAddr& ip : vIPs) |
| 1649 | { |
| 1650 | int nOneDay = 24*3600; |
| 1651 | CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits); |
| 1652 | addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old |
| 1653 | vAdd.push_back(addr); |
| 1654 | found++; |
| 1655 | } |
| 1656 | addrman.Add(vAdd, resolveSource); |
| 1657 | } else { |
| 1658 | // We now avoid directly using results from DNS Seeds which do not support service bit filtering, |
| 1659 | // instead using them as a oneshot to get nodes with our desired service bits. |
| 1660 | AddOneShot(seed); |
nothing calls this directly
no test coverage detected