split the tracing function for received short and long header packets

This commit is contained in:
Marten Seemann 2022-08-27 15:46:37 +03:00
parent 3a12a898a5
commit ed15a94703
18 changed files with 222 additions and 89 deletions

View file

@ -1199,7 +1199,16 @@ func (s *connection) handleUnpackedPacket(
for i, frame := range frames {
fs[i] = logutils.ConvertFrame(frame)
}
s.tracer.ReceivedPacket(packet.hdr, packetSize, fs)
if packet.hdr.IsLongHeader {
s.tracer.ReceivedLongHeaderPacket(packet.hdr, packetSize, fs)
} else {
s.tracer.ReceivedShortHeaderPacket(&wire.ShortHeader{
DestConnectionID: packet.hdr.DestConnectionID,
PacketNumber: packet.hdr.PacketNumber,
PacketNumberLen: packet.hdr.PacketNumberLen,
KeyPhase: packet.hdr.KeyPhase,
}, packetSize, fs)
}
for _, frame := range frames {
if err := s.handleFrame(frame, packet.encryptionLevel, packet.hdr.DestConnectionID); err != nil {
return err

View file

@ -572,7 +572,7 @@ var _ = Describe("Connection", func() {
})
gomock.InOrder(
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()),
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any()),
tracer.EXPECT().ReceivedShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any()),
tracer.EXPECT().ClosedConnection(gomock.Any()),
tracer.EXPECT().Close(),
)
@ -749,7 +749,7 @@ var _ = Describe("Connection", func() {
conn.receivedPacketHandler = rph
packet.rcvTime = rcvTime
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedPacket(&unpackedHdr, protocol.ByteCount(len(packet.data)), []logging.Frame{})
tracer.EXPECT().ReceivedShortHeaderPacket(&wire.ShortHeader{PacketNumber: 0x1337, PacketNumberLen: 1, DestConnectionID: srcConnID}, protocol.ByteCount(len(packet.data)), []logging.Frame{})
Expect(conn.handlePacketImpl(packet)).To(BeTrue())
})
@ -779,7 +779,7 @@ var _ = Describe("Connection", func() {
conn.receivedPacketHandler = rph
packet.rcvTime = rcvTime
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedPacket(&unpackedHdr, protocol.ByteCount(len(packet.data)), []logging.Frame{&logging.PingFrame{}})
tracer.EXPECT().ReceivedShortHeaderPacket(&wire.ShortHeader{PacketNumber: 0x1337, PacketNumberLen: 1, DestConnectionID: srcConnID}, protocol.ByteCount(len(packet.data)), []logging.Frame{&logging.PingFrame{}})
Expect(conn.handlePacketImpl(packet)).To(BeTrue())
})
@ -854,7 +854,7 @@ var _ = Describe("Connection", func() {
}, nil
}).Times(3)
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ExtendedHeader, _ protocol.ByteCount, _ []logging.Frame) {
tracer.EXPECT().ReceivedShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ShortHeader, _ protocol.ByteCount, _ []logging.Frame) {
}).Times(3)
packer.EXPECT().PackCoalescedPacket() // only expect a single call
@ -901,7 +901,7 @@ var _ = Describe("Connection", func() {
}, nil
}).Times(3)
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ExtendedHeader, _ protocol.ByteCount, _ []logging.Frame) {
tracer.EXPECT().ReceivedShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ShortHeader, _ protocol.ByteCount, _ []logging.Frame) {
}).Times(3)
packer.EXPECT().PackCoalescedPacket().Times(3) // only expect a single call
@ -1048,7 +1048,7 @@ var _ = Describe("Connection", func() {
}, nil)
p1 := getPacket(hdr1, nil)
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(p1.data)), gomock.Any())
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(p1.data)), gomock.Any())
Expect(conn.handlePacketImpl(p1)).To(BeTrue())
// The next packet has to be ignored, since the source connection ID doesn't match.
p2 := getPacket(hdr2, nil)
@ -1090,7 +1090,7 @@ var _ = Describe("Connection", func() {
}, nil)
packet.remoteAddr = &net.IPAddr{IP: net.IPv4(192, 168, 0, 100)}
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(packet.data)), gomock.Any())
tracer.EXPECT().ReceivedShortHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet.data)), gomock.Any())
Expect(conn.handlePacketImpl(packet)).To(BeTrue())
})
})
@ -1125,10 +1125,10 @@ var _ = Describe("Connection", func() {
return &unpackedPacket{
encryptionLevel: protocol.EncryptionHandshake,
data: []byte{0},
hdr: &wire.ExtendedHeader{},
hdr: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true}},
}, nil
})
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(packet.data)), gomock.Any())
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet.data)), gomock.Any())
Expect(conn.handlePacketImpl(packet)).To(BeTrue())
})
@ -1141,7 +1141,7 @@ var _ = Describe("Connection", func() {
data: []byte{0},
hdr: &wire.ExtendedHeader{
PacketNumber: 1,
Header: wire.Header{SrcConnectionID: destConnID},
Header: wire.Header{SrcConnectionID: destConnID, IsLongHeader: true},
},
}, nil
})
@ -1153,13 +1153,13 @@ var _ = Describe("Connection", func() {
data: []byte{0},
hdr: &wire.ExtendedHeader{
PacketNumber: 2,
Header: wire.Header{SrcConnectionID: destConnID},
Header: wire.Header{SrcConnectionID: destConnID, IsLongHeader: true},
},
}, nil
})
gomock.InOrder(
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(packet1.data)), gomock.Any()),
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(packet2.data)), gomock.Any()),
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet1.data)), gomock.Any()),
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet2.data)), gomock.Any()),
)
packet1.data = append(packet1.data, packet2.data...)
Expect(conn.handlePacketImpl(packet1)).To(BeTrue())
@ -1176,13 +1176,13 @@ var _ = Describe("Connection", func() {
return &unpackedPacket{
encryptionLevel: protocol.EncryptionHandshake,
data: []byte{0},
hdr: &wire.ExtendedHeader{},
hdr: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true}},
}, nil
}),
)
gomock.InOrder(
tracer.EXPECT().BufferedPacket(gomock.Any()),
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(packet2.data)), gomock.Any()),
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet2.data)), gomock.Any()),
)
packet1.data = append(packet1.data, packet2.data...)
Expect(conn.handlePacketImpl(packet1)).To(BeTrue())
@ -1200,13 +1200,13 @@ var _ = Describe("Connection", func() {
return &unpackedPacket{
encryptionLevel: protocol.EncryptionHandshake,
data: []byte{0},
hdr: &wire.ExtendedHeader{},
hdr: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true}},
}, nil
})
_, packet2 := getPacketWithLength(wrongConnID, 123)
// don't EXPECT any more calls to unpacker.Unpack()
gomock.InOrder(
tracer.EXPECT().ReceivedPacket(gomock.Any(), protocol.ByteCount(len(packet1.data)), gomock.Any()),
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet1.data)), gomock.Any()),
tracer.EXPECT().DroppedPacket(gomock.Any(), protocol.ByteCount(len(packet2.data)), logging.PacketDropUnknownConnectionID),
)
packet1.data = append(packet1.data, packet2.data...)
@ -2481,7 +2481,7 @@ var _ = Describe("Client Connection", func() {
},
PacketNumberLen: protocol.PacketNumberLen2,
}, []byte("foobar"))
tracer.EXPECT().ReceivedPacket(gomock.Any(), p.Size(), []logging.Frame{})
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), p.Size(), []logging.Frame{})
Expect(conn.handlePacketImpl(p)).To(BeTrue())
// make sure the go routine returns
packer.EXPECT().PackApplicationClose(gomock.Any()).Return(&coalescedPacket{buffer: getPacketBuffer()}, nil)
@ -2518,7 +2518,7 @@ var _ = Describe("Client Connection", func() {
DestConnectionID: srcConnID,
SrcConnectionID: destConnID,
}
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any())
Expect(conn.handleSinglePacket(&receivedPacket{buffer: getPacketBuffer()}, hdr)).To(BeTrue())
})
@ -2951,7 +2951,7 @@ var _ = Describe("Client Connection", func() {
hdr: hdr1,
data: []byte{0}, // one PADDING frame
}, nil)
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any())
Expect(conn.handlePacketImpl(getPacket(hdr1, nil))).To(BeTrue())
// The next packet has to be ignored, since the source connection ID doesn't match.
tracer.EXPECT().DroppedPacket(gomock.Any(), gomock.Any(), gomock.Any())
@ -2979,7 +2979,7 @@ var _ = Describe("Client Connection", func() {
It("fails on Initial-level ACK for unsent packet", func() {
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, conn.version, destConnID, []wire.Frame{ack})
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any())
Expect(conn.handlePacketImpl(wrapPacket(initialPacket))).To(BeFalse())
})
@ -2991,7 +2991,7 @@ var _ = Describe("Client Connection", func() {
ReasonPhrase: "mitm attacker",
}
initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, conn.version, destConnID, []wire.Frame{connCloseFrame})
tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any())
Expect(conn.handlePacketImpl(wrapPacket(initialPacket))).To(BeTrue())
})

View file

@ -17,7 +17,7 @@ import (
var (
sentHeaders []*logging.ExtendedHeader
receivedHeaders []*logging.ExtendedHeader
receivedHeaders []*logging.ShortHeader
)
func countKeyPhases() (sent, received int) {
@ -33,9 +33,6 @@ func countKeyPhases() (sent, received int) {
}
lastKeyPhase = protocol.KeyPhaseOne
for _, hdr := range receivedHeaders {
if hdr.IsLongHeader {
continue
}
if hdr.KeyPhase != lastKeyPhase {
received++
lastKeyPhase = hdr.KeyPhase
@ -52,7 +49,7 @@ func (t *keyUpdateConnTracer) SentPacket(hdr *logging.ExtendedHeader, size loggi
sentHeaders = append(sentHeaders, hdr)
}
func (t *keyUpdateConnTracer) ReceivedPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, frames []logging.Frame) {
func (t *keyUpdateConnTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, size logging.ByteCount, frames []logging.Frame) {
receivedHeaders = append(receivedHeaders, hdr)
}

View file

@ -84,11 +84,8 @@ var _ = Describe("Packetization", func() {
}
Expect(conn.CloseWithError(0, "")).To(Succeed())
countBundledPackets := func(packets []packet) (numBundled int) {
countBundledPackets := func(packets []shortHeaderPacket) (numBundled int) {
for _, p := range packets {
if p.hdr.IsLongHeader {
continue
}
var hasAck, hasStreamFrame bool
for _, f := range p.frames {
switch f.(type) {
@ -105,8 +102,8 @@ var _ = Describe("Packetization", func() {
return
}
numBundledIncoming := countBundledPackets(clientTracer.getRcvdPackets())
numBundledOutgoing := countBundledPackets(serverTracer.getRcvdPackets())
numBundledIncoming := countBundledPackets(clientTracer.getRcvdShortHeaderPackets())
numBundledOutgoing := countBundledPackets(serverTracer.getRcvdShortHeaderPackets())
fmt.Fprintf(GinkgoWriter, "bundled incoming packets: %d / %d\n", numBundledIncoming, numMsg)
fmt.Fprintf(GinkgoWriter, "bundled outgoing packets: %d / %d\n", numBundledOutgoing, numMsg)
Expect(numBundledIncoming).To(And(

View file

@ -347,18 +347,29 @@ type packet struct {
frames []logging.Frame
}
type shortHeaderPacket struct {
time time.Time
hdr *logging.ShortHeader
frames []logging.Frame
}
type packetTracer struct {
logging.NullConnectionTracer
closed chan struct{}
sent, rcvd []packet
closed chan struct{}
rcvdShortHdr []shortHeaderPacket
sent, rcvdLongHdr []packet
}
func newPacketTracer() *packetTracer {
return &packetTracer{closed: make(chan struct{})}
}
func (t *packetTracer) ReceivedPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, frames []logging.Frame) {
t.rcvd = append(t.rcvd, packet{time: time.Now(), hdr: hdr, frames: frames})
func (t *packetTracer) ReceivedLongHeaderPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, frames []logging.Frame) {
t.rcvdLongHdr = append(t.rcvdLongHdr, packet{time: time.Now(), hdr: hdr, frames: frames})
}
func (t *packetTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, _ logging.ByteCount, frames []logging.Frame) {
t.rcvdShortHdr = append(t.rcvdShortHdr, shortHeaderPacket{time: time.Now(), hdr: hdr, frames: frames})
}
func (t *packetTracer) SentPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, ack *wire.AckFrame, frames []logging.Frame) {
@ -373,9 +384,14 @@ func (t *packetTracer) getSentPackets() []packet {
return t.sent
}
func (t *packetTracer) getRcvdPackets() []packet {
func (t *packetTracer) getRcvdLongHeaderPackets() []packet {
<-t.closed
return t.rcvd
return t.rcvdLongHdr
}
func (t *packetTracer) getRcvdShortHeaderPackets() []shortHeaderPacket {
<-t.closed
return t.rcvdShortHdr
}
func TestSelf(t *testing.T) {

View file

@ -226,7 +226,7 @@ var _ = Describe("Timeout tests", func() {
lastAckElicitingPacketSentAt = p.time
}
}
rcvdPackets := tr.getRcvdPackets()
rcvdPackets := tr.getRcvdShortHeaderPackets()
lastPacketRcvdAt := rcvdPackets[len(rcvdPackets)-1].time
// We're ignoring here that only the first ack-eliciting packet sent resets the idle timeout.
// This is ok since we're dealing with a lossless connection here,

View file

@ -217,7 +217,7 @@ var _ = Describe("0-RTT", func() {
)
var numNewConnIDs int
for _, p := range tracer.getRcvdPackets() {
for _, p := range tracer.getRcvdLongHeaderPackets() {
for _, f := range p.frames {
if _, ok := f.(*logging.NewConnectionIDFrame); ok {
numNewConnIDs++
@ -233,7 +233,7 @@ var _ = Describe("0-RTT", func() {
num0RTT := atomic.LoadUint32(num0RTTPackets)
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
Expect(num0RTT).ToNot(BeZero())
zeroRTTPackets := get0RTTPackets(tracer.getRcvdPackets())
zeroRTTPackets := get0RTTPackets(tracer.getRcvdLongHeaderPackets())
Expect(len(zeroRTTPackets)).To(BeNumerically(">", 10))
sort.Slice(zeroRTTPackets, func(i, j int) bool { return zeroRTTPackets[i] < zeroRTTPackets[j] })
Expect(zeroRTTPackets[0]).To(Equal(protocol.PacketNumber(0)))
@ -310,7 +310,7 @@ var _ = Describe("0-RTT", func() {
num0RTT := atomic.LoadUint32(num0RTTPackets)
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
Expect(num0RTT).To(Or(BeEquivalentTo(2), BeEquivalentTo(3))) // the FIN might be sent in a separate packet
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(HaveLen(int(num0RTT)))
Expect(get0RTTPackets(tracer.getRcvdLongHeaderPackets())).To(HaveLen(int(num0RTT)))
})
It("transfers 0-RTT data, when 0-RTT packets are lost", func() {
@ -367,7 +367,7 @@ var _ = Describe("0-RTT", func() {
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets. Dropped %d of those.", num0RTT, numDropped)
Expect(numDropped).ToNot(BeZero())
Expect(num0RTT).ToNot(BeZero())
Expect(get0RTTPackets(tracer.getRcvdPackets())).ToNot(BeEmpty())
Expect(get0RTTPackets(tracer.getRcvdLongHeaderPackets())).ToNot(BeEmpty())
})
It("retransmits all 0-RTT data when the server performs a Retry", func() {
@ -441,7 +441,7 @@ var _ = Describe("0-RTT", func() {
defer mutex.Unlock()
Expect(firstCounter).To(BeNumerically("~", 5000+100 /* framing overhead */, 100)) // the FIN bit might be sent extra
Expect(secondCounter).To(BeNumerically("~", firstCounter, 20))
zeroRTTPackets := get0RTTPackets(tracer.getRcvdPackets())
zeroRTTPackets := get0RTTPackets(tracer.getRcvdLongHeaderPackets())
Expect(len(zeroRTTPackets)).To(BeNumerically(">=", 5))
Expect(zeroRTTPackets[0]).To(BeNumerically(">=", protocol.PacketNumber(5)))
})
@ -516,7 +516,7 @@ var _ = Describe("0-RTT", func() {
num0RTT := atomic.LoadUint32(num0RTTPackets)
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
Expect(num0RTT).ToNot(BeZero())
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(BeEmpty())
Expect(get0RTTPackets(tracer.getRcvdLongHeaderPackets())).To(BeEmpty())
})
It("rejects 0-RTT when the ALPN changed", func() {
@ -545,7 +545,7 @@ var _ = Describe("0-RTT", func() {
num0RTT := atomic.LoadUint32(num0RTTPackets)
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
Expect(num0RTT).ToNot(BeZero())
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(BeEmpty())
Expect(get0RTTPackets(tracer.getRcvdLongHeaderPackets())).To(BeEmpty())
})
DescribeTable("flow control limits",
@ -603,7 +603,7 @@ var _ = Describe("0-RTT", func() {
Eventually(conn.Context().Done()).Should(BeClosed())
var processedFirst bool
for _, p := range tracer.getRcvdPackets() {
for _, p := range tracer.getRcvdLongHeaderPackets() {
for _, f := range p.frames {
if sf, ok := f.(*logging.StreamFrame); ok {
if !processedFirst {
@ -613,9 +613,7 @@ var _ = Describe("0-RTT", func() {
Expect(sf.Length).To(BeEquivalentTo(3))
processedFirst = true
} else {
// All other STREAM frames can only be sent after handshake completion.
Expect(p.hdr.IsLongHeader).To(BeFalse())
Expect(sf.Offset).ToNot(BeZero())
Fail("STREAM was shouldn't have been sent in 0-RTT")
}
}
}
@ -700,7 +698,7 @@ var _ = Describe("0-RTT", func() {
num0RTT := atomic.LoadUint32(num0RTTPackets)
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
Expect(num0RTT).ToNot(BeZero())
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(BeEmpty())
Expect(get0RTTPackets(tracer.getRcvdLongHeaderPackets())).To(BeEmpty())
})
}
@ -732,8 +730,8 @@ var _ = Describe("0-RTT", func() {
transfer0RTTData(ln, proxy.LocalPort(), clientConf, nil, PRData)
Expect(tracer.getRcvdPackets()[0].hdr.Type).To(Equal(protocol.PacketTypeInitial))
zeroRTTPackets := get0RTTPackets(tracer.getRcvdPackets())
Expect(tracer.getRcvdLongHeaderPackets()[0].hdr.Type).To(Equal(protocol.PacketTypeInitial))
zeroRTTPackets := get0RTTPackets(tracer.getRcvdLongHeaderPackets())
Expect(len(zeroRTTPackets)).To(BeNumerically(">", 10))
Expect(zeroRTTPackets[0]).To(Equal(protocol.PacketNumber(0)))
})

View file

@ -183,16 +183,16 @@ func (mr *MockConnectionTracerMockRecorder) NegotiatedVersion(arg0, arg1, arg2 i
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NegotiatedVersion", reflect.TypeOf((*MockConnectionTracer)(nil).NegotiatedVersion), arg0, arg1, arg2)
}
// ReceivedPacket mocks base method.
func (m *MockConnectionTracer) ReceivedPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 []logging.Frame) {
// ReceivedLongHeaderPacket mocks base method.
func (m *MockConnectionTracer) ReceivedLongHeaderPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 []logging.Frame) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ReceivedPacket", arg0, arg1, arg2)
m.ctrl.Call(m, "ReceivedLongHeaderPacket", arg0, arg1, arg2)
}
// ReceivedPacket indicates an expected call of ReceivedPacket.
func (mr *MockConnectionTracerMockRecorder) ReceivedPacket(arg0, arg1, arg2 interface{}) *gomock.Call {
// ReceivedLongHeaderPacket indicates an expected call of ReceivedLongHeaderPacket.
func (mr *MockConnectionTracerMockRecorder) ReceivedLongHeaderPacket(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedPacket", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedPacket), arg0, arg1, arg2)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedLongHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedLongHeaderPacket), arg0, arg1, arg2)
}
// ReceivedRetry mocks base method.
@ -207,6 +207,18 @@ func (mr *MockConnectionTracerMockRecorder) ReceivedRetry(arg0 interface{}) *gom
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedRetry", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedRetry), arg0)
}
// ReceivedShortHeaderPacket mocks base method.
func (m *MockConnectionTracer) ReceivedShortHeaderPacket(arg0 *wire.ShortHeader, arg1 protocol.ByteCount, arg2 []logging.Frame) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ReceivedShortHeaderPacket", arg0, arg1, arg2)
}
// ReceivedShortHeaderPacket indicates an expected call of ReceivedShortHeaderPacket.
func (mr *MockConnectionTracerMockRecorder) ReceivedShortHeaderPacket(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedShortHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedShortHeaderPacket), arg0, arg1, arg2)
}
// ReceivedTransportParameters mocks base method.
func (m *MockConnectionTracer) ReceivedTransportParameters(arg0 *wire.TransportParameters) {
m.ctrl.T.Helper()

View file

@ -44,8 +44,10 @@ type (
// The Header is the QUIC packet header, before removing header protection.
Header = wire.Header
// The ExtendedHeader is the QUIC packet header, after removing header protection.
// The ExtendedHeader is the QUIC Long Header packet header, after removing header protection.
ExtendedHeader = wire.ExtendedHeader
// The ShortHeader is the QUIC Short Header packet header, after removing header protection.
ShortHeader = wire.ShortHeader
// The TransportParameters are QUIC transport parameters.
TransportParameters = wire.TransportParameters
// The PreferredAddress is the preferred address sent in the transport parameters.
@ -116,7 +118,8 @@ type ConnectionTracer interface {
SentPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame)
ReceivedVersionNegotiationPacket(dest, src ArbitraryLenConnectionID, _ []VersionNumber)
ReceivedRetry(*Header)
ReceivedPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame)
ReceivedLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame)
ReceivedShortHeaderPacket(hdr *ShortHeader, size ByteCount, frames []Frame)
BufferedPacket(PacketType)
DroppedPacket(PacketType, ByteCount, PacketDropReason)
UpdatedMetrics(rttStats *RTTStats, cwnd, bytesInFlight ByteCount, packetsInFlight int)

View file

@ -182,16 +182,16 @@ func (mr *MockConnectionTracerMockRecorder) NegotiatedVersion(arg0, arg1, arg2 i
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NegotiatedVersion", reflect.TypeOf((*MockConnectionTracer)(nil).NegotiatedVersion), arg0, arg1, arg2)
}
// ReceivedPacket mocks base method.
func (m *MockConnectionTracer) ReceivedPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 []Frame) {
// ReceivedLongHeaderPacket mocks base method.
func (m *MockConnectionTracer) ReceivedLongHeaderPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 []Frame) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ReceivedPacket", arg0, arg1, arg2)
m.ctrl.Call(m, "ReceivedLongHeaderPacket", arg0, arg1, arg2)
}
// ReceivedPacket indicates an expected call of ReceivedPacket.
func (mr *MockConnectionTracerMockRecorder) ReceivedPacket(arg0, arg1, arg2 interface{}) *gomock.Call {
// ReceivedLongHeaderPacket indicates an expected call of ReceivedLongHeaderPacket.
func (mr *MockConnectionTracerMockRecorder) ReceivedLongHeaderPacket(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedPacket", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedPacket), arg0, arg1, arg2)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedLongHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedLongHeaderPacket), arg0, arg1, arg2)
}
// ReceivedRetry mocks base method.
@ -206,6 +206,18 @@ func (mr *MockConnectionTracerMockRecorder) ReceivedRetry(arg0 interface{}) *gom
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedRetry", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedRetry), arg0)
}
// ReceivedShortHeaderPacket mocks base method.
func (m *MockConnectionTracer) ReceivedShortHeaderPacket(arg0 *wire.ShortHeader, arg1 protocol.ByteCount, arg2 []Frame) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ReceivedShortHeaderPacket", arg0, arg1, arg2)
}
// ReceivedShortHeaderPacket indicates an expected call of ReceivedShortHeaderPacket.
func (mr *MockConnectionTracerMockRecorder) ReceivedShortHeaderPacket(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReceivedShortHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).ReceivedShortHeaderPacket), arg0, arg1, arg2)
}
// ReceivedTransportParameters mocks base method.
func (m *MockConnectionTracer) ReceivedTransportParameters(arg0 *wire.TransportParameters) {
m.ctrl.T.Helper()

View file

@ -122,9 +122,15 @@ func (m *connTracerMultiplexer) ReceivedRetry(hdr *Header) {
}
}
func (m *connTracerMultiplexer) ReceivedPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame) {
func (m *connTracerMultiplexer) ReceivedLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame) {
for _, t := range m.tracers {
t.ReceivedPacket(hdr, size, frames)
t.ReceivedLongHeaderPacket(hdr, size, frames)
}
}
func (m *connTracerMultiplexer) ReceivedShortHeaderPacket(hdr *ShortHeader, size ByteCount, frames []Frame) {
for _, t := range m.tracers {
t.ReceivedShortHeaderPacket(hdr, size, frames)
}
}

View file

@ -181,12 +181,20 @@ var _ = Describe("Tracing", func() {
tracer.ReceivedRetry(hdr)
})
It("traces the ReceivedPacket event", func() {
It("traces the ReceivedLongHeaderPacket event", func() {
hdr := &ExtendedHeader{Header: Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}}
ping := &PingFrame{}
tr1.EXPECT().ReceivedPacket(hdr, ByteCount(1337), []Frame{ping})
tr2.EXPECT().ReceivedPacket(hdr, ByteCount(1337), []Frame{ping})
tracer.ReceivedPacket(hdr, 1337, []Frame{ping})
tr1.EXPECT().ReceivedLongHeaderPacket(hdr, ByteCount(1337), []Frame{ping})
tr2.EXPECT().ReceivedLongHeaderPacket(hdr, ByteCount(1337), []Frame{ping})
tracer.ReceivedLongHeaderPacket(hdr, 1337, []Frame{ping})
})
It("traces the ReceivedShortHeaderPacket event", func() {
hdr := &ShortHeader{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}
ping := &PingFrame{}
tr1.EXPECT().ReceivedShortHeaderPacket(hdr, ByteCount(1337), []Frame{ping})
tr2.EXPECT().ReceivedShortHeaderPacket(hdr, ByteCount(1337), []Frame{ping})
tracer.ReceivedShortHeaderPacket(hdr, 1337, []Frame{ping})
})
It("traces the BufferedPacket event", func() {

View file

@ -38,10 +38,12 @@ func (n NullConnectionTracer) RestoredTransportParameters(*TransportParameters)
func (n NullConnectionTracer) SentPacket(*ExtendedHeader, ByteCount, *AckFrame, []Frame) {}
func (n NullConnectionTracer) ReceivedVersionNegotiationPacket(dest, src ArbitraryLenConnectionID, _ []VersionNumber) {
}
func (n NullConnectionTracer) ReceivedRetry(*Header) {}
func (n NullConnectionTracer) ReceivedPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame) {}
func (n NullConnectionTracer) BufferedPacket(PacketType) {}
func (n NullConnectionTracer) DroppedPacket(PacketType, ByteCount, PacketDropReason) {}
func (n NullConnectionTracer) ReceivedRetry(*Header) {}
func (n NullConnectionTracer) ReceivedLongHeaderPacket(*ExtendedHeader, ByteCount, []Frame) {}
func (n NullConnectionTracer) ReceivedShortHeaderPacket(*ShortHeader, ByteCount, []Frame) {}
func (n NullConnectionTracer) BufferedPacket(PacketType) {}
func (n NullConnectionTracer) DroppedPacket(PacketType, ByteCount, PacketDropReason) {}
func (n NullConnectionTracer) UpdatedMetrics(rttStats *RTTStats, cwnd, bytesInFlight ByteCount, packetsInFlight int) {
}
func (n NullConnectionTracer) AcknowledgedPacket(EncryptionLevel, PacketNumber) {}

View file

@ -177,7 +177,7 @@ func (e eventPacketSent) MarshalJSONObject(enc *gojay.Encoder) {
}
type eventPacketReceived struct {
Header packetHeader
Header gojay.MarshalerJSONObject // either a shortHeader or a packetHeader
Length logging.ByteCount
PayloadLength logging.ByteCount
Frames frames

View file

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/wire"
"github.com/lucas-clemente/quic-go/logging"
"github.com/francoispqt/gojay"
@ -37,6 +36,7 @@ func (t token) MarshalJSONObject(enc *gojay.Encoder) {
}
// PacketHeader is a QUIC packet header.
// TODO: make this a long header
type packetHeader struct {
PacketType logging.PacketType
@ -50,7 +50,7 @@ type packetHeader struct {
Token *token
}
func transformHeader(hdr *wire.Header) *packetHeader {
func transformHeader(hdr *logging.Header) *packetHeader {
h := &packetHeader{
PacketType: logging.PacketTypeFromHeader(hdr),
SrcConnectionID: hdr.SrcConnectionID,
@ -63,7 +63,7 @@ func transformHeader(hdr *wire.Header) *packetHeader {
return h
}
func transformExtendedHeader(hdr *wire.ExtendedHeader) *packetHeader {
func transformLongHeader(hdr *logging.ExtendedHeader) *packetHeader {
h := transformHeader(&hdr.Header)
h.PacketNumber = hdr.PacketNumber
h.KeyPhaseBit = hdr.KeyPhase
@ -131,3 +131,27 @@ func (h packetHeaderWithTypeAndPacketNumber) MarshalJSONObject(enc *gojay.Encode
enc.StringKey("packet_type", packetType(h.PacketType).String())
enc.Int64Key("packet_number", int64(h.PacketNumber))
}
type shortHeader struct {
DestConnectionID logging.ConnectionID
PacketNumber logging.PacketNumber
KeyPhaseBit logging.KeyPhaseBit
}
func transformShortHeader(hdr *logging.ShortHeader) *shortHeader {
return &shortHeader{
DestConnectionID: hdr.DestConnectionID,
PacketNumber: hdr.PacketNumber,
KeyPhaseBit: hdr.KeyPhase,
}
}
func (h shortHeader) IsNil() bool { return false }
func (h shortHeader) MarshalJSONObject(enc *gojay.Encoder) {
enc.StringKey("packet_type", packetType(logging.PacketType1RTT).String())
if h.DestConnectionID.Len() > 0 {
enc.StringKey("dcid", h.DestConnectionID.String())
}
enc.Int64Key("packet_number", int64(h.PacketNumber))
enc.StringKey("key_phase_bit", h.KeyPhaseBit.String())
}

View file

@ -26,7 +26,7 @@ var _ = Describe("Packet Header", func() {
check := func(hdr *wire.ExtendedHeader, expected map[string]interface{}) {
buf := &bytes.Buffer{}
enc := gojay.NewEncoder(buf)
ExpectWithOffset(1, enc.Encode(transformExtendedHeader(hdr))).To(Succeed())
ExpectWithOffset(1, enc.Encode(transformLongHeader(hdr))).To(Succeed())
data := buf.Bytes()
ExpectWithOffset(1, json.Valid(data)).To(BeTrue())
checkEncoding(data, expected)

View file

@ -286,7 +286,7 @@ func (t *connectionTracer) SentPacket(hdr *wire.ExtendedHeader, packetSize loggi
for _, f := range frames {
fs = append(fs, frame{Frame: f})
}
header := *transformExtendedHeader(hdr)
header := *transformLongHeader(hdr)
t.mutex.Lock()
t.recordEvent(time.Now(), &eventPacketSent{
Header: header,
@ -297,12 +297,12 @@ func (t *connectionTracer) SentPacket(hdr *wire.ExtendedHeader, packetSize loggi
t.mutex.Unlock()
}
func (t *connectionTracer) ReceivedPacket(hdr *wire.ExtendedHeader, packetSize logging.ByteCount, frames []logging.Frame) {
func (t *connectionTracer) ReceivedLongHeaderPacket(hdr *logging.ExtendedHeader, packetSize logging.ByteCount, frames []logging.Frame) {
fs := make([]frame, len(frames))
for i, f := range frames {
fs[i] = frame{Frame: f}
}
header := *transformExtendedHeader(hdr)
header := *transformLongHeader(hdr)
t.mutex.Lock()
t.recordEvent(time.Now(), &eventPacketReceived{
Header: header,
@ -313,6 +313,22 @@ func (t *connectionTracer) ReceivedPacket(hdr *wire.ExtendedHeader, packetSize l
t.mutex.Unlock()
}
func (t *connectionTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, packetSize logging.ByteCount, frames []logging.Frame) {
fs := make([]frame, len(frames))
for i, f := range frames {
fs[i] = frame{Frame: f}
}
header := *transformShortHeader(hdr)
t.mutex.Lock()
t.recordEvent(time.Now(), &eventPacketReceived{
Header: header,
Length: packetSize,
PayloadLength: packetSize - hdr.Len(),
Frames: fs,
})
t.mutex.Unlock()
}
func (t *connectionTracer) ReceivedRetry(hdr *wire.Header) {
t.mutex.Lock()
t.recordEvent(time.Now(), &eventRetryReceived{

View file

@ -11,6 +11,8 @@ import (
"os"
"time"
"github.com/lucas-clemente/quic-go/internal/wire"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/qerr"
@ -486,8 +488,8 @@ var _ = Describe("Tracing", func() {
Expect(frames[1].(map[string]interface{})).To(HaveKeyWithValue("frame_type", "max_data"))
})
It("records a received packet", func() {
tracer.ReceivedPacket(
It("records a received Long Header packet", func() {
tracer.ReceivedLongHeaderPacket(
&logging.ExtendedHeader{
Header: logging.Header{
IsLongHeader: true,
@ -526,6 +528,37 @@ var _ = Describe("Tracing", func() {
Expect(ev["frames"].([]interface{})).To(HaveLen(2))
})
It("records a received Short Header packet", func() {
shdr := &wire.ShortHeader{
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
PacketNumber: 1337,
KeyPhase: protocol.KeyPhaseZero,
}
tracer.ReceivedShortHeaderPacket(
shdr,
789,
[]logging.Frame{
&logging.MaxStreamDataFrame{StreamID: 42, MaximumStreamData: 987},
&logging.StreamFrame{StreamID: 123, Offset: 1234, Length: 6, Fin: true},
},
)
entry := exportAndParseSingle()
Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond)))
Expect(entry.Name).To(Equal("transport:packet_received"))
ev := entry.Event
Expect(ev).To(HaveKey("raw"))
raw := ev["raw"].(map[string]interface{})
Expect(raw).To(HaveKeyWithValue("length", float64(789)))
Expect(raw).To(HaveKeyWithValue("payload_length", float64(789-shdr.Len())))
Expect(ev).To(HaveKey("header"))
hdr := ev["header"].(map[string]interface{})
Expect(hdr).To(HaveKeyWithValue("packet_type", "1RTT"))
Expect(hdr).To(HaveKeyWithValue("packet_number", float64(1337)))
Expect(hdr).To(HaveKeyWithValue("key_phase_bit", "0"))
Expect(ev).To(HaveKey("frames"))
Expect(ev["frames"].([]interface{})).To(HaveLen(2))
})
It("records a received Retry packet", func() {
tracer.ReceivedRetry(
&logging.Header{