From 7f31762cb6261806542cc6d1188ca07db98a6950 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 23 May 2017 20:04:38 -0400 Subject: net: add an internal subnet for representing unresolved hostnames We currently do two resolves for dns seeds: one for the results, and one to serve in addrman as the source for those addresses. There's no requirement that the source hostname resolves to the stored identifier, only that the mapping is unique. So rather than incurring the second lookup, combine a private subnet with a hash of the hostname. The resulting v6 ip is guaranteed not to be publicy routable, and has only a negligible chance of colliding with a user's internal network (which would be of no consequence anyway). --- src/net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index 75d1719e86..e10016d983 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -240,7 +240,7 @@ bool RemoveLocal(const CService& addr) /** Make a particular network entirely off-limits (no automatic connects to it) */ void SetLimited(enum Network net, bool fLimited) { - if (net == NET_UNROUTABLE) + if (net == NET_UNROUTABLE || net == NET_INTERNAL) return; LOCK(cs_mapLocalHost); vfLimited[net] = fLimited; -- cgit v1.2.3 From 6cdc488e3604267b1e115da5c50ffb970cd30084 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 23 May 2017 20:48:08 -0400 Subject: net: switch to dummy internal ip for dns seed source This addresss the TODO to avoid resolving twice. --- src/net.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index e10016d983..0fcf9e0aba 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1604,7 +1604,12 @@ void CConnman::ThreadDNSAddressSeed() std::vector vIPs; std::vector vAdd; ServiceFlags requiredServiceBits = nRelevantServices; - if (LookupHost(GetDNSHost(seed, &requiredServiceBits).c_str(), vIPs, 0, true)) + std::string host = GetDNSHost(seed, &requiredServiceBits); + CNetAddr resolveSource; + if (!resolveSource.SetInternal(host)) { + continue; + } + if (LookupHost(host.c_str(), vIPs, 0, true)) { BOOST_FOREACH(const CNetAddr& ip, vIPs) { @@ -1614,18 +1619,7 @@ void CConnman::ThreadDNSAddressSeed() vAdd.push_back(addr); found++; } - } - if (interruptNet) { - return; - } - // TODO: The seed name resolve may fail, yielding an IP of [::], which results in - // addrman assigning the same source to results from different seeds. - // This should switch to a hard-coded stable dummy IP for each seed name, so that the - // resolve is not required at all. - if (!vIPs.empty()) { - CService seedSource; - Lookup(seed.name.c_str(), seedSource, 0, true); - addrman.Add(vAdd, seedSource); + addrman.Add(vAdd, resolveSource); } } } -- cgit v1.2.3 From d5c7c1cfe3090775bf30dee531d511801926c18b Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 21 Jun 2017 15:45:20 -0400 Subject: net: use an internal address for fixed seeds --- src/net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index 0fcf9e0aba..cd9e0d05d9 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1718,7 +1718,7 @@ void CConnman::ThreadOpenConnections() if (!done) { LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n"); CNetAddr local; - LookupHost("127.0.0.1", local, false); + local.SetInternal("fixedseeds"); addrman.Add(convertSeed6(Params().FixedSeeds()), local); done = true; } -- cgit v1.2.3