From 41c456059217a91cc3c50ee0f512f66d384d9e9b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 6 Aug 2020 10:23:16 -0700 Subject: [PATCH] control/controlclient: remove unused NetworkMap.UAPI method And remove last remaining use of wgcfg.ToUAPI in a test's debug output; replace it with JSON. --- control/controlclient/netmap.go | 15 --------------- wgengine/magicsock/magicsock_test.go | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/control/controlclient/netmap.go b/control/controlclient/netmap.go index d1a0b9d37..422feafbf 100644 --- a/control/controlclient/netmap.go +++ b/control/controlclient/netmap.go @@ -7,7 +7,6 @@ package controlclient import ( "encoding/json" "fmt" - "log" "net" "reflect" "strconv" @@ -223,20 +222,6 @@ const ( HackDefaultRoute ) -// TODO(bradfitz): UAPI seems to only be used by the old confnode and -// pingnode; delete this when those are deleted/rewritten? -func (nm *NetworkMap) UAPI(flags WGConfigFlags) string { - wgcfg, err := nm.WGCfg(log.Printf, flags) - if err != nil { - log.Fatalf("WGCfg() failed unexpectedly: %v", err) - } - s, err := wgcfg.ToUAPI() - if err != nil { - log.Fatalf("ToUAPI() failed unexpectedly: %v", err) - } - return s -} - // EndpointDiscoSuffix is appended to the hex representation of a peer's discovery key // and is then the sole wireguard endpoint for peers with a non-zero discovery key. // This form is then recognize by magicsock's CreateEndpoint. diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index d42d837f7..2187d0d1a 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -10,12 +10,14 @@ import ( crand "crypto/rand" "crypto/tls" "encoding/binary" + "encoding/json" "fmt" "io/ioutil" "net" "net/http" "net/http/httptest" "os" + "strconv" "strings" "sync" "testing" @@ -927,7 +929,7 @@ func testTwoDevicePing(t *testing.T, d *devices) { }) // TODO: Remove this once the following tests are reliable. - if os.Getenv("RUN_CURSED_TESTS") == "" { + if run, _ := strconv.ParseBool(os.Getenv("RUN_CURSED_TESTS")); !run { t.Skip("skipping following tests because RUN_CURSED_TESTS is not set.") } @@ -1025,10 +1027,8 @@ func testTwoDevicePing(t *testing.T, d *devices) { defer setT(outerT) defer func() { if t.Failed() || true { - uapi1, _ := cfgs[0].ToUAPI() - logf("cfg0: %v", uapi1) - uapi2, _ := cfgs[1].ToUAPI() - logf("cfg1: %v", uapi2) + logf("cfg0: %v", stringifyConfig(cfgs[0])) + logf("cfg1: %v", stringifyConfig(cfgs[1])) } }() pingSeq(t, 20, 0, true) @@ -1314,3 +1314,11 @@ func TestDiscoStringLogRace(t *testing.T) { }() wg.Wait() } + +func stringifyConfig(cfg wgcfg.Config) string { + j, err := json.Marshal(cfg) + if err != nil { + panic(err) + } + return string(j) +}