Skip to content

[RFC] Detect system default resolver - #52

Closed
WyriHaximus wants to merge 2 commits into
reactphp:masterfrom
WyriHaximus-labs:feature-system-resolver
Closed

[RFC] Detect system default resolver#52
WyriHaximus wants to merge 2 commits into
reactphp:masterfrom
WyriHaximus-labs:feature-system-resolver

Conversation

@WyriHaximus

Copy link
Copy Markdown
Member

As discussed in #29 a PR that detects the system default resolver on *nix systems.

@jsor

jsor commented Feb 23, 2017

Copy link
Copy Markdown
Member

#48 adds a TimeoutExecutor, would it make sense to read the timeout option from resolve.conf and use that value to create the TimeoutExecutor?

@WyriHaximus

Copy link
Copy Markdown
MemberAuthor

#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 😄 .

@WyriHaximusWyriHaximus changed the title Detect system default resolver[RFC] Detect system default resolverMar 2, 2017
@WyriHaximusWyriHaximus mentioned this pull request Mar 9, 2017
@mailopl

Copy link
Copy Markdown

Any news on this guys? Any chance for it to being merged in next week?

@kelunik

Copy link
Copy Markdown

What's with Windows? This PR will result in many written apps not being able to run on Windows.

@WyriHaximus

Copy link
Copy Markdown
MemberAuthor

Ping @jsor@clue, what do you think about the public facing API? If you like it I'll work it out into something that also works on windows and has a default fallback so it works if detection fails.

@clueclue left a comment

Copy link
Copy Markdown
Member

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?

@WyriHaximus

Copy link
Copy Markdown
MemberAuthor

@clue we could go with something like this, where 8.8.8.8 is used as a fallback:

$loop = React\EventLoop\Factory::create();
$factory = newReact\Dns\Resolver\Factory();
$dns = $factory->createCached(determineSystemDefaultServer('8.8.8.8'), $loop);

}

if (count($nameservers) > 0) {
shuffle($nameservers);

Copy link
Copy Markdown

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);

Copy link
Copy Markdown

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');

Copy link
Copy Markdown

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.

@kelunik

Copy link
Copy Markdown

I added some comments regarding the implementation.

While it will usually work to read /etc/resolv.conf once, the nameservers in there might change, e.g. because a software might be running on a notebook that changes the access point (WLAN).

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@WyriHaximus@jsor@mailopl@kelunik@clue