summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-05-11 10:44:15 -0700
committerJosh Bleecher Snyder <josh@tailscale.com>2021-05-11 12:20:30 -0700
commitf858bfd61b813ed9379b8a8b3d66c71f9c2909e1 (patch)
tree6fc23e4b64ff880c9c55e21b193f4407b4f68178
parent6ab2176dc75176a8b1a8efb17c444d9197f10be6 (diff)
downloadtailscale-josh/opt-dp-wip.tar.xz
tailscale-josh/opt-dp-wip.zip
internal/deepprint: handle common map types speciallyjosh/opt-dp-wip
-rw-r--r--internal/deepprint/deepprint.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/deepprint/deepprint.go b/internal/deepprint/deepprint.go
index d2be04440..c0d31064c 100644
--- a/internal/deepprint/deepprint.go
+++ b/internal/deepprint/deepprint.go
@@ -16,10 +16,12 @@ import (
"crypto/sha256"
"fmt"
"reflect"
+ "sort"
"inet.af/netaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/wgkey"
+ "tailscale.com/util/dnsname"
)
func Hash(v ...interface{}) string {
@@ -51,6 +53,8 @@ var (
wgkeyKeyType = reflect.TypeOf(wgkey.Key{})
wgkeyPrivateType = reflect.TypeOf(wgkey.Private{})
tailcfgDiscoKeyType = reflect.TypeOf(tailcfg.DiscoKey{})
+ mapFQDNIPType = reflect.TypeOf(map[dnsname.FQDN][]netaddr.IP{})
+ mapFQDNIPPortType = reflect.TypeOf(map[dnsname.FQDN][]netaddr.IPPort{})
)
func print(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) {
@@ -116,6 +120,44 @@ func print(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) {
w.Write(x[:])
}
return
+ case mapFQDNIPType:
+ x := v.Interface().(map[dnsname.FQDN][]netaddr.IP)
+ keys := make([]dnsname.FQDN, 0, len(x))
+ for k := range x {
+ keys = append(keys, k)
+ }
+ sort.Slice(keys, func(i, j int) bool { return string(keys[i]) < string(keys[j]) })
+ fmt.Fprintf(w, "map[%d]{\n", len(x))
+ for _, k := range keys {
+ w.WriteString(string(k))
+ w.WriteString(": ")
+ for _, ip := range x[dnsname.FQDN(k)] {
+ b, _ := ip.MarshalText()
+ w.Write(b)
+ w.WriteString(",")
+ }
+ }
+ w.WriteString("}\n")
+ return
+ case mapFQDNIPPortType:
+ x := v.Interface().(map[dnsname.FQDN][]netaddr.IPPort)
+ keys := make([]dnsname.FQDN, 0, len(x))
+ for k := range x {
+ keys = append(keys, k)
+ }
+ sort.Slice(keys, func(i, j int) bool { return string(keys[i]) < string(keys[j]) })
+ fmt.Fprintf(w, "map[%d]{\n", len(x))
+ for _, k := range keys {
+ w.WriteString(string(k))
+ w.WriteString(": ")
+ for _, ipp := range x[dnsname.FQDN(k)] {
+ b, _ := ipp.MarshalText()
+ w.Write(b)
+ w.WriteString(",")
+ }
+ }
+ w.WriteString("}\n")
+ return
}
}