qlog the key phase bit

This commit is contained in:
Marten Seemann 2020-10-06 15:05:26 +07:00
parent c75da7965b
commit 93e3873141
3 changed files with 27 additions and 0 deletions

View file

@ -22,6 +22,8 @@ type (
EncryptionLevel = protocol.EncryptionLevel
// The KeyPhase is the key phase of the 1-RTT keys.
KeyPhase = protocol.KeyPhase
// The KeyPhaseBit is the value of the key phase bit of the 1-RTT packets.
KeyPhaseBit = protocol.KeyPhaseBit
// The PacketNumber is the packet number of a packet.
PacketNumber = protocol.PacketNumber
// The Perspective is the role of a QUIC endpoint (client or server).
@ -53,6 +55,13 @@ type (
RTTStats = utils.RTTStats
)
const (
// KeyPhaseZero is key phase bit 0
KeyPhaseZero KeyPhaseBit = protocol.KeyPhaseZero
// KeyPhaseOne is key phase bit 1
KeyPhaseOne KeyPhaseBit = protocol.KeyPhaseOne
)
const (
// PerspectiveServer is used for a QUIC server
PerspectiveServer Perspective = protocol.PerspectiveServer

View file

@ -37,6 +37,9 @@ type packetHeader struct {
Version logging.VersionNumber
SrcConnectionID logging.ConnectionID
DestConnectionID logging.ConnectionID
hasKeyPhase bool
KeyPhaseBit logging.KeyPhaseBit
}
func transformHeader(hdr *wire.Header) *packetHeader {
@ -52,6 +55,10 @@ func transformHeader(hdr *wire.Header) *packetHeader {
func transformExtendedHeader(hdr *wire.ExtendedHeader) *packetHeader {
h := transformHeader(&hdr.Header)
h.PacketNumber = hdr.PacketNumber
if !hdr.IsLongHeader {
h.hasKeyPhase = true
h.KeyPhaseBit = hdr.KeyPhase
}
return h
}
@ -74,4 +81,12 @@ func (h packetHeader) MarshalJSONObject(enc *gojay.Encoder) {
if h.DestConnectionID.Len() > 0 {
enc.StringKey("dcid", connectionID(h.DestConnectionID).String())
}
if h.hasKeyPhase {
switch h.KeyPhaseBit {
case logging.KeyPhaseZero:
enc.StringKey("key_phase_bit", "0")
case logging.KeyPhaseOne:
enc.StringKey("key_phase_bit", "1")
}
}
}

View file

@ -38,6 +38,7 @@ var _ = Describe("Packet Header", func() {
map[string]interface{}{
"packet_number": 42,
"dcil": 0,
"key_phase_bit": "0",
},
)
})
@ -108,11 +109,13 @@ var _ = Describe("Packet Header", func() {
&wire.ExtendedHeader{
PacketNumber: 42,
Header: wire.Header{DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}},
KeyPhase: protocol.KeyPhaseOne,
},
map[string]interface{}{
"packet_number": 42,
"dcil": 4,
"dcid": "deadbeef",
"key_phase_bit": "1",
},
)
})