mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 05:07:36 +03:00
split the qlog package into a logging and a qlog package
This commit is contained in:
parent
7c42d7941a
commit
78ba619a0b
25 changed files with 525 additions and 460 deletions
|
@ -2,43 +2,21 @@ package qlog
|
|||
|
||||
import (
|
||||
"github.com/francoispqt/gojay"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/wire"
|
||||
"github.com/lucas-clemente/quic-go/logging"
|
||||
)
|
||||
|
||||
// PacketTypeFromHeader determines the packet type from a *wire.Header.
|
||||
func PacketTypeFromHeader(hdr *wire.Header) PacketType {
|
||||
if !hdr.IsLongHeader {
|
||||
return PacketType1RTT
|
||||
}
|
||||
if hdr.Version == 0 {
|
||||
return PacketTypeVersionNegotiation
|
||||
}
|
||||
switch hdr.Type {
|
||||
case protocol.PacketTypeInitial:
|
||||
return PacketTypeInitial
|
||||
case protocol.PacketTypeHandshake:
|
||||
return PacketTypeHandshake
|
||||
case protocol.PacketType0RTT:
|
||||
return PacketType0RTT
|
||||
case protocol.PacketTypeRetry:
|
||||
return PacketTypeRetry
|
||||
default:
|
||||
return PacketTypeNotDetermined
|
||||
}
|
||||
}
|
||||
|
||||
func getPacketTypeFromEncryptionLevel(encLevel protocol.EncryptionLevel) PacketType {
|
||||
func getPacketTypeFromEncryptionLevel(encLevel protocol.EncryptionLevel) logging.PacketType {
|
||||
switch encLevel {
|
||||
case protocol.EncryptionInitial:
|
||||
return PacketTypeInitial
|
||||
return logging.PacketTypeInitial
|
||||
case protocol.EncryptionHandshake:
|
||||
return PacketTypeHandshake
|
||||
return logging.PacketTypeHandshake
|
||||
case protocol.Encryption0RTT:
|
||||
return PacketType0RTT
|
||||
return logging.PacketType0RTT
|
||||
case protocol.Encryption1RTT:
|
||||
return PacketType1RTT
|
||||
return logging.PacketType1RTT
|
||||
default:
|
||||
panic("unknown encryption level")
|
||||
}
|
||||
|
@ -46,7 +24,7 @@ func getPacketTypeFromEncryptionLevel(encLevel protocol.EncryptionLevel) PacketT
|
|||
|
||||
func transformHeader(hdr *wire.Header) *packetHeader {
|
||||
return &packetHeader{
|
||||
PacketType: PacketTypeFromHeader(hdr),
|
||||
PacketType: logging.PacketTypeFromHeader(hdr),
|
||||
PayloadLength: hdr.Length,
|
||||
SrcConnectionID: hdr.SrcConnectionID,
|
||||
DestConnectionID: hdr.DestConnectionID,
|
||||
|
@ -60,23 +38,11 @@ func transformExtendedHeader(hdr *wire.ExtendedHeader) *packetHeader {
|
|||
return h
|
||||
}
|
||||
|
||||
type packetHeader struct {
|
||||
// We don't log the packet type as a part of the header yet, see https://github.com/quiclog/internet-drafts/issues/40.
|
||||
PacketType PacketType
|
||||
|
||||
PacketNumber protocol.PacketNumber
|
||||
PayloadLength protocol.ByteCount
|
||||
// Size of the QUIC packet (QUIC header + payload).
|
||||
// See https://github.com/quiclog/internet-drafts/issues/40.
|
||||
PacketSize protocol.ByteCount
|
||||
|
||||
Version protocol.VersionNumber
|
||||
SrcConnectionID protocol.ConnectionID
|
||||
DestConnectionID protocol.ConnectionID
|
||||
}
|
||||
// We don't log the packet type as a part of the header yet, see https://github.com/quiclog/internet-drafts/issues/40.
|
||||
type packetHeader logging.PacketHeader
|
||||
|
||||
func (h packetHeader) MarshalJSONObject(enc *gojay.Encoder) {
|
||||
if h.PacketType != PacketTypeRetry && h.PacketType != PacketTypeVersionNegotiation {
|
||||
if h.PacketType != logging.PacketTypeRetry && h.PacketType != logging.PacketTypeVersionNegotiation {
|
||||
enc.Int64Key("packet_number", int64(h.PacketNumber))
|
||||
}
|
||||
enc.Int64KeyOmitEmpty("payload_length", int64(h.PayloadLength))
|
||||
|
@ -84,7 +50,7 @@ func (h packetHeader) MarshalJSONObject(enc *gojay.Encoder) {
|
|||
if h.Version != 0 {
|
||||
enc.StringKey("version", versionNumber(h.Version).String())
|
||||
}
|
||||
if h.PacketType != PacketType1RTT {
|
||||
if h.PacketType != logging.PacketType1RTT {
|
||||
enc.IntKey("scil", h.SrcConnectionID.Len())
|
||||
if h.SrcConnectionID.Len() > 0 {
|
||||
enc.StringKey("scid", connectionID(h.SrcConnectionID).String())
|
||||
|
@ -95,5 +61,3 @@ func (h packetHeader) MarshalJSONObject(enc *gojay.Encoder) {
|
|||
enc.StringKey("dcid", connectionID(h.DestConnectionID).String())
|
||||
}
|
||||
}
|
||||
|
||||
func (packetHeader) IsNil() bool { return false }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue