pass a logging.Tracer to the packet handler map

This commit is contained in:
Marten Seemann 2020-07-10 15:23:24 +07:00
parent dc245ca6a3
commit 2f63bc0731
9 changed files with 73 additions and 48 deletions

View file

@ -3,6 +3,8 @@ package quic
import (
"net"
"github.com/lucas-clemente/quic-go/internal/mocks"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -15,7 +17,7 @@ type testConn struct {
var _ = Describe("Client Multiplexer", func() {
It("adds a new packet conn ", func() {
conn := newMockPacketConn()
_, err := getMultiplexer().AddConn(conn, 8, nil)
_, err := getMultiplexer().AddConn(conn, 8, nil, nil)
Expect(err).ToNot(HaveOccurred())
})
@ -23,27 +25,36 @@ var _ = Describe("Client Multiplexer", func() {
pconn := newMockPacketConn()
pconn.addr = &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 4321}
conn := testConn{PacketConn: pconn}
_, err := getMultiplexer().AddConn(conn, 8, nil)
tracer := mocks.NewMockTracer(mockCtrl)
_, err := getMultiplexer().AddConn(conn, 8, []byte("foobar"), tracer)
Expect(err).ToNot(HaveOccurred())
conn.counter++
_, err = getMultiplexer().AddConn(conn, 8, nil)
_, err = getMultiplexer().AddConn(conn, 8, []byte("foobar"), tracer)
Expect(err).ToNot(HaveOccurred())
Expect(getMultiplexer().(*connMultiplexer).conns).To(HaveLen(1))
})
It("errors when adding an existing conn with a different connection ID length", func() {
conn := newMockPacketConn()
_, err := getMultiplexer().AddConn(conn, 5, nil)
_, err := getMultiplexer().AddConn(conn, 5, nil, nil)
Expect(err).ToNot(HaveOccurred())
_, err = getMultiplexer().AddConn(conn, 6, nil)
_, err = getMultiplexer().AddConn(conn, 6, nil, nil)
Expect(err).To(MatchError("cannot use 6 byte connection IDs on a connection that is already using 5 byte connction IDs"))
})
It("errors when adding an existing conn with a different stateless rest key", func() {
conn := newMockPacketConn()
_, err := getMultiplexer().AddConn(conn, 7, []byte("foobar"))
_, err := getMultiplexer().AddConn(conn, 7, []byte("foobar"), nil)
Expect(err).ToNot(HaveOccurred())
_, err = getMultiplexer().AddConn(conn, 7, []byte("raboof"))
_, err = getMultiplexer().AddConn(conn, 7, []byte("raboof"), nil)
Expect(err).To(MatchError("cannot use different stateless reset keys on the same packet conn"))
})
It("errors when adding an existing conn with different tracers", func() {
conn := newMockPacketConn()
_, err := getMultiplexer().AddConn(conn, 7, nil, mocks.NewMockTracer(mockCtrl))
Expect(err).ToNot(HaveOccurred())
_, err = getMultiplexer().AddConn(conn, 7, nil, mocks.NewMockTracer(mockCtrl))
Expect(err).To(MatchError("cannot use different tracers on the same packet conn"))
})
})