Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

dns: add getServers and setServers #5435

Closed
wants to merge 1 commit into from

Conversation

tjfontaine
Copy link

getServers returns an array of ips that are currently being used for
resolution

setServers takes an array of ips that are to be used for resolution,
this will throw if there's invalid input but preserve the original
configuration

@@ -117,6 +117,17 @@ The callback has arguments `(err, domains)`.
On error, `err` is an `Error` object, where `err.code` is
one of the error codes listed below.

## dns.getServers()

Returns an array of ips as strings that are currently being used for resolution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ips/IP addresses/ ?

@tjfontaine
Copy link
Author

I have pushed the changes for the lint fixes. I also further extended the test to include setting IPv6 resolvers.

However, ares_set_servers_csv currently has broken IPv6 parsing, if the address includes '::' it thinks everything to the right of the first ':' will be the port.

So this PR is currently blocked, ares_set_servers_csv should be fixed, and I could also parse on my own and use ares_set_servers instead

@keithws
Copy link

keithws commented May 11, 2013

I believe I fixed the bug in ares_set_servers_csv with this pull request.

@tjfontaine
Copy link
Author

Thanks for looking into this, I've commented on that pullreq with another issue I found. I updated my current branch but haven't force pushed, I opted to do the parsing in js and the slightly safer ares_set_servers function

@bnoordhuis
Copy link
Member

c-ares doesn't take pull requests, I believe. You have to git send-email it to the mailing list.

@tjfontaine
Copy link
Author

@bnoordhuis I did push my new change, if you could please re-review I'd appreciate it.

char ip[INET6_ADDRSTRLEN];

uv_inet_ntop(cur->family,
static_cast<const void *>(&cur->addr),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: const void*

@tjfontaine
Copy link
Author

@bnoordhuis updated, I also got rid of the superfluous memcpy since uv_inet_pton does that.

for (int i = 0; cur != NULL; ++i, cur = cur->next) {
char ip[INET6_ADDRSTRLEN];

uv_inet_ntop(cur->family,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the return value. If return_value.code is not UV_OK, ip probably contains garbage.

@bnoordhuis
Copy link
Member

A few more nits, otherwise LGTM.

getServers returns an array of ips that are currently being used for
resolution

setServers takes an array of ips that are to be used for resolution,
this will throw if there's invalid input but preserve the original
configuration
@tjfontaine
Copy link
Author

landed in 8886c6b

@tjfontaine tjfontaine closed this May 14, 2013
@jcspencer
Copy link

Is there a need to make these functions invoke callbacks, as getting the data synchronously isn't the best thing to do.

@tjfontaine
Copy link
Author

I struggled with that decision, in fact in my original ticket #3132 that's what I had done, with an eye towards how I do it in my JS implementation of the dns module.

Ultimately c-ares initializes synchronously when node itself starts, so most of your file operations to determine the resolvers happen at startup, the call to ares_get_servers is only pulling from the state of our c-ares channel and not hitting disk or performing any other blocking call.

In any JS reimplementation that might happen in the future, it would also make sense to initialize synchronously (on the first require) as otherwise you end up having to queue any incoming requests while you wait for the platform to initialize.

@jcspencer
Copy link

Would it be better to add optional callbacks, that are called once the servers have been loaded/set? So you're not waiting for a variable to be initialised synchronously.

@tjfontaine
Copy link
Author

Well it's not really an issue for c-ares as everything has already been initialized by the time you are executing javascript. And replacing c-ares with a pure javascript version is still a hypothetical situation for now.

Perhaps @bnoordhuis or @isaacs have an opinion on this

@jcspencer
Copy link

One possible option would be to compile c-ares into JavaScript with Emscripten. I'm not sure wether this would better or worsen performance, but either way, it's an option

@tjfontaine
Copy link
Author

While I find emscripten interesting, it is certainly the wrong way to handle this particular situation. Especially as there are multiple DNS in javascript parsers, including one I've written. The question is if there's enough to gain/solve by using a javascript implementation to offset the overhead of owning the maintenance cost. The vast majority of requests are handled through dns.lookup which doesn't go through c-ares anyway.

@jcspencer
Copy link

Yeah, a pure javascript dns module would be great.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants