mirror of
https://github.com/danog/dns.git
synced 2024-11-26 20:14:51 +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\MultiReasonException;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use LibDNS\Messages\Message;
|
||||
use LibDNS\Messages\MessageTypes;
|
||||
use LibDNS\Records\Question;
|
||||
@ -57,7 +56,7 @@ class BasicResolver implements Resolver {
|
||||
if ($inAddr !== false) {
|
||||
// It's already a valid IP, don't query, immediately 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $type
|
||||
|
@ -6,12 +6,28 @@ use Amp\Promise;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
@ -40,30 +40,16 @@ function driver(): Resolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve 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
|
||||
*
|
||||
* @return Promise
|
||||
* @see Resolver::resolve()
|
||||
*/
|
||||
function resolve(string $name): Promise {
|
||||
return resolver()->resolve($name);
|
||||
function resolve(string $name, int $typeRestriction = null): Promise {
|
||||
return resolver()->resolve($name, $typeRestriction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query specific DNS records.
|
||||
*
|
||||
* @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
|
||||
* @see Resolver::query()
|
||||
*/
|
||||
function query(string $name, $type): Promise {
|
||||
function query(string $name, int $type): Promise {
|
||||
return resolver()->query($name, $type);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user