From 313a129fe57b2d9768c4a3a0a0cf0348295cd279 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 30 Aug 2023 13:34:22 -0700 Subject: [PATCH] control/controlclient: use slices package more Updates #cleanup Change-Id: Ic17384266dc59bc4e710efdda311d6e0719529da Signed-off-by: Brad Fitzpatrick --- control/controlclient/direct.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index f999e4c50..34d3eb147 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -22,6 +22,7 @@ import ( "os" "reflect" "runtime" + "slices" "strings" "sync" "sync/atomic" @@ -736,18 +737,6 @@ func resignNKS(priv key.NLPrivate, nodeKey key.NodePublic, oldNKS tkatype.Marsha return newSig.Serialize(), nil } -func sameEndpoints(a, b []tailcfg.Endpoint) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true -} - // newEndpoints acquires c.mu and sets the local port and endpoints and reports // whether they've changed. // @@ -757,15 +746,11 @@ func (c *Direct) newEndpoints(endpoints []tailcfg.Endpoint) (changed bool) { defer c.mu.Unlock() // Nothing new? - if sameEndpoints(c.endpoints, endpoints) { + if slices.Equal(c.endpoints, endpoints) { return false // unchanged } - var epStrs []string - for _, ep := range endpoints { - epStrs = append(epStrs, ep.Addr.String()) - } - c.logf("[v2] client.newEndpoints(%v)", epStrs) - c.endpoints = append(c.endpoints[:0], endpoints...) + c.logf("[v2] client.newEndpoints(%v)", endpoints) + c.endpoints = slices.Clone(endpoints) return true // changed }