mirror of
https://github.com/danog/dns.git
synced 2024-11-30 04:29:06 +01:00
Add BasicResolver::reloadConfig() and move docs to interface
This commit is contained in:
parent
1124aa1117
commit
ea1cd633dd
@ -7,7 +7,6 @@ use Amp\Cache\Cache;
|
|||||||
use Amp\Coroutine;
|
use Amp\Coroutine;
|
||||||
use Amp\MultiReasonException;
|
use Amp\MultiReasonException;
|
||||||
use Amp\Promise;
|
use Amp\Promise;
|
||||||
use Amp\Success;
|
|
||||||
use LibDNS\Messages\Message;
|
use LibDNS\Messages\Message;
|
||||||
use LibDNS\Messages\MessageTypes;
|
use LibDNS\Messages\MessageTypes;
|
||||||
use LibDNS\Records\Question;
|
use LibDNS\Records\Question;
|
||||||
@ -57,7 +56,7 @@ class BasicResolver implements Resolver {
|
|||||||
if ($inAddr !== false) {
|
if ($inAddr !== false) {
|
||||||
// It's already a valid IP, don't query, immediately return
|
// It's already a valid IP, don't query, immediately return
|
||||||
return [
|
return [
|
||||||
new Record($name, isset($inAddr[4]) ? Record::AAAA : Record::A, null)
|
new Record($name, isset($inAddr[4]) ? Record::AAAA : Record::A, null),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,6 +182,19 @@ class BasicResolver implements Resolver {
|
|||||||
throw new ResolutionException("No response from any nameserver after {$attempts} attempts");
|
throw new ResolutionException("No response from any nameserver after {$attempts} attempts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads the configuration in the background.
|
||||||
|
*
|
||||||
|
* Once it's finished, the configuration will be used for new requests.
|
||||||
|
*
|
||||||
|
* @return Promise
|
||||||
|
*/
|
||||||
|
public function reloadConfig(): Promise {
|
||||||
|
return call(function () {
|
||||||
|
$this->config = $this->configLoader->loadConfig();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param int $type
|
* @param int $type
|
||||||
|
@ -6,12 +6,28 @@ use Amp\Promise;
|
|||||||
|
|
||||||
interface Resolver {
|
interface Resolver {
|
||||||
/**
|
/**
|
||||||
* @see \Amp\Dns\resolve
|
* Resolves a hostname name to an IP address [hostname as defined by RFC 3986].
|
||||||
|
*
|
||||||
|
* Upon success the returned promise resolves to an array of Record objects.
|
||||||
|
*
|
||||||
|
* A null $ttl value indicates the DNS name was resolved from the cache or the local hosts file.
|
||||||
|
*
|
||||||
|
* @param string $name The hostname to resolve.
|
||||||
|
* @param int $typeRestriction Optional type restriction to `Record::A` or `Record::AAAA`, otherwise `null`.
|
||||||
|
*
|
||||||
|
* @return Promise
|
||||||
*/
|
*/
|
||||||
public function resolve(string $name, int $typeRestriction = null): Promise;
|
public function resolve(string $name, int $typeRestriction = null): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \Amp\Dns\query
|
* Query specific DNS records.
|
||||||
|
*
|
||||||
|
* Upon success the returned promise resolves to an array of Record objects.
|
||||||
|
*
|
||||||
|
* @param string $name Record to question, A, AAAA and PTR queries are automatically normalized.
|
||||||
|
* @param int $type Use constants of Amp\Dns\Record.
|
||||||
|
*
|
||||||
|
* @return Promise
|
||||||
*/
|
*/
|
||||||
public function query(string $name, int $type): Promise;
|
public function query(string $name, int $type): Promise;
|
||||||
}
|
}
|
||||||
|
@ -40,30 +40,16 @@ function driver(): Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a hostname name to an IP address [hostname as defined by RFC 3986].
|
* @see Resolver::resolve()
|
||||||
*
|
|
||||||
* Upon success the returned promise resolves to an array of Record objects.
|
|
||||||
*
|
|
||||||
* A null $ttl value indicates the DNS name was resolved from the cache or the local hosts file.
|
|
||||||
*
|
|
||||||
* @param string $name The hostname to resolve
|
|
||||||
*
|
|
||||||
* @return Promise
|
|
||||||
*/
|
*/
|
||||||
function resolve(string $name): Promise {
|
function resolve(string $name, int $typeRestriction = null): Promise {
|
||||||
return resolver()->resolve($name);
|
return resolver()->resolve($name, $typeRestriction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query specific DNS records.
|
* @see Resolver::query()
|
||||||
*
|
|
||||||
* @param string $name Unlike resolve(), query() allows for requesting _any_ name (as DNS RFC allows for arbitrary
|
|
||||||
* strings)
|
|
||||||
* @param int|int[] $type Use constants of Amp\Dns\Record
|
|
||||||
*
|
|
||||||
* @return Promise
|
|
||||||
*/
|
*/
|
||||||
function query(string $name, $type): Promise {
|
function query(string $name, int $type): Promise {
|
||||||
return resolver()->query($name, $type);
|
return resolver()->query($name, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user