From 0e728a7a9ba837dd9fb16063c42653c1bf4a99fc Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Tue, 11 Feb 2025 22:36:13 +1100 Subject: [PATCH] chore(vpn/tunnel): sort outgoing fqdns by length (#16520) On the Mac app, we want to display the shortest FQDN - we might as well do the sorting as they leave the tunnel. Right now it's coming from a map, so it's they arrive in a random order each peer update. --- vpn/tunnel.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vpn/tunnel.go b/vpn/tunnel.go index b33dd5b084..4ed21ab026 100644 --- a/vpn/tunnel.go +++ b/vpn/tunnel.go @@ -10,6 +10,7 @@ import ( "net/netip" "net/url" "reflect" + "sort" "strconv" "sync" "time" @@ -402,6 +403,9 @@ func (u *updater) createPeerUpdateLocked(update tailnet.WorkspaceUpdate) *PeerUp for name := range agent.Hosts { fqdn = append(fqdn, name.WithTrailingDot()) } + sort.Slice(fqdn, func(i, j int) bool { + return len(fqdn[i]) < len(fqdn[j]) + }) out.DeletedAgents[i] = &Agent{ Id: tailnet.UUIDToByteSlice(agent.ID), Name: agent.Name, @@ -424,6 +428,9 @@ func (u *updater) convertAgentsLocked(agents []*tailnet.Agent) []*Agent { for name := range agent.Hosts { fqdn = append(fqdn, name.WithTrailingDot()) } + sort.Slice(fqdn, func(i, j int) bool { + return len(fqdn[i]) < len(fqdn[j]) + }) protoAgent := &Agent{ Id: tailnet.UUIDToByteSlice(agent.ID), Name: agent.Name,