diff --git a/internal/wire/header.go b/internal/wire/header.go index 0cffb8c6..b17e8127 100644 --- a/internal/wire/header.go +++ b/internal/wire/header.go @@ -247,3 +247,11 @@ func (h *Header) ParseExtended(b *bytes.Reader, ver protocol.VersionNumber) (*Ex func (h *Header) toExtendedHeader() *ExtendedHeader { return &ExtendedHeader{Header: *h} } + +// PacketType is the type of the packet, for logging purposes +func (h *Header) PacketType() string { + if h.IsLongHeader { + return h.Type.String() + } + return "1-RTT" +} diff --git a/internal/wire/header_test.go b/internal/wire/header_test.go index 8b790a23..b6076193 100644 --- a/internal/wire/header_test.go +++ b/internal/wire/header_test.go @@ -558,4 +558,9 @@ var _ = Describe("Header Parsing", func() { } }) }) + + It("tells its packet type for logging", func() { + Expect((&Header{IsLongHeader: true, Type: protocol.PacketTypeHandshake}).PacketType()).To(Equal("Handshake")) + Expect((&Header{}).PacketType()).To(Equal("1-RTT")) + }) }) diff --git a/session.go b/session.go index d99e2083..9b43d6b6 100644 --- a/session.go +++ b/session.go @@ -665,7 +665,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool / // After this, all packets with a different source connection have to be ignored. destConnID := s.connIDManager.Get() if s.receivedFirstPacket && hdr.IsLongHeader && !hdr.SrcConnectionID.Equal(destConnID) { - s.logger.Debugf("Dropping packet with unexpected source connection ID: %s (expected %s)", hdr.SrcConnectionID, destConnID) + s.logger.Debugf("Dropping %s packet with unexpected source connection ID: %s (expected %s)", hdr.PacketType(), hdr.SrcConnectionID, destConnID) return false } // drop 0-RTT packets @@ -677,7 +677,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool / if err != nil { switch err { case handshake.ErrKeysDropped: - s.logger.Debugf("Dropping packet because we already dropped the keys.") + s.logger.Debugf("Dropping %s packet because we already dropped the keys.", hdr.PacketType()) case handshake.ErrKeysNotYetAvailable: // Sealer for this encryption level not yet available. // Try again later. @@ -688,7 +688,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool / default: // This might be a packet injected by an attacker. // Drop it. - s.logger.Debugf("Dropping packet that could not be unpacked. Error: %s", err) + s.logger.Debugf("Dropping %s packet that could not be unpacked. Error: %s", hdr.PacketType(), err) } return false }