From 861cc857b1ba6e02e8a7439c30403682785fce96 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 24 Dec 2018 16:23:04 +0100 Subject: [PATCH] Move localhost fallback generation to Config, use cloudflare DNS as DNS fallback --- lib/BasicResolver.php | 13 +------------ lib/Config.php | 12 ++++++++++++ lib/HostLoader.php | 11 ----------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/BasicResolver.php b/lib/BasicResolver.php index d7229e2..37e8f70 100644 --- a/lib/BasicResolver.php +++ b/lib/BasicResolver.php @@ -115,17 +115,6 @@ final class BasicResolver implements Resolver { $name = normalizeDnsName($name); - if (in_array($name, ['localhost', 'localhost.'])) { - switch ($typeRestriction) { - case Record::A: - return [new Record('127.0.0.1', Record::A, null)]; - case Record::AAAA: - return [new Record('::1', Record::AAAA, null)]; - default: - return [new Record('127.0.0.1', Record::A, null), new Record('::1', Record::AAAA, null)]; - } - } - if ($records = $this->queryHosts($name, $typeRestriction)) { return $records; } @@ -340,7 +329,7 @@ final class BasicResolver implements Resolver { try { $this->config = yield $this->configLoader->loadConfig(); } catch (\Exception $e) { - $this->config = new Config(['8.8.8.8:53', '8.8.4.4:53', '[2001:4860:4860::8888]:53', '[2001:4860:4860::8844]:53']); + $this->config = new Config(['1.1.1.1:53', '1.0.0.1:53', '[2606:4700:4700::1111]:53', '[2606:4700:4700::1001]:53']); } }); diff --git a/lib/Config.php b/lib/Config.php index dff02d7..04dbf33 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -25,6 +25,18 @@ final class Config { throw new ConfigException("Invalid attempt count ({$attempts}), must be 1 or greater"); } + // Windows does not include localhost in its host file. Fetch it from the system instead + if (!isset($knownHosts[Record::A]["localhost"]) && !isset($knownHosts[Record::AAAA]["localhost"])) { + // PHP currently provides no way to **resolve** IPv6 hostnames (not even with fallback) + $local = \gethostbyname("localhost"); + if ($local !== "localhost") { + $knownHosts[Record::A]["localhost"] = $local; + } else { + $knownHosts[Record::A]["localhost"] = '127.0.0.1'; + } + $knownHosts[Record::AAAA]["localhost"] = "::1"; + } + $this->nameservers = $nameservers; $this->knownHosts = $knownHosts; $this->timeout = $timeout; diff --git a/lib/HostLoader.php b/lib/HostLoader.php index aba83d9..1636647 100644 --- a/lib/HostLoader.php +++ b/lib/HostLoader.php @@ -58,17 +58,6 @@ class HostLoader { } } - // Windows does not include localhost in its host file. Fetch it from the system instead - if (!isset($data[Record::A]["localhost"]) && !isset($data[Record::AAAA]["localhost"])) { - // PHP currently provides no way to **resolve** IPv6 hostnames (not even with fallback) - $local = \gethostbyname("localhost"); - if ($local !== "localhost") { - $data[Record::A]["localhost"] = $local; - } else { - $data[Record::AAAA]["localhost"] = "::1"; - } - } - return $data; }); }