wgengine/magicsock: use netaddr more

In prep for deleting from the ever-growing maps.
pull/308/head
Brad Fitzpatrick 5 years ago
parent 6fb30ff543
commit 7fc97c5493

@ -28,6 +28,6 @@ require (
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
gortc.io/stun v1.22.1
inet.af/netaddr v0.0.0-20200417204647-17eccff2620c
inet.af/netaddr v0.0.0-20200417213433-f9e5bcc2d6ea
rsc.io/goversion v1.2.0
)

@ -151,5 +151,9 @@ inet.af/netaddr v0.0.0-20200417144406-01f6d1b213c8 h1:flBh+hqli1lALDWbRAkX2Cs7QS
inet.af/netaddr v0.0.0-20200417144406-01f6d1b213c8/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww=
inet.af/netaddr v0.0.0-20200417204647-17eccff2620c h1:MzkYVBmOE/xWhdLv/R4ycVJ2On0j00w5gtboXBIqnE8=
inet.af/netaddr v0.0.0-20200417204647-17eccff2620c/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww=
inet.af/netaddr v0.0.0-20200417205003-27c4b435b671 h1:rZdhNZoQfq9HLsGYWHYkNNa2hnSMH2wu0VdXZDA3mXs=
inet.af/netaddr v0.0.0-20200417205003-27c4b435b671/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww=
inet.af/netaddr v0.0.0-20200417213433-f9e5bcc2d6ea h1:DpXewrGVf9+vvYQFrNGj9v34bXMuTVQv+2wuULTNV8I=
inet.af/netaddr v0.0.0-20200417213433-f9e5bcc2d6ea/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww=
rsc.io/goversion v1.2.0 h1:SPn+NLTiAG7w30IRK/DKp1BjvpWabYgxlLp/+kx5J8w=
rsc.io/goversion v1.2.0/go.mod h1:Eih9y/uIBS3ulggl7KNJ09xGSLcuNaLgmvvqa07sgfo=

@ -1514,6 +1514,7 @@ type AddrSet struct {
//
// But there could be multiple or none of each.
addrs []net.UDPAddr
ipPorts []netaddr.IPPort // same as addrs, in different form
// clock, if non-nil, is used in tests instead of time.Now.
clock func() time.Time
@ -1748,12 +1749,17 @@ func (c *Conn) CreateEndpoint(key [32]byte, addrs string) (conn.Endpoint, error)
if addrs != "" {
for _, ep := range strings.Split(addrs, ",") {
addr, err := net.ResolveUDPAddr("udp", ep)
ua, err := net.ResolveUDPAddr("udp", ep)
if err != nil {
return nil, err
}
addr.IP = ip4or6(addr.IP)
a.addrs = append(a.addrs, *addr)
ipp, ok := netaddr.FromStdAddr(ua.IP, ua.Port, ua.Zone)
if !ok {
return nil, fmt.Errorf("bogus address %q", ep)
}
ua.IP = ipp.IP.IPAddr().IP // makes IPv4 addresses 4 bytes long
a.ipPorts = append(a.ipPorts, ipp)
a.addrs = append(a.addrs, *ua)
}
}
@ -1903,13 +1909,6 @@ func peerShort(k key.Public) string {
return k2.ShortString()
}
func ip4or6(ip net.IP) net.IP {
if ip4 := ip.To4(); ip4 != nil {
return ip4
}
return ip
}
func sbPrintAddr(sb *strings.Builder, a net.UDPAddr) {
is6 := a.IP.To4() == nil
if is6 {

Loading…
Cancel
Save