MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ThreadDNSAddressSeed

Function ThreadDNSAddressSeed

src/net.cpp:888–926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886#endif
887
888void ThreadDNSAddressSeed() {
889 // goal: only query DNS seeds if address need is acute
890 if ((addrman.size() > 0) && (!SysCfg().GetBoolArg("-forcednsseed", false))) {
891 MilliSleep(11 * 1000);
892
893 LOCK(cs_vNodes);
894 if (vNodes.size() >= 2) {
895 LogPrint(BCLog::INFO, "P2P peers available. Skipped DNS seeding.\n");
896 return;
897 }
898 }
899
900 const vector<CDNSSeedData>& vSeeds = SysCfg().DNSSeeds();
901 int32_t found = 0;
902
903 LogPrint(BCLog::INFO, "Loading addresses from DNS seeds (could take a while)\n");
904
905 for (const auto& seed : vSeeds) {
906 if (HaveNameProxy()) {
907 AddOneShot(seed.host);
908 } else {
909 vector<CNetAddr> vIPs;
910 vector<CAddress> vAdd;
911 if (LookupHost(seed.host.c_str(), vIPs)) {
912 for (auto& ip : vIPs) {
913 int32_t nOneDay = 24 * 3600;
914 CAddress addr = CAddress(CService(ip, SysCfg().GetDefaultPort()));
915 addr.nTime =
916 GetTime() - 3 * nOneDay - GetRand(4 * nOneDay); // use a random age between 3 and 7 days old
917 vAdd.push_back(addr);
918 found++;
919 }
920 }
921 addrman.Add(vAdd, CNetAddr(seed.name, true));
922 }
923 }
924
925 LogPrint(BCLog::INFO, "%d addresses found from DNS seeds\n", found);
926}
927
928void DumpAddresses() {
929 int64_t nStart = GetTimeMillis();

Callers

nothing calls this directly

Calls 14

MilliSleepFunction · 0.85
HaveNameProxyFunction · 0.85
AddOneShotFunction · 0.85
LookupHostFunction · 0.85
GetTimeFunction · 0.85
GetRandFunction · 0.85
GetBoolArgMethod · 0.80
push_backMethod · 0.80
CServiceClass · 0.70
CNetAddrClass · 0.70
CAddressClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected