mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
qlog: log packet drops outside of a QUIC connection
This commit is contained in:
parent
2abbd41806
commit
3a7a53fdb9
2 changed files with 28 additions and 1 deletions
|
@ -2,8 +2,10 @@ package qlog
|
|||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
"github.com/quic-go/quic-go/logging"
|
||||
)
|
||||
|
||||
|
@ -17,7 +19,14 @@ func NewTracer(w io.WriteCloser) *logging.Tracer {
|
|||
return &logging.Tracer{
|
||||
SentPacket: nil,
|
||||
SentVersionNegotiationPacket: nil,
|
||||
DroppedPacket: nil,
|
||||
DroppedPacket: func(addr net.Addr, p logging.PacketType, count logging.ByteCount, reason logging.PacketDropReason) {
|
||||
wr.RecordEvent(time.Now(), eventPacketDropped{
|
||||
PacketType: p,
|
||||
PacketNumber: protocol.InvalidPacketNumber,
|
||||
PacketSize: count,
|
||||
Trigger: packetDropReason(reason),
|
||||
})
|
||||
},
|
||||
Debug: func(name, msg string) {
|
||||
wr.RecordEvent(time.Now(), &eventGeneric{
|
||||
name: name,
|
||||
|
|
|
@ -3,6 +3,7 @@ package qlog
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go/logging"
|
||||
|
@ -45,6 +46,23 @@ var _ = Describe("Tracing", func() {
|
|||
})
|
||||
|
||||
Context("Events", func() {
|
||||
It("records dropped packets", func() {
|
||||
addr := net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234}
|
||||
tracer.DroppedPacket(&addr, logging.PacketTypeInitial, 1337, logging.PacketDropPayloadDecryptError)
|
||||
tracer.Close()
|
||||
entry := exportAndParseSingle(buf)
|
||||
Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond)))
|
||||
Expect(entry.Name).To(Equal("transport:packet_dropped"))
|
||||
ev := entry.Event
|
||||
Expect(ev).To(HaveKey("raw"))
|
||||
Expect(ev["raw"].(map[string]interface{})).To(HaveKeyWithValue("length", float64(1337)))
|
||||
Expect(ev).To(HaveKey("header"))
|
||||
hdr := ev["header"].(map[string]interface{})
|
||||
Expect(hdr).To(HaveLen(1))
|
||||
Expect(hdr).To(HaveKeyWithValue("packet_type", "initial"))
|
||||
Expect(ev).To(HaveKeyWithValue("trigger", "payload_decrypt_error"))
|
||||
})
|
||||
|
||||
It("records a generic event", func() {
|
||||
tracer.Debug("foo", "bar")
|
||||
tracer.Close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue