diff --git a/cmd/k8s-operator/depaware.txt b/cmd/k8s-operator/depaware.txt index 5e8361175..1f9b38487 100644 --- a/cmd/k8s-operator/depaware.txt +++ b/cmd/k8s-operator/depaware.txt @@ -1099,7 +1099,7 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/ hash from compress/zlib+ hash/adler32 from compress/zlib hash/crc32 from compress/gzip+ - hash/fnv from google.golang.org/protobuf/internal/detrand + hash/fnv from google.golang.org/protobuf/internal/detrand+ hash/maphash from go4.org/mem html from html/template+ html/template from tailscale.com/util/eventbus diff --git a/cmd/tailscaled/depaware-min.txt b/cmd/tailscaled/depaware-min.txt index 9b9003c85..33f7eb744 100644 --- a/cmd/tailscaled/depaware-min.txt +++ b/cmd/tailscaled/depaware-min.txt @@ -335,6 +335,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de fmt from compress/flate+ hash from crypto+ hash/crc32 from compress/gzip+ + hash/fnv from tailscale.com/net/traffic hash/maphash from go4.org/mem html from tailscale.com/ipn/ipnlocal+ internal/abi from hash/maphash+ diff --git a/cmd/tailscaled/depaware-minbox.txt b/cmd/tailscaled/depaware-minbox.txt index 90d410664..e0b07a2c2 100644 --- a/cmd/tailscaled/depaware-minbox.txt +++ b/cmd/tailscaled/depaware-minbox.txt @@ -356,6 +356,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de fmt from compress/flate+ hash from crypto+ hash/crc32 from compress/gzip+ + hash/fnv from tailscale.com/net/traffic hash/maphash from go4.org/mem html from tailscale.com/ipn/ipnlocal+ internal/abi from hash/maphash+ diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 84dde50c1..88c433757 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -665,6 +665,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de hash from compress/zlib+ hash/adler32 from compress/zlib+ hash/crc32 from compress/gzip+ + hash/fnv from tailscale.com/net/traffic hash/maphash from go4.org/mem html from html/template+ html/template from tailscale.com/util/eventbus diff --git a/cmd/tsidp/depaware.txt b/cmd/tsidp/depaware.txt index a5cac442e..46fa27785 100644 --- a/cmd/tsidp/depaware.txt +++ b/cmd/tsidp/depaware.txt @@ -482,6 +482,7 @@ tailscale.com/cmd/tsidp dependencies: (generated by github.com/tailscale/depawar hash from crypto+ W hash/adler32 from compress/zlib hash/crc32 from compress/gzip+ + hash/fnv from tailscale.com/net/traffic hash/maphash from go4.org/mem html from html/template+ html/template from tailscale.com/util/eventbus+ diff --git a/ipn/ipnlocal/local_test.go b/ipn/ipnlocal/local_test.go index d63a8535d..7a1cd1230 100644 --- a/ipn/ipnlocal/local_test.go +++ b/ipn/ipnlocal/local_test.go @@ -5832,8 +5832,8 @@ func TestSuggestExitNodeTrafficSteering(t *testing.T) { }, }, // Change this, if the hashing function changes. - wantID: "stable3", - wantName: "peer3", + wantID: "stable1", + wantName: "peer1", }, { name: "exit-nodes-without-priority-for-suggestions", @@ -5973,8 +5973,9 @@ func TestSuggestExitNodeTrafficSteering(t *testing.T) { withLocationPriority(2)), // top }, }, - wantID: "stable5", - wantName: "peer5", + // Change this, if the hashing function changes. + wantID: "stable2", + wantName: "peer2", wantPri: 2, }, { diff --git a/net/traffic/traffic.go b/net/traffic/traffic.go index 84b3efbfb..c6ef7e19d 100644 --- a/net/traffic/traffic.go +++ b/net/traffic/traffic.go @@ -7,8 +7,8 @@ package traffic import ( "cmp" - "crypto/sha256" "encoding/binary" + "hash/fnv" "iter" "maps" "slices" @@ -107,8 +107,16 @@ func MakeRendezvousHasher(seed tailcfg.NodeID) NodeHasher { var b [16]byte en.PutUint64(b[:], uint64(seed)) en.PutUint64(b[8:], uint64(n)) - v := sha256.Sum256(b[:]) - return en.Uint64(v[:]) + + // FNV-1a is more modern and distributes bits more evenly, + // so it is recommended by the designers. + // + // Note that we don’t use a global hasher and h.Reset + // because this closure could be called concurrently. + // This is cheap because hash/fnv doesn’t need to allocate. + h := fnv.New64a() + h.Write(b[:]) + return h.Sum64() } } diff --git a/tsnet/depaware.txt b/tsnet/depaware.txt index 817043896..c117384aa 100644 --- a/tsnet/depaware.txt +++ b/tsnet/depaware.txt @@ -475,6 +475,7 @@ tailscale.com/tsnet dependencies: (generated by github.com/tailscale/depaware) hash from crypto+ W hash/adler32 from compress/zlib hash/crc32 from compress/gzip+ + hash/fnv from tailscale.com/net/traffic hash/maphash from go4.org/mem html from html/template+ LDW html/template from tailscale.com/util/eventbus