trace dropped packets in the packet handler map

This commit is contained in:
Marten Seemann 2020-07-10 15:39:56 +07:00
parent 2f63bc0731
commit 48e15aed92
2 changed files with 14 additions and 3 deletions

View file

@ -274,6 +274,9 @@ func (h *packetHandlerMap) handlePacket(
connID, err := wire.ParseConnectionID(data, h.connIDLen)
if err != nil {
h.logger.Debugf("error parsing connection ID on packet from %s: %s", addr, err)
if h.tracer != nil {
h.tracer.DroppedPacket(addr, logging.PacketTypeNotDetermined, protocol.ByteCount(len(data)), logging.PacketDropHeaderParseError)
}
return
}
rcvTime := time.Now()

View file

@ -7,10 +7,14 @@ import (
"net"
"time"
"github.com/golang/mock/gomock"
"github.com/lucas-clemente/quic-go/internal/mocks"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/internal/wire"
"github.com/lucas-clemente/quic-go/logging"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -19,6 +23,7 @@ var _ = Describe("Packet Handler Map", func() {
var (
handler *packetHandlerMap
conn *mockPacketConn
tracer *mocks.MockTracer
connIDLen int
statelessResetKey []byte
@ -46,11 +51,12 @@ var _ = Describe("Packet Handler Map", func() {
BeforeEach(func() {
statelessResetKey = nil
connIDLen = 0
tracer = mocks.NewMockTracer(mockCtrl)
})
JustBeforeEach(func() {
conn = newMockPacketConn()
handler = newPacketHandlerMap(conn, connIDLen, statelessResetKey, nil, utils.DefaultLogger).(*packetHandlerMap)
handler = newPacketHandlerMap(conn, connIDLen, statelessResetKey, tracer, utils.DefaultLogger).(*packetHandlerMap)
})
AfterEach(func() {
@ -122,7 +128,9 @@ var _ = Describe("Packet Handler Map", func() {
})
It("drops unparseable packets", func() {
handler.handlePacket(nil, nil, []byte{0, 1, 2, 3})
addr := &net.UDPAddr{IP: net.IPv4(9, 8, 7, 6), Port: 1234}
tracer.EXPECT().DroppedPacket(addr, logging.PacketTypeNotDetermined, protocol.ByteCount(4), logging.PacketDropHeaderParseError)
handler.handlePacket(addr, nil, []byte{0, 1, 2, 3})
})
It("deletes removed sessions immediately", func() {