mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-26 18:18:47 +00:00
ipn/ipnlocal: add some verbose logging to taildrive peerapi handler
Updates tailscale/corp#29702 Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:
parent
939355f667
commit
4431fb89c2
@ -247,6 +247,10 @@ func (h *peerAPIHandler) logf(format string, a ...any) {
|
|||||||
h.ps.b.logf("peerapi: "+format, a...)
|
h.ps.b.logf("peerapi: "+format, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *peerAPIHandler) logfv1(format string, a ...any) {
|
||||||
|
h.ps.b.logf("[v1] peerapi: "+format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
// isAddressValid reports whether addr is a valid destination address for this
|
// isAddressValid reports whether addr is a valid destination address for this
|
||||||
// node originating from the peer.
|
// node originating from the peer.
|
||||||
func (h *peerAPIHandler) isAddressValid(addr netip.Addr) bool {
|
func (h *peerAPIHandler) isAddressValid(addr netip.Addr) bool {
|
||||||
@ -1015,6 +1019,7 @@ func (rbw *requestBodyWrapper) Read(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *peerAPIHandler) handleServeDrive(w http.ResponseWriter, r *http.Request) {
|
func (h *peerAPIHandler) handleServeDrive(w http.ResponseWriter, r *http.Request) {
|
||||||
|
h.logfv1("taildrive: got %s request from %s", r.Method, h.peerNode.Key().ShortString())
|
||||||
if !h.ps.b.DriveSharingEnabled() {
|
if !h.ps.b.DriveSharingEnabled() {
|
||||||
h.logf("taildrive: not enabled")
|
h.logf("taildrive: not enabled")
|
||||||
http.Error(w, "taildrive not enabled", http.StatusNotFound)
|
http.Error(w, "taildrive not enabled", http.StatusNotFound)
|
||||||
@ -1055,21 +1060,23 @@ func (h *peerAPIHandler) handleServeDrive(w http.ResponseWriter, r *http.Request
|
|||||||
}
|
}
|
||||||
r.Body = bw
|
r.Body = bw
|
||||||
|
|
||||||
if r.Method == httpm.PUT || r.Method == httpm.GET {
|
defer func() {
|
||||||
defer func() {
|
switch wr.statusCode {
|
||||||
switch wr.statusCode {
|
case 304:
|
||||||
case 304:
|
// 304s are particularly chatty so skip logging.
|
||||||
// 304s are particularly chatty so skip logging.
|
default:
|
||||||
default:
|
log := h.logf
|
||||||
contentType := "unknown"
|
if r.Method != httpm.PUT && r.Method != httpm.GET {
|
||||||
if ct := wr.Header().Get("Content-Type"); ct != "" {
|
log = h.logfv1
|
||||||
contentType = ct
|
|
||||||
}
|
|
||||||
|
|
||||||
h.logf("taildrive: share: %s from %s to %s: status-code=%d ext=%q content-type=%q tx=%.f rx=%.f", r.Method, h.peerNode.Key().ShortString(), h.selfNode.Key().ShortString(), wr.statusCode, parseDriveFileExtensionForLog(r.URL.Path), contentType, roundTraffic(wr.contentLength), roundTraffic(bw.bytesRead))
|
|
||||||
}
|
}
|
||||||
}()
|
contentType := "unknown"
|
||||||
}
|
if ct := wr.Header().Get("Content-Type"); ct != "" {
|
||||||
|
contentType = ct
|
||||||
|
}
|
||||||
|
|
||||||
|
log("taildrive: share: %s from %s to %s: status-code=%d ext=%q content-type=%q tx=%.f rx=%.f", r.Method, h.peerNode.Key().ShortString(), h.selfNode.Key().ShortString(), wr.statusCode, parseDriveFileExtensionForLog(r.URL.Path), contentType, roundTraffic(wr.contentLength), roundTraffic(bw.bytesRead))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, taildrivePrefix)
|
r.URL.Path = strings.TrimPrefix(r.URL.Path, taildrivePrefix)
|
||||||
fs.ServeHTTPWithPerms(p, wr, r)
|
fs.ServeHTTPWithPerms(p, wr, r)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user