diff --git a/lib/BasicResolver.php b/lib/BasicResolver.php index 41c848d..63dec1c 100644 --- a/lib/BasicResolver.php +++ b/lib/BasicResolver.php @@ -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 diff --git a/lib/Resolver.php b/lib/Resolver.php index a17b06d..f37d115 100644 --- a/lib/Resolver.php +++ b/lib/Resolver.php @@ -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; } diff --git a/lib/functions.php b/lib/functions.php index 52d3e7a..9cc97f3 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -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); }