wgengine/magicsock: simplify legacy endpoint DstToString

Legacy endpoints (addrSet) currently reconstruct their dst string when requested.

Instead, store the dst string we were given to begin with.
In addition to being simpler and cheaper, this makes less code
aware of how to interpret endpoint strings.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/1874/head
Josh Bleecher Snyder 4 years ago
parent 777c816b34
commit a0dacba877

@ -43,6 +43,7 @@ func (c *Conn) createLegacyEndpointLocked(pk key.Public, addrs string) (conn.End
Logf: c.logf, Logf: c.logf,
publicKey: pk, publicKey: pk,
curAddr: -1, curAddr: -1,
rawdst: addrs,
} }
if addrs != "" { if addrs != "" {
@ -384,6 +385,9 @@ type addrSet struct {
// set to a better one. This is only to suppress some // set to a better one. This is only to suppress some
// redundant logs. // redundant logs.
loggedLogPriMask uint32 loggedLogPriMask uint32
// rawdst is the destination string from/for wireguard-go.
rawdst string
} }
// derpID returns this addrSet's home DERP node, or 0 if none is found. // derpID returns this addrSet's home DERP node, or 0 if none is found.
@ -426,17 +430,7 @@ func (a *addrSet) DstToBytes() []byte {
return packIPPort(a.dst()) return packIPPort(a.dst())
} }
func (a *addrSet) DstToString() string { func (a *addrSet) DstToString() string {
var addrs []string return a.rawdst
for _, addr := range a.ipPorts {
addrs = append(addrs, addr.String())
}
a.mu.Lock()
defer a.mu.Unlock()
if a.roamAddr != nil {
addrs = append(addrs, a.roamAddr.String())
}
return strings.Join(addrs, ",")
} }
func (a *addrSet) DstIP() net.IP { func (a *addrSet) DstIP() net.IP {
return a.dst().IP.IPAddr().IP // TODO: add netaddr accessor to cut an alloc here? return a.dst().IP.IPAddr().IP // TODO: add netaddr accessor to cut an alloc here?

Loading…
Cancel
Save