1
0
mirror of https://github.com/danog/dns.git synced 2024-11-30 04:29:06 +01:00

Fix resolution data and add CNAME / DNAME support

This commit is contained in:
Niklas Keller 2017-06-23 14:11:11 +02:00
parent 05a413f72c
commit b05d11912b

View File

@ -76,17 +76,39 @@ class BasicResolver implements Resolver {
return $records;
}
if ($typeRestriction) {
return $this->query($name, $typeRestriction);
}
for ($cnames = 0; $cnames < 5; $cnames++) {
try {
if ($typeRestriction) {
$records = yield $this->query($name, $typeRestriction);
} else {
try {
list(, $records) = yield Promise\some([
$this->query($name, Record::A),
$this->query($name, Record::AAAA),
]);
} catch (MultiReasonException $e) {
foreach ($e->getReasons() as $reason) {
if ($reason instanceof NoRecordException) {
throw $reason;
}
}
try {
list(, $records) = yield Promise\some([
$this->query($name, Record::A),
$this->query($name, Record::AAAA),
]);
} catch (MultiReasonException $e) {
throw new ResolutionException("All query attempts failed", 0, $e);
throw new ResolutionException("All query attempts failed", 0, $e);
}
}
} catch (NoRecordException $e) {
try {
/** @var Record[] $cnameRecords */
$cnameRecords = yield $this->query($name, Record::CNAME);
$name = $cnameRecords[0]->getValue();
continue;
} catch (NoRecordException $e) {
/** @var Record[] $dnameRecords */
$dnameRecords = yield $this->query($name, Record::DNAME);
$name = $dnameRecords[0]->getValue();
continue;
}
}
}
return array_merge(...$records);
@ -169,7 +191,7 @@ class BasicResolver implements Resolver {
foreach ($answers as $record) {
$recordType = $record->getType();
$result[$recordType][] = $record->getData();
$result[$recordType][] = (string) $record->getData();
$ttls[$recordType] = \min($ttls[$recordType] ?? \PHP_INT_MAX, $record->getTTL());
}