This commit is contained in:
Daniil Gentili 2022-10-29 20:07:24 +02:00
parent f4d729a758
commit dc86c058c6
4 changed files with 72 additions and 118 deletions

View File

@ -1,38 +0,0 @@
sudo: false
language: php
php:
# - 7.2
# - 7.3
- 7.4
- nightly
matrix:
allow_failures:
- php: nightly
fast_finish: true
env:
- AMP_DEBUG=true
before_install:
- phpenv config-rm xdebug.ini || echo "No xdebug config."
install:
- composer update -n --prefer-dist
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.2/coveralls.phar
- chmod +x coveralls.phar
script:
- vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
after_script:
- ./coveralls.phar -v
cache:
directories:
- $HOME/.composer/cache
- $HOME/.php-cs-fixer
- $HOME/.local

View File

@ -1,7 +1,5 @@
# dns
[![Build Status](https://img.shields.io/travis/danog/dns-over-https/master.svg?style=flat-square)](https://travis-ci.org/danog/dns-over-https)
[![CoverageStatus](https://img.shields.io/coveralls/danog/dns-over-https/master.svg?style=flat-square)](https://coveralls.io/github/danog/dns-over-https?branch=master)
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
`danog/dns-over-https` provides asynchronous and secure DNS-over-HTTPS name resolution for [Amp](https://github.com/amphp/amp).

View File

@ -1,38 +0,0 @@
build: false
shallow_clone: false
platform:
- x86
- x64
clone_folder: c:\projects\amphp
cache:
- c:\tools\php73 -> appveyor.yml
init:
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php73;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET PHP=1
- SET ANSICON=121x90 (121x90)
install:
- IF EXIST c:\tools\php73 (SET PHP=0)
- IF %PHP%==1 sc config wuauserv start= auto
- IF %PHP%==1 net start wuauserv
- IF %PHP%==1 cinst -y OpenSSL.Light
- IF %PHP%==1 cinst -y php
- cd c:\tools\php73
- IF %PHP%==1 copy php.ini-production php.ini /Y
- IF %PHP%==1 echo date.timezone="UTC" >> php.ini
- IF %PHP%==1 echo extension_dir=ext >> php.ini
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
- IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini
- IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini
- cd c:\projects\amphp
- appveyor DownloadFile https://getcomposer.org/composer.phar
- php composer.phar install --prefer-dist --no-progress
test_script:
- cd c:\projects\amphp
- vendor/bin/phpunit --colors=always

View File

@ -95,26 +95,34 @@ final class Rfc8484StubResolver implements Resolver
case Record::A:
if (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return [new Record($name, Record::A, null)];
} elseif (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
}
if (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
throw new DnsException("Got an IPv6 address, but type is restricted to IPv4");
}
break;
case Record::AAAA:
if (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return [new Record($name, Record::AAAA, null)];
} elseif (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
}
if (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
throw new DnsException("Got an IPv4 address, but type is restricted to IPv6");
}
break;
default:
if (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return [new Record($name, Record::A, null)];
} elseif (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
}
if (\filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return [new Record($name, Record::AAAA, null)];
}
break;
}
$dots = \substr_count($name, ".");
$trailingDot = $name[-1] === ".";
$name = normalizeName($name);
if ($records = $this->queryHosts($name, $typeRestriction)) {
@ -132,53 +140,77 @@ final class Rfc8484StubResolver implements Resolver
if ($this->dohConfig->isNameserver($name)) {
return $this->subResolver->resolve($name, $typeRestriction, $cancellation);
}
\assert($this->config !== null);
for ($redirects = 0; $redirects < 5; $redirects++) {
try {
if ($typeRestriction) {
return $this->query($name, $typeRestriction, $cancellation);
$searchList = [null];
if (!$trailingDot && $dots < $this->config->getNdots()) {
$searchList = \array_merge($this->config->getSearchList(), $searchList);
}
foreach ($searchList as $searchIndex => $search) {
for ($redirects = 0; $redirects < 5; $redirects++) {
$searchName = $name;
if ($search !== null) {
$searchName = $name . "." . $search;
}
list($exceptions, $records) = awaitAll([
async(fn () => $this->query($name, Record::A, $cancellation)),
async(fn () => $this->query($name, Record::AAAA, $cancellation)),
]);
if (\count($exceptions) === 2) {
$errors = [];
foreach ($exceptions as $reason) {
if ($reason instanceof NoRecordException) {
throw $reason;
}
if ($searchIndex < \count($searchList) - 1 && \in_array($reason->getCode(), [2, 3], true)) {
continue 2;
}
$errors[] = $reason->getMessage();
try {
if ($typeRestriction) {
return $this->query($searchName, $typeRestriction, $cancellation);
}
throw new DnsException(
"All query attempts failed for {$name}: " . \implode(", ", $errors),
0,
new CompositeException($exceptions)
);
}
return \array_merge(...$records);
} catch (NoRecordException $e) {
try {
$cnameRecords = $this->query($name, Record::CNAME, $cancellation);
$name = $cnameRecords[0]->getValue();
continue;
[$exceptions, $records] = Future\awaitAll([
async(fn () => $this->query($searchName, Record::A, $cancellation)),
async(fn () => $this->query($searchName, Record::AAAA, $cancellation)),
]);
if (\count($exceptions) === 2) {
$errors = [];
foreach ($exceptions as $reason) {
if ($reason instanceof NoRecordException) {
throw $reason;
}
if ($searchIndex < \count($searchList) - 1 && \in_array($reason->getCode(), [2, 3], true)) {
continue 2;
}
$errors[] = $reason->getMessage();
}
throw new DnsException(
"All query attempts failed for {$searchName}: " . \implode(", ", $errors),
0,
new CompositeException($exceptions)
);
}
return \array_merge(...$records);
} catch (NoRecordException) {
$dnameRecords = $this->query($name, Record::DNAME, $cancellation);
$name = $dnameRecords[0]->getValue();
continue;
try {
$cnameRecords = $this->query($searchName, Record::CNAME, $cancellation);
$name = $cnameRecords[0]->getValue();
continue;
} catch (NoRecordException) {
$dnameRecords = $this->query($searchName, Record::DNAME, $cancellation);
$name = $dnameRecords[0]->getValue();
continue;
}
} catch (DnsException $e) {
if ($searchIndex < \count($searchList) - 1 && \in_array($e->getCode(), [2, 3], true)) {
continue 2;
}
throw $e;
}
}
}
return $records;
\assert(isset($searchName));
throw new DnsException("Giving up resolution of '{$searchName}', too many redirects");
}
/**