From 5fae108bfc97ac84cf388c3f1711007eb65cbdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 5 Feb 2018 10:44:52 +0100 Subject: [PATCH 1/2] Use system default DNS server config --- README.md | 10 ++++++---- composer.json | 2 +- src/Connector.php | 11 ++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9424777f..17e8cd29 100644 --- a/README.md +++ b/README.md @@ -918,10 +918,12 @@ also shares all of their features and implementation details. If you want to typehint in your higher-level protocol implementation, you SHOULD use the generic [`ConnectorInterface`](#connectorinterface) instead. -In particular, the `Connector` class uses Google's public DNS server `8.8.8.8` -to resolve all public hostnames into underlying IP addresses by default. -If you want to use a custom DNS server (such as a local DNS relay or a company -wide DNS server), you can set up the `Connector` like this: +The `Connector` class will try to detect your system DNS settings (and uses +Google's public DNS server `8.8.8.8` as a fallback if unable to determine your +system settings) to resolve all public hostnames into underlying IP addresses by +default. +If you explicitly want to use a custom DNS server (such as a local DNS relay or +a company wide DNS server), you can set up the `Connector` like this: ```php $connector = new Connector($loop, array( diff --git a/composer.json b/composer.json index a3c4cf60..bc85aabc 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=5.3.0", "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "react/dns": "^0.4.11", + "react/dns": "^0.4.13", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5", "react/stream": "^1.0 || ^0.7.1", "react/promise": "^2.1 || ^1.2", diff --git a/src/Connector.php b/src/Connector.php index dfd8b0cf..75276bc5 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -2,6 +2,7 @@ namespace React\Socket; +use React\Dns\Config\Config; use React\Dns\Resolver\Factory; use React\Dns\Resolver\Resolver; use React\EventLoop\LoopInterface; @@ -56,9 +57,17 @@ public function __construct(LoopInterface $loop, array $options = array()) if ($options['dns'] instanceof Resolver) { $resolver = $options['dns']; } else { + if ($options['dns'] !== true) { + $server = $options['dns']; + } else { + // try to load nameservers from system config or default to Google's public DNS + $config = Config::loadSystemConfigBlocking(); + $server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8'; + } + $factory = new Factory(); $resolver = $factory->create( - $options['dns'] === true ? '8.8.8.8' : $options['dns'], + $server, $loop ); } From c452f78f0d3859effe50ff60ccad9a99ff31b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 27 Feb 2018 13:57:29 +0100 Subject: [PATCH 2/2] Cyclic DNS dependency is resolved, remove obsolte documentation --- .travis.yml | 2 +- README.md | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d875a323..917dc0c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ install: curl -s http://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer fi - - COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install --no-interaction + - composer install --no-interaction script: - ./vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index 17e8cd29..bef4707e 100644 --- a/README.md +++ b/README.md @@ -1394,12 +1394,10 @@ on affected versions. ## Tests To run the test suite, you first need to clone this repo and then install all -dependencies [through Composer](https://getcomposer.org). -Because the test suite contains some circular dependencies, you may have to -manually specify the root package version like this: +dependencies [through Composer](https://getcomposer.org): ```bash -$ COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install +$ composer install ``` To run the test suite, go to the project root and run: