github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/quic/gquic-go/internal/wire/log.go (about) 1 package wire 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/internal/utils" 8 ) 9 10 // LogFrame logs a frame, either sent or received 11 func LogFrame(logger utils.Logger, frame Frame, sent bool) { 12 if !logger.Debug() { 13 return 14 } 15 dir := "<-" 16 if sent { 17 dir = "->" 18 } 19 switch f := frame.(type) { 20 case *StreamFrame: 21 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()) 22 case *StopWaitingFrame: 23 if sent { 24 logger.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x, PacketNumberLen: 0x%x}", dir, f.LeastUnacked, f.PacketNumberLen) 25 } else { 26 logger.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x}", dir, f.LeastUnacked) 27 } 28 case *AckFrame: 29 if len(f.AckRanges) > 1 { 30 ackRanges := make([]string, len(f.AckRanges)) 31 for i, r := range f.AckRanges { 32 ackRanges[i] = fmt.Sprintf("{Largest: %#x, Smallest: %#x}", r.Largest, r.Smallest) 33 } 34 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()) 35 } else { 36 logger.Debugf("\t%s &wire.AckFrame{LargestAcked: %#x, LowestAcked: %#x, DelayTime: %s}", dir, f.LargestAcked(), f.LowestAcked(), f.DelayTime.String()) 37 } 38 default: 39 logger.Debugf("\t%s %#v", dir, frame) 40 } 41 }