Skip to content
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

net: add (*Resolver).ResolveIPAddr #30452

Closed
iangudger opened this issue Feb 28, 2019 · 17 comments
Closed

net: add (*Resolver).ResolveIPAddr #30452

iangudger opened this issue Feb 28, 2019 · 17 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal Proposal-Accepted
Milestone

Comments

@iangudger
Copy link
Contributor

In the net package, there are two classes of DNS functions: LookupXxx and ResolveXxx. The net.Resolver type implements the LookupXxx functions as methods, but not the ResolveXxx functions. The ResolveXxx functions are similar to LookupHost, except they allow specifying a network. Adding the ResolveXxx functions as methods will allow a net.Resolver to fully replace the global DNS functions.

@gopherbot gopherbot added this to the Proposal milestone Feb 28, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 28, 2019

CC @mikioh @bradfitz @ianlancetaylor for net

@bcmills bcmills added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 28, 2019
@bradfitz
Copy link
Contributor

I'm fine with that on principle. I'd never noticed you couldn't do IPv4- vs IPv6-specific lookups on Resolver before. That is, you can't do the equivalent of this today on Resolver:

func main() {
        fmt.Println(net.ResolveIPAddr("ip4", "google.com"))
        fmt.Println(net.ResolveIPAddr("ip6", "google.com"))
}

The name Resolver.ResolveIPAddr is a bit stuttery but probably best for consistency. But I'd also be fine with Resolver.LookupNetIPAddr or something.

@rsc
Copy link
Contributor

rsc commented Mar 6, 2019

It's unclear why we should add net.Resolver.ResolveIPAddr; why not just use LookupIPAddr and filter out what you want? ResolveIPAddr is just LookupIPAddr plus client-side filtering anyway. It's not any fewer bits on the wire.

@iangudger
Copy link
Contributor Author

Sure, it can be done, but it would be nice to not make everyone who wants it re-implement it.

@bradfitz
Copy link
Contributor

I'm inclined to add this. @rsc, it is fewer bytes on the wire, in both directions: only asking for A or AAAA instead of both, and only getting answers for what we asked for.

@rsc
Copy link
Contributor

rsc commented Apr 24, 2019

Today we have:

func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, error)

We need a new name for the function that takes a network. It would be good to keep the Lookup prefix common to all the other methods.

Maybe it would be enough to shorten to "LookupIP":

func (r *Resolver) LookupIP(ctx context.Context, net, host string) ([]IPAddr, error)

where net is either "ip4" or "ip6".

Do we really need IPAddr in the return type vs plain IP? Can DNS return a zone?

@rsc
Copy link
Contributor

rsc commented May 7, 2019

@iangudger, any thoughts on the questions in the previous comment? If that API is OK then I think we're close to accepting the proposal. Thanks for your help and your patience.

@iangudger
Copy link
Contributor Author

Sounds good to me.

@andybons andybons changed the title proposal: net: add (*Resolver).ResolveIPAddr net: add (*Resolver).ResolveIPAddr May 14, 2019
@andybons andybons modified the milestones: Proposal, Go1.14 May 14, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@odeke-em
Copy link
Member

odeke-em commented Apr 9, 2020

Howdy @iangudger, kindly pinging you as this proposal was approved almost a year ago. The Go tree closes in 3 weeks so if we’d like to see this for Go1.15, we’ve got a window of opportunity. Thank you!

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/228641 mentions this issue: net: add (*Resolver).LookupIP

@odeke-em
Copy link
Member

@rsc, @iangudger @bradfitz @andybons and @golang/proposal-review, I just gave @iangudger a code review in https://go-review.googlesource.com/c/go/+/228641/ and I realized that perhaps the name that we
considered has a couple of problems:
a) There already exists a package level LookuIP; by convention we previously had package level functions that invoked the respectively named methods on the DefaultResolveer
b) The package level ResolveIPAddr(network, address string) (*IPAddr, error) has a signature that returns only a single IPAddr pointer so even a Resolver based ResolveIPAddr of signature (r *Resolver) LookupIP(ctx context.Context, network, host string) ([]IPAddr, error) would be inconsistent, and the name is also stuttery as @bradfitz pointed out

I think @bradfitz's suggestion in #30452 (comment) of

Resolver.LookupNetIPAddr(ctx context.Context, network, host string) ([]IPAddr, error)

might be the best suited, or

Resolver.LookupIPAddrByNetwork(ctx context.Context, network, host string) ([]IPAddr, error)

would suffice. The code otherwise LGTM, but I think that the name will make or break us and inconsistencies might make it harder later on for users to navigate through the net package.

Thank you.

@iangudger
Copy link
Contributor Author

Ping @rsc, @bradfitz, @andybons and @golang/proposal-review.

@bradfitz
Copy link
Contributor

We never got an answer on @rsc's question:

Do we really need IPAddr in the return type vs plain IP? Can DNS return a zone?

If not, then we could just return []IP instead of []IPAddr and then its name LookupIP matches func LookupIP(host string) ([]IP, error) except for the addition of context + network which seems fine.

@iangudger
Copy link
Contributor Author

AAAA records cannot contain a zone, so I think []IP should be fine.

@bradfitz
Copy link
Contributor

Phew. That's what I thought & hoped. (Was worried I missed some RFC.)

Let's go with []IP then.

gopherbot pushed a commit that referenced this issue Apr 28, 2020
Previously, looking up only IPv4 or IPv6 addresses was only possible
with DefaultResolver via ResolveIPAddr. Add this functionality to the
Resolver type with a new method, LookupIP. This largely brings Resolver
functionally to parity with the global functions. The name LookupIP is
used over ResolveIPAddr to be consistent with the other Resolver
methods.

There are two main benefits to (*Resolver).LookupIP over
(*Resolver).LookupHost. First is an ergonomic benefit. Wanting a
specific family of address is common enough to justify a method, evident
by the existence of ResolveIPAddr. Second, this opens the possibility of
not performing unnecessary DNS requests when only a specific family of
addresses are needed. This optimization is left to follow up work.

Updates #30452

Change-Id: I241f61019588022a39738f8920b0ddba900cecdd
Reviewed-on: https://go-review.googlesource.com/c/go/+/228641
Reviewed-by: Brad Fitzpatrick <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
xujianhai666 pushed a commit to xujianhai666/go-1 that referenced this issue May 21, 2020
Previously, looking up only IPv4 or IPv6 addresses was only possible
with DefaultResolver via ResolveIPAddr. Add this functionality to the
Resolver type with a new method, LookupIP. This largely brings Resolver
functionally to parity with the global functions. The name LookupIP is
used over ResolveIPAddr to be consistent with the other Resolver
methods.

There are two main benefits to (*Resolver).LookupIP over
(*Resolver).LookupHost. First is an ergonomic benefit. Wanting a
specific family of address is common enough to justify a method, evident
by the existence of ResolveIPAddr. Second, this opens the possibility of
not performing unnecessary DNS requests when only a specific family of
addresses are needed. This optimization is left to follow up work.

Updates golang#30452

Change-Id: I241f61019588022a39738f8920b0ddba900cecdd
Reviewed-on: https://go-review.googlesource.com/c/go/+/228641
Reviewed-by: Brad Fitzpatrick <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
@tmthrgd
Copy link
Contributor

tmthrgd commented May 24, 2020

Should CL 228641 have closed this issue?

@ianlancetaylor
Copy link
Contributor

As far as I can tell, this is done. Thanks.

@golang golang locked and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal Proposal-Accepted
Projects
None yet
Development

No branches or pull requests

9 participants