2018-02-17 00:29:53 -05:00
|
|
|
package wire
|
|
|
|
|
2018-09-02 16:18:54 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
|
|
|
)
|
2018-02-17 00:29:53 -05:00
|
|
|
|
|
|
|
// LogFrame logs a frame, either sent or received
|
2018-04-18 16:48:08 -05:00
|
|
|
func LogFrame(logger utils.Logger, frame Frame, sent bool) {
|
|
|
|
if !logger.Debug() {
|
2018-02-17 00:29:53 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
dir := "<-"
|
|
|
|
if sent {
|
|
|
|
dir = "->"
|
|
|
|
}
|
|
|
|
switch f := frame.(type) {
|
|
|
|
case *StreamFrame:
|
2018-04-18 16:48:08 -05:00
|
|
|
logger.Debugf("\t%s &wire.StreamFrame{StreamID: %d, FinBit: %t, Offset: 0x%x, Data length: 0x%x, Offset + Data length: 0x%x}", dir, f.StreamID, f.FinBit, f.Offset, f.DataLen(), f.Offset+f.DataLen())
|
2018-02-17 00:29:53 -05:00
|
|
|
case *StopWaitingFrame:
|
|
|
|
if sent {
|
2018-04-18 16:48:08 -05:00
|
|
|
logger.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x, PacketNumberLen: 0x%x}", dir, f.LeastUnacked, f.PacketNumberLen)
|
2018-02-17 00:29:53 -05:00
|
|
|
} else {
|
2018-04-18 16:48:08 -05:00
|
|
|
logger.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x}", dir, f.LeastUnacked)
|
2018-02-17 00:29:53 -05:00
|
|
|
}
|
|
|
|
case *AckFrame:
|
2018-09-02 16:18:54 -05:00
|
|
|
if len(f.AckRanges) > 1 {
|
|
|
|
ackRanges := make([]string, len(f.AckRanges))
|
|
|
|
for i, r := range f.AckRanges {
|
|
|
|
ackRanges[i] = fmt.Sprintf("{Largest: %#x, Smallest: %#x}", r.Largest, r.Smallest)
|
|
|
|
}
|
|
|
|
logger.Debugf("\t%s &wire.AckFrame{LargestAcked: %#x, LowestAcked: %#x, AckRanges: {%s}, DelayTime: %s}", dir, f.LargestAcked(), f.LowestAcked(), strings.Join(ackRanges, ", "), f.DelayTime.String())
|
|
|
|
} else {
|
|
|
|
logger.Debugf("\t%s &wire.AckFrame{LargestAcked: %#x, LowestAcked: %#x, DelayTime: %s}", dir, f.LargestAcked(), f.LowestAcked(), f.DelayTime.String())
|
|
|
|
}
|
2018-02-17 00:29:53 -05:00
|
|
|
default:
|
2018-04-18 16:48:08 -05:00
|
|
|
logger.Debugf("\t%s %#v", dir, frame)
|
2018-02-17 00:29:53 -05:00
|
|
|
}
|
|
|
|
}
|