mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
ipn/ipnlocal: add peerapi goroutine fetch
Between owners. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
5835a3f553
commit
86e85d8934
@ -401,6 +401,10 @@ func (h *peerAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.handlePeerPut(w, r)
|
h.handlePeerPut(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if r.URL.Path == "/v0/goroutines" {
|
||||||
|
h.handleServeGoroutines(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
who := h.peerUser.DisplayName
|
who := h.peerUser.DisplayName
|
||||||
fmt.Fprintf(w, `<html>
|
fmt.Fprintf(w, `<html>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
@ -582,3 +586,19 @@ func approxSize(n int64) string {
|
|||||||
}
|
}
|
||||||
return fmt.Sprintf("~%dMB", n>>20)
|
return fmt.Sprintf("~%dMB", n>>20)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *peerAPIHandler) handleServeGoroutines(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !h.isSelf {
|
||||||
|
http.Error(w, "not owner", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var buf []byte
|
||||||
|
for size := 4 << 10; size <= 2<<20; size *= 2 {
|
||||||
|
buf = make([]byte, size)
|
||||||
|
buf = buf[:runtime.Stack(buf, true)]
|
||||||
|
if len(buf) < size {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.Write(buf)
|
||||||
|
}
|
||||||
|
@ -103,7 +103,7 @@ func hexAll(v string) string {
|
|||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandlePeerPut(t *testing.T) {
|
func TestHandlePeerAPI(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
isSelf bool // the peer sending the request is owned by us
|
isSelf bool // the peer sending the request is owned by us
|
||||||
@ -134,6 +134,21 @@ func TestHandlePeerPut(t *testing.T) {
|
|||||||
bodyNotContains("You are the owner of this node."),
|
bodyNotContains("You are the owner of this node."),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "peer_api_goroutines_deny",
|
||||||
|
isSelf: false,
|
||||||
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
||||||
|
checks: checks(httpStatus(403)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "peer_api_goroutines",
|
||||||
|
isSelf: true,
|
||||||
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
||||||
|
checks: checks(
|
||||||
|
httpStatus(200),
|
||||||
|
bodyContains("ServeHTTP"),
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "reject_non_owner_put",
|
name: "reject_non_owner_put",
|
||||||
isSelf: false,
|
isSelf: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user