diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index b6747c9f0..4e0622e96 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -875,6 +875,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm c.mu.Unlock() log.Println("MAPRESPONSE: ", resp.Node) + c.logf("MAPRESPONSE: %v", resp.Node) cb(nm) } if ctx.Err() != nil { diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 2c2581b23..644e53335 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -749,6 +749,9 @@ type MapRequest struct { // * "minimize-netmap": have control minimize the netmap, removing // peers that are unreachable per ACLS. DebugFlags []string `json:",omitempty"` + + // Basic boolean field to determine if a Ping is being intitiated + Ping bool } // PortRange represents a range of UDP or TCP port numbers. diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index 4b886eea7..4a6fb0290 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -754,3 +754,12 @@ func TestTwoNodePing(t *testing.T) { d1.MustCleanShutdown(t) d2.MustCleanShutdown(t) } + +// Tests if our addPingRequest function works +func TestAddPingRequest(t *testing.T) { +} + +// Test such that we can simulate the ping instead of hardcoding in the map response +func TestControlSelectivePing(t *testing.T) { + +} diff --git a/tstest/integration/testcontrol/testcontrol.go b/tstest/integration/testcontrol/testcontrol.go index ae00f9f73..f2c8b5ae6 100644 --- a/tstest/integration/testcontrol/testcontrol.go +++ b/tstest/integration/testcontrol/testcontrol.go @@ -373,6 +373,24 @@ func (s *Server) updateLocked(source string, peers []tailcfg.NodeID) { } } +// Adds a PingRequest to a MapResponse, we will ping the first peer. +func (s *Server) addPingRequest(res *tailcfg.MapResponse) error { + if len(res.Peers) == 0 { + return errors.New("MapResponse has no peers to ping") + } + + if len(res.Peers[0].Addresses) == 0 || len(res.Peers[0].AllowedIPs) == 0 { + return errors.New("peer has no Addresses or no AllowedIPs") + } + targetIP := res.Peers[0].AllowedIPs[0].IP() + res.PingRequest = &tailcfg.PingRequest{URL: s.BaseURL + "/ping", TestIP: targetIP, Types: "tsmp"} + jsonRes, _ := json.MarshalIndent(res, "", " ") + log.Println("jsonprint", string(jsonRes)) + log.Println("respeers", res.Peers) + log.Println("allnodes", s.AllNodes(), res.Node.AllowedIPs) + return nil +} + // sendUpdate sends updateType to dst if dst is non-nil and // has capacity. func sendUpdate(dst chan<- updateType, updateType updateType) { @@ -456,6 +474,9 @@ func (s *Server) serveMap(w http.ResponseWriter, r *http.Request, mkey tailcfg.M streaming := req.Stream && !req.ReadOnly compress := req.Compress != "" + log.Println("CREATED MAPREQ", *req) + log.Println("REQUEST", r) + log.Println("REQBODY", r.Body) w.WriteHeader(200) for { res, err := s.MapResponse(req) @@ -548,12 +569,12 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse, } res.Node.AllowedIPs = res.Node.Addresses - // Optional Ping Request, hardcode address for now, in the two nodes example we are accessing node4. - res.PingRequest = &tailcfg.PingRequest{URL: s.BaseURL + "/ping", TestIP: netaddr.IPv4(100, 64, 0, 1), Types: "tsmp"} - jsonRes, _ := json.MarshalIndent(res, "", " ") - log.Println("jsonprint", string(jsonRes)) - log.Println("respeers", res.Peers) - log.Println("allnodes", s.AllNodes(), res.Node.AllowedIPs) + // Function to add a PingRequest to one of its Peers to the MapResponse + err = s.addPingRequest(res) + if err != nil { + log.Println("ADDPINGREQ ERROR", err) + } + return res, nil } @@ -720,8 +741,3 @@ func (s *Server) receivePingInfo(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) io.WriteString(w, "Ping Streamed Back : "+string(reqBody)) } - -// TODO -// We want it such that we can add a pingrequest to a mapresponse instead of hard coding it. -func (s *Server) AddPingRequest() { -}