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/v2: meta bug for v2 changes #28900

Open
bradfitz opened this issue Nov 20, 2018 · 9 comments
Open

net/v2: meta bug for v2 changes #28900

bradfitz opened this issue Nov 20, 2018 · 9 comments
Labels
v2 An incompatible library change
Milestone

Comments

@bradfitz
Copy link
Contributor

This is a meta/index bug for things we might change in a possible future net/v2 (~ "Go 2") package, including both links to other issues, or just comments with API problems/cleanups that are too little to warrant their own bugs.

(This is not about net/http, net/mail, net/rpc, net/smtp, net/nextproto, or net/url. Those should have their own bugs if/when needed.)

@bradfitz bradfitz added the v2 An incompatible library change label Nov 20, 2018
@bradfitz
Copy link
Contributor Author

There's probably at least 1 too many ways to read from a UDP Conn:

go1.txt:pkg net, method (*UDPConn) Read([]uint8) (int, error)
go1.txt:pkg net, method (*UDPConn) ReadFrom([]uint8) (int, Addr, error)
go1.txt:pkg net, method (*UDPConn) ReadFromUDP([]uint8) (int, *UDPAddr, error)
go1.1.txt:pkg net, method (*UDPConn) ReadMsgUDP([]uint8, []uint8) (int, int, int, *UDPAddr, error)

Likewise with UnixConn and IPConn.

And maybe they're still not sufficient because it says at:

https://golang.org/pkg/net/#UDPConn.ReadMsgUDP

The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob.

Maybe we can get it right in one place and remove some of the redundant ones.

@bradfitz
Copy link
Contributor Author

@cespare
Copy link
Contributor

cespare commented Nov 20, 2018

Also the more general

@networkimprov
Copy link

This is now tagged for 1.13, but has been open since 2012

@ianlancetaylor ianlancetaylor added this to the Proposal milestone Dec 11, 2018
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 11, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Go2 Dec 11, 2018
@mikioh
Copy link
Contributor

mikioh commented Feb 22, 2019

A few things in my mind, though each of these must be an individual proposal and I still have no concrete draft-proposals yet:

  1. A buffering mechanism between packages close to users and packages close to protocol stacks, for example, the packages net/http, crypto/tls and net. The motivation behind this is, a) to achieve efficient layered buffering interacting with transport-layer protocol properties, as in, link/path MTUs and capsulation overhead, b) to provide a way to handle both partial reads/writes on connection-oriented protocols and message reads/writes on connection-less protocols seamlessly, to help applications using io.Reader interface over datagram/message-based protocols.

  2. A printer for network-specific types, for example, net.IP and net.HardwareAddr. The motivation behind this is to provide a way to control various output forms of the types for people who need to work on systems using pipelines of various text forms.

@cristaloleg
Copy link

@networkimprov
Copy link

@mateusz834
Copy link
Member

mateusz834 commented Jul 20, 2024

Few thoughts after my contributions to the net package:

func LookupCNAME(string) ([]string, error) {/*...*/}

// Struct, insted of returning multiple values in LookupHostInfo, so that we can add more field in the future.
type HostInfo struct {
    Addrs         []netip.Addr
    CanonicalName string
}

func LookupHostInfo(string) (HostInfo, error) {/*...*/}

func LookupCanonicalName(h string) (string, error) {
    hi, err := LookupHostInfo(h)
    if err != nil {
        return "", err
    }
    return hi.CanonicalName, nil
}
  • network is passed as a string, should be a special type, like:
type Network uint8

const (
    NetworkUDP Network = iota
    NetworkUDP4
    NetworkUDP6
    NetworkTCP
    NetworkTCP4
    NetworkTCP6

    // ....
)
  • We have bunch of methods for resolving hostnames to IP Addresses (LookupHost, LookupIP, LookupIPAddr, LookupNetIP), there should be exactly one:
func LookupIP(network Network, host string) ([]netip.Addr, error) {
    hi, err := LookupHostInfo(h)
    if err != nil {
        return nil, err
    }
    return hi.Addrs, nil
}
  • support all DNS names, not just Preferred name syntax https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.1 (with escapes).

  • remove Err, IsTimeout, IsTemporary, IsNotFound fields from the DNSError, leave methods for retrieving them from the unwrapErr. Make all fields unexported, name and server are usefull for constructing nice-error message, but not sure how useful they are in real code (we can even make the DNSError unexported).

type DNSError struct {
    name      string
    server    netip.Addr
    unwrapErr error
}

Keep the bevhaviour of only returing few error conditions in Unwrap, this logic is moved into the Unwrap method:

go/src/net/net.go

Lines 686 to 690 in 3959d54

// At this time, the only errors we wrap are context errors, to allow
// users to check for canceled/timed out requests.
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
unwrapErr = err
}

Instead of the IsNotFound field, define a global error and return it through the (*DNSError).Unwrap method. It would be then used as errors.Is(err, net.ErrHostNotFound).

    ErrHostNotFound = errors.New("no such host")
  • remove unused error types, like: DNSConfigError.

  • DefaultResolver should be an unexported atomic.Pointer with a global getter and setter.

@ianlancetaylor ianlancetaylor changed the title net: meta bug for Go2 changes net/v2: meta bug for v2 changes Aug 6, 2024
@ianlancetaylor ianlancetaylor removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 6, 2024
@ianlancetaylor ianlancetaylor modified the milestones: Go2, Proposal Aug 6, 2024
@mohammed90
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

8 participants