From 49e733773c7b23025798afa6244f836780b9a0c4 Mon Sep 17 00:00:00 2001 From: Simeng He Date: Thu, 13 May 2021 13:48:52 -0400 Subject: [PATCH] Put placeholder code for the customping --- control/controlclient/direct.go | 18 ++++++++++++++++-- control/controlclient/direct_test.go | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index dfdce39c5..3a194b499 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -765,7 +765,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm if pr := resp.PingRequest; pr != nil { log.Println("Ping Triggered") - go CustomPing(&resp) + go c.CustomPing(&resp) // go answerPing(c.logf, c.httpc, pr) } @@ -1220,8 +1220,22 @@ func sleepAsRequested(ctx context.Context, logf logger.Logf, timeoutReset chan<- // Run the ping suite from this client to another one // Send the ping results via http to the adminhttp handlers. -func CustomPing(mr *tailcfg.MapResponse) bool { +// This is where we hopefully will run the ping suite similar to CLI +func (c *Direct) CustomPing(mr *tailcfg.MapResponse) bool { log.Printf("Custom Ping Triggered with %d number of peers\n", len(mr.Peers)) log.Println(mr.PingRequest) + start := time.Now() + // Run the ping + time.Sleep(10 * time.Millisecond) + duration := time.Since(start) + url := "urlplaceholder" + // Temporary place holder for something we would stream back + pingres := &tailcfg.StreamedPingResult{ + IP: mr.PingRequest.TestIP, + Seconds: duration.Seconds(), + } + body, _ := json.Marshal(pingres) + resp, _ := c.httpc.Post(url, "application/json", bytes.NewBuffer(body)) + defer resp.Body.Close() return len(mr.Peers) > 0 } diff --git a/control/controlclient/direct_test.go b/control/controlclient/direct_test.go index 8fbe55aea..2a6689c48 100644 --- a/control/controlclient/direct_test.go +++ b/control/controlclient/direct_test.go @@ -134,5 +134,5 @@ func TestPingFromMapResponse(t *testing.T) { if !CustomPing(mr) { t.Errorf("Custom ping failed!\n") } - t.Log("Successfull ping") + t.Log("Successful ping") }