forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
tracer.go
60 lines (57 loc) · 1.6 KB
/
tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package qlog
import (
"io"
"net"
"time"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/logging"
)
func NewTracer(w io.WriteCloser) *logging.Tracer {
tr := &trace{
VantagePoint: vantagePoint{Type: "transport"},
CommonFields: commonFields{ReferenceTime: time.Now()},
}
wr := *newWriter(w, tr)
go wr.Run()
return &logging.Tracer{
SentPacket: func(_ net.Addr, hdr *logging.Header, size logging.ByteCount, frames []logging.Frame) {
fs := make([]frame, 0, len(frames))
for _, f := range frames {
fs = append(fs, frame{Frame: f})
}
wr.RecordEvent(time.Now(), &eventPacketSent{
Header: transformHeader(hdr),
Length: size,
Frames: fs,
})
},
SentVersionNegotiationPacket: func(_ net.Addr, dest, src logging.ArbitraryLenConnectionID, versions []logging.VersionNumber) {
ver := make([]versionNumber, len(versions))
for i, v := range versions {
ver[i] = versionNumber(v)
}
wr.RecordEvent(time.Now(), &eventVersionNegotiationSent{
Header: packetHeaderVersionNegotiation{
SrcConnectionID: src,
DestConnectionID: dest,
},
SupportedVersions: ver,
})
},
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,
msg: msg,
})
},
Close: func() { wr.Close() },
}
}