Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e728a7

Browse files
chore(vpn/tunnel): sort outgoing fqdns by length (coder#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.
1 parent 4867cbe commit 0e728a7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vpn/tunnel.go

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/netip"
1111
"net/url"
1212
"reflect"
13+
"sort"
1314
"strconv"
1415
"sync"
1516
"time"
@@ -402,6 +403,9 @@ func (u *updater) createPeerUpdateLocked(update tailnet.WorkspaceUpdate) *PeerUp
402403
for name := range agent.Hosts {
403404
fqdn = append(fqdn, name.WithTrailingDot())
404405
}
406+
sort.Slice(fqdn, func(i, j int) bool {
407+
return len(fqdn[i]) < len(fqdn[j])
408+
})
405409
out.DeletedAgents[i] = &Agent{
406410
Id: tailnet.UUIDToByteSlice(agent.ID),
407411
Name: agent.Name,
@@ -424,6 +428,9 @@ func (u *updater) convertAgentsLocked(agents []*tailnet.Agent) []*Agent {
424428
for name := range agent.Hosts {
425429
fqdn = append(fqdn, name.WithTrailingDot())
426430
}
431+
sort.Slice(fqdn, func(i, j int) bool {
432+
return len(fqdn[i]) < len(fqdn[j])
433+
})
427434
protoAgent := &Agent{
428435
Id: tailnet.UUIDToByteSlice(agent.ID),
429436
Name: agent.Name,

0 commit comments

Comments
 (0)