-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Detect system default resolver #52
[RFC] Detect system default resolver #52
Conversation
#48 adds a TimeoutExecutor, would it make sense to read the timeout option from resolve.conf and use that value to create the TimeoutExecutor? |
Most certainly! If @reactphp/core likes the proposed external API I'll go more in depth and add more features like the timeout option 😄 . |
Any news on this guys? Any chance for it to being merged in next week? |
What's with Windows? This PR will result in many written apps not being able to run on Windows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for filing this ticket @WyriHaximus, I'd love to get this feature in! 👍
I'm currently unsure about its API, but have you seen the (somewhat outdated) https://github.com/reactphp/dns/blob/master/src/Config/FilesystemFactory.php ?
I think it make more sense to keep this in a separate class and then pass the nameserver configuration to the default create*()
methods.
What do you think about this?
@clue we could go with something like this, where $loop = React\EventLoop\Factory::create();
$factory = new React\Dns\Resolver\Factory();
$dns = $factory->createCached(determineSystemDefaultServer('8.8.8.8'), $loop); |
} | ||
|
||
if (count($nameservers) > 0) { | ||
shuffle($nameservers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should use the first one, not a random one. I think the first one is considered the primary DNS and order should be respected in /etc/resolv.conf
.
$nameserverPosition = stripos($line, 'nameserver'); | ||
if ($nameserverPosition !== false) { | ||
$nameserverLine = trim(substr($line, $nameserverPosition + 11)); | ||
list ($nameservers[]) = explode(' ', $nameserverLine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be only one nameserver per nameserver
config option in /etc/resolv.conf
.
return array_pop($nameservers); | ||
} | ||
|
||
throw new \Exception('Nameserver configuration missing'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man resolv.conf
says it should default to the local nameserver if none are present, but Amp doesn't do this either, at least currently.
I added some comments regarding the implementation. While it will usually work to read |
As discussed in #29 a PR that detects the system default resolver on *nix systems.