|
|
@ -7,8 +7,6 @@ import (
|
|
|
|
"bufio"
|
|
|
|
"bufio"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"hash/fnv"
|
|
|
|
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"net/netip"
|
|
|
|
"net/netip"
|
|
|
|
"reflect"
|
|
|
|
"reflect"
|
|
|
@ -16,6 +14,7 @@ import (
|
|
|
|
"sort"
|
|
|
|
"sort"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/tailscale/wireguard-go/conn"
|
|
|
|
"github.com/tailscale/wireguard-go/conn"
|
|
|
|
"tailscale.com/derp"
|
|
|
|
"tailscale.com/derp"
|
|
|
@ -31,6 +30,7 @@ import (
|
|
|
|
"tailscale.com/types/key"
|
|
|
|
"tailscale.com/types/key"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/util/mak"
|
|
|
|
"tailscale.com/util/mak"
|
|
|
|
|
|
|
|
"tailscale.com/util/rands"
|
|
|
|
"tailscale.com/util/sysresources"
|
|
|
|
"tailscale.com/util/sysresources"
|
|
|
|
"tailscale.com/util/testenv"
|
|
|
|
"tailscale.com/util/testenv"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -94,7 +94,6 @@ type activeDerp struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
processStartUnixNano = time.Now().UnixNano()
|
|
|
|
|
|
|
|
pickDERPFallbackForTests func() int
|
|
|
|
pickDERPFallbackForTests func() int
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -136,10 +135,7 @@ func (c *Conn) pickDERPFallback() int {
|
|
|
|
return pickDERPFallbackForTests()
|
|
|
|
return pickDERPFallbackForTests()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: use math/rand/v2 here.
|
|
|
|
return ids[rands.IntN(uint64(uintptr(unsafe.Pointer(c))), len(ids))]
|
|
|
|
h := fnv.New64()
|
|
|
|
|
|
|
|
fmt.Fprintf(h, "%p/%d", c, processStartUnixNano) // arbitrary
|
|
|
|
|
|
|
|
return ids[rand.New(rand.NewSource(int64(h.Sum64()))).Intn(len(ids))]
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This allows existing tests to pass, but allows us to still test the
|
|
|
|
// This allows existing tests to pass, but allows us to still test the
|
|
|
|