diff --git a/internal/deephash/deephash.go b/internal/deephash/deephash.go index fcbd59601..3d94292d1 100644 --- a/internal/deephash/deephash.go +++ b/internal/deephash/deephash.go @@ -19,18 +19,18 @@ import ( "tailscale.com/types/wgkey" ) -func Hash(v ...interface{}) string { +func calcHash(v interface{}) string { h := sha256.New() // 64 matches the chunk size in crypto/sha256/sha256.go b := bufio.NewWriterSize(h, 64) - Print(b, v) + printTo(b, v) b.Flush() return fmt.Sprintf("%x", h.Sum(nil)) } // UpdateHash sets last to the hash of v and reports whether its value changed. func UpdateHash(last *string, v ...interface{}) (changed bool) { - sig := Hash(v) + sig := calcHash(v) if *last != sig { *last = sig return true @@ -38,7 +38,7 @@ func UpdateHash(last *string, v ...interface{}) (changed bool) { return false } -func Print(w *bufio.Writer, v ...interface{}) { +func printTo(w *bufio.Writer, v interface{}) { print(w, reflect.ValueOf(v), make(map[uintptr]bool)) } diff --git a/internal/deephash/deephash_test.go b/internal/deephash/deephash_test.go index 1442b1ba5..af408e4f3 100644 --- a/internal/deephash/deephash_test.go +++ b/internal/deephash/deephash_test.go @@ -18,15 +18,15 @@ import ( "tailscale.com/wgengine/wgcfg" ) -func TestDeepPrint(t *testing.T) { +func TestDeepHash(t *testing.T) { // v contains the types of values we care about for our current callers. // Mostly we're just testing that we don't panic on handled types. v := getVal() - hash1 := Hash(v) + hash1 := calcHash(v) t.Logf("hash: %v", hash1) for i := 0; i < 20; i++ { - hash2 := Hash(getVal()) + hash2 := calcHash(getVal()) if hash1 != hash2 { t.Error("second hash didn't match") } @@ -80,7 +80,7 @@ func BenchmarkHash(b *testing.B) { b.ReportAllocs() v := getVal() for i := 0; i < b.N; i++ { - Hash(v) + calcHash(v) } }