-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log every packet sent and received to stdout when GODEBUG=quiclogpackets=1. For golang/go#58547 Change-Id: I904336017ea646ad6459557b44702bfe4c732ba9 Reviewed-on: https://go-review.googlesource.com/c/net/+/513439 Reviewed-by: Jonathan Amsterdam <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Damien Neil <[email protected]>
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.21 | ||
|
||
package quic | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var logPackets bool | ||
|
||
// Parse GODEBUG settings. | ||
// | ||
// GODEBUG=quiclogpackets=1 -- log every packet sent and received. | ||
func init() { | ||
s := os.Getenv("GODEBUG") | ||
for len(s) > 0 { | ||
var opt string | ||
opt, s, _ = strings.Cut(s, ",") | ||
switch opt { | ||
case "quiclogpackets=1": | ||
logPackets = true | ||
} | ||
} | ||
} | ||
|
||
func logInboundLongPacket(c *Conn, p longPacket) { | ||
if !logPackets { | ||
return | ||
} | ||
prefix := c.String() | ||
fmt.Printf("%v recv %v %v\n", prefix, p.ptype, p.num) | ||
logFrames(prefix+" <- ", p.payload) | ||
} | ||
|
||
func logInboundShortPacket(c *Conn, p shortPacket) { | ||
if !logPackets { | ||
return | ||
} | ||
prefix := c.String() | ||
fmt.Printf("%v recv 1-RTT %v\n", prefix, p.num) | ||
logFrames(prefix+" <- ", p.payload) | ||
} | ||
|
||
func logSentPacket(c *Conn, ptype packetType, pnum packetNumber, src, dst, payload []byte) { | ||
if !logPackets || len(payload) == 0 { | ||
return | ||
} | ||
prefix := c.String() | ||
fmt.Printf("%v send %v %v\n", prefix, ptype, pnum) | ||
logFrames(prefix+" -> ", payload) | ||
} | ||
|
||
func logFrames(prefix string, payload []byte) { | ||
for len(payload) > 0 { | ||
f, n := parseDebugFrame(payload) | ||
if n < 0 { | ||
fmt.Printf("%vBAD DATA\n", prefix) | ||
break | ||
} | ||
payload = payload[n:] | ||
fmt.Printf("%v%v\n", prefix, f) | ||
} | ||
} |