forked from quic-go/quic-go
add a function to determine the length of a short header
This commit is contained in:
@@ -50,6 +50,10 @@ func ParseShortHeader(data []byte, connIDLen int) (length int, _ protocol.Packet
|
||||
return 1 + connIDLen + int(pnLen), pn, pnLen, kp, err
|
||||
}
|
||||
|
||||
func ShortHeaderLen(dest protocol.ConnectionID, pnLen protocol.PacketNumberLen) protocol.ByteCount {
|
||||
return 1 + protocol.ByteCount(dest.Len()) + protocol.ByteCount(pnLen)
|
||||
}
|
||||
|
||||
func LogShortHeader(logger utils.Logger, dest protocol.ConnectionID, pn protocol.PacketNumber, pnLen protocol.PacketNumberLen, kp protocol.KeyPhaseBit) {
|
||||
logger.Debugf("\tShort Header{DestConnectionID: %s, PacketNumber: %d, PacketNumberLen: %d, KeyPhase: %s}", dest, pn, pnLen, kp)
|
||||
}
|
||||
|
||||
@@ -70,6 +70,11 @@ var _ = Describe("Short Header", func() {
|
||||
})
|
||||
})
|
||||
|
||||
It("determines the length", func() {
|
||||
Expect(ShortHeaderLen(protocol.ParseConnectionID([]byte{1, 2, 3, 4}), protocol.PacketNumberLen3)).To(BeEquivalentTo(8))
|
||||
Expect(ShortHeaderLen(protocol.ParseConnectionID([]byte{}), protocol.PacketNumberLen1)).To(BeEquivalentTo(2))
|
||||
})
|
||||
|
||||
Context("logging", func() {
|
||||
var (
|
||||
buf *bytes.Buffer
|
||||
|
||||
@@ -326,12 +326,11 @@ func (t *connectionTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, p
|
||||
fs[i] = frame{Frame: f}
|
||||
}
|
||||
header := *transformShortHeader(hdr)
|
||||
hdrLen := 1 + hdr.DestConnectionID.Len() + int(hdr.PacketNumberLen)
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketReceived{
|
||||
Header: header,
|
||||
Length: packetSize,
|
||||
PayloadLength: packetSize - protocol.ByteCount(hdrLen),
|
||||
PayloadLength: packetSize - wire.ShortHeaderLen(hdr.DestConnectionID, hdr.PacketNumberLen),
|
||||
Frames: fs,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user