Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | convertSeed6(const std::vector<SeedSpec6> &vSeedsIn) { | ||||
// it'll get a pile of addresses with newer timestamps. Seed nodes are given | // it'll get a pile of addresses with newer timestamps. Seed nodes are given | ||||
// a random 'last seen time' of between one and two weeks ago. | // a random 'last seen time' of between one and two weeks ago. | ||||
const int64_t nOneWeek = 7 * 24 * 60 * 60; | const int64_t nOneWeek = 7 * 24 * 60 * 60; | ||||
std::vector<CAddress> vSeedsOut; | std::vector<CAddress> vSeedsOut; | ||||
vSeedsOut.reserve(vSeedsIn.size()); | vSeedsOut.reserve(vSeedsIn.size()); | ||||
for (const auto &seed_in : vSeedsIn) { | for (const auto &seed_in : vSeedsIn) { | ||||
struct in6_addr ip; | struct in6_addr ip; | ||||
memcpy(&ip, seed_in.addr, sizeof(ip)); | memcpy(&ip, seed_in.addr, sizeof(ip)); | ||||
CAddress addr(CService(ip, seed_in.port), NODE_NETWORK); | CAddress addr(CService(ip, seed_in.port), | ||||
GetDesirableServiceFlags(NODE_NONE)); | |||||
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek; | addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek; | ||||
vSeedsOut.push_back(addr); | vSeedsOut.push_back(addr); | ||||
} | } | ||||
return vSeedsOut; | return vSeedsOut; | ||||
} | } | ||||
// Get best local address for a particular peer as a CAddress. Otherwise, return | // Get best local address for a particular peer as a CAddress. Otherwise, return | ||||
// the unroutable 0.0.0.0 but filled in with the normal parameters, since the IP | // the unroutable 0.0.0.0 but filled in with the normal parameters, since the IP | ||||
▲ Show 20 Lines • Show All 1,517 Lines • ▼ Show 20 Lines | |||||
void InterruptMapPort() { | void InterruptMapPort() { | ||||
// Intentionally left blank. | // Intentionally left blank. | ||||
} | } | ||||
void StopMapPort() { | void StopMapPort() { | ||||
// Intentionally left blank. | // Intentionally left blank. | ||||
} | } | ||||
#endif | #endif | ||||
static std::string GetDNSHost(const CDNSSeedData &data, | |||||
ServiceFlags *requiredServiceBits) { | |||||
// use default host for non-filter-capable seeds or if we use the default | |||||
// service bits (NODE_NETWORK) | |||||
if (!data.supportsServiceBitsFiltering || | |||||
*requiredServiceBits == NODE_NETWORK) { | |||||
*requiredServiceBits = NODE_NETWORK; | |||||
return data.host; | |||||
} | |||||
// See chainparams.cpp, most dnsseeds only support one or two possible | |||||
// servicebits hostnames | |||||
return strprintf("x%x.%s", *requiredServiceBits, data.host); | |||||
} | |||||
void CConnman::ThreadDNSAddressSeed() { | void CConnman::ThreadDNSAddressSeed() { | ||||
// goal: only query DNS seeds if address need is acute. | // goal: only query DNS seeds if address need is acute. | ||||
// Avoiding DNS seeds when we don't need them improves user privacy by | // Avoiding DNS seeds when we don't need them improves user privacy by | ||||
// creating fewer identifying DNS requests, reduces trust by giving seeds | // creating fewer identifying DNS requests, reduces trust by giving seeds | ||||
// less influence on the network topology, and reduces traffic to the seeds. | // less influence on the network topology, and reduces traffic to the seeds. | ||||
if ((addrman.size() > 0) && | if ((addrman.size() > 0) && | ||||
(!gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED))) { | (!gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED))) { | ||||
if (!interruptNet.sleep_for(std::chrono::seconds(11))) { | if (!interruptNet.sleep_for(std::chrono::seconds(11))) { | ||||
return; | return; | ||||
} | } | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
int nRelevant = 0; | int nRelevant = 0; | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
nRelevant += pnode->fSuccessfullyConnected && !pnode->fFeeler && | nRelevant += pnode->fSuccessfullyConnected && !pnode->fFeeler && | ||||
!pnode->fOneShot && !pnode->m_manual_connection && | !pnode->fOneShot && !pnode->m_manual_connection && | ||||
!pnode->fInbound; | !pnode->fInbound; | ||||
} | } | ||||
if (nRelevant >= 2) { | if (nRelevant >= 2) { | ||||
LogPrintf("P2P peers available. Skipped DNS seeding.\n"); | LogPrintf("P2P peers available. Skipped DNS seeding.\n"); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
const std::vector<CDNSSeedData> &vSeeds = | const std::vector<std::string> &vSeeds = | ||||
config->GetChainParams().DNSSeeds(); | config->GetChainParams().DNSSeeds(); | ||||
int found = 0; | int found = 0; | ||||
LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); | LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); | ||||
for (const CDNSSeedData &seed : vSeeds) { | for (const std::string &seed : vSeeds) { | ||||
if (interruptNet) { | |||||
return; | |||||
} | |||||
if (HaveNameProxy()) { | if (HaveNameProxy()) { | ||||
AddOneShot(seed.host); | AddOneShot(seed); | ||||
} else { | } else { | ||||
std::vector<CNetAddr> vIPs; | std::vector<CNetAddr> vIPs; | ||||
std::vector<CAddress> vAdd; | std::vector<CAddress> vAdd; | ||||
ServiceFlags requiredServiceBits = | ServiceFlags requiredServiceBits = | ||||
GetDesirableServiceFlags(NODE_NONE); | GetDesirableServiceFlags(NODE_NONE); | ||||
std::string host = GetDNSHost(seed, &requiredServiceBits); | std::string host = strprintf("x%x.%s", requiredServiceBits, seed); | ||||
CNetAddr resolveSource; | CNetAddr resolveSource; | ||||
if (!resolveSource.SetInternal(host)) { | if (!resolveSource.SetInternal(host)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (LookupHost(host.c_str(), vIPs, 0, true)) { | if (LookupHost(host.c_str(), vIPs, 0, true)) { | ||||
for (const CNetAddr &ip : vIPs) { | for (const CNetAddr &ip : vIPs) { | ||||
int nOneDay = 24 * 3600; | int nOneDay = 24 * 3600; | ||||
CAddress addr = CAddress( | CAddress addr = CAddress( | ||||
CService(ip, config->GetChainParams().GetDefaultPort()), | CService(ip, config->GetChainParams().GetDefaultPort()), | ||||
requiredServiceBits); | requiredServiceBits); | ||||
// Use a random age between 3 and 7 days old. | // Use a random age between 3 and 7 days old. | ||||
addr.nTime = GetTime() - 3 * nOneDay - GetRand(4 * nOneDay); | addr.nTime = GetTime() - 3 * nOneDay - GetRand(4 * nOneDay); | ||||
vAdd.push_back(addr); | vAdd.push_back(addr); | ||||
found++; | found++; | ||||
} | } | ||||
addrman.Add(vAdd, resolveSource); | addrman.Add(vAdd, resolveSource); | ||||
} else { | |||||
// We now avoid directly using results from DNS Seeds which do | |||||
// not support service bit filtering, instead using them as a | |||||
// oneshot to get nodes with our desired service bits. | |||||
AddOneShot(seed); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
LogPrintf("%d addresses found from DNS seeds\n", found); | LogPrintf("%d addresses found from DNS seeds\n", found); | ||||
} | } | ||||
void CConnman::DumpAddresses() { | void CConnman::DumpAddresses() { | ||||
▲ Show 20 Lines • Show All 1,344 Lines • Show Last 20 Lines |