introduce a type for the stateless reset key (#3621)

This commit is contained in:
Marten Seemann 2022-11-16 16:11:25 -06:00 committed by GitHub
parent b8447041bb
commit 8d496ebb5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 27 deletions

View file

@ -25,15 +25,16 @@ var _ = Describe("Multiplexer", func() {
})
It("recognizes when the same connection is added twice", func() {
srk := &StatelessResetKey{'f', 'o', 'o', 'b', 'a', 'r'}
pconn := NewMockPacketConn(mockCtrl)
pconn.EXPECT().LocalAddr().Return(&net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 4321}).Times(2)
pconn.EXPECT().ReadFrom(gomock.Any()).Do(func([]byte) { <-(make(chan struct{})) }).MaxTimes(1)
conn := testConn{PacketConn: pconn}
tracer := mocklogging.NewMockTracer(mockCtrl)
_, err := getMultiplexer().AddConn(conn, 8, []byte("foobar"), tracer)
_, err := getMultiplexer().AddConn(conn, 8, srk, tracer)
Expect(err).ToNot(HaveOccurred())
conn.counter++
_, err = getMultiplexer().AddConn(conn, 8, []byte("foobar"), tracer)
_, err = getMultiplexer().AddConn(conn, 8, srk, tracer)
Expect(err).ToNot(HaveOccurred())
Expect(getMultiplexer().(*connMultiplexer).conns).To(HaveLen(1))
})
@ -49,12 +50,14 @@ var _ = Describe("Multiplexer", func() {
})
It("errors when adding an existing conn with a different stateless rest key", func() {
srk1 := &StatelessResetKey{'f', 'o', 'o'}
srk2 := &StatelessResetKey{'b', 'a', 'r'}
conn := NewMockPacketConn(mockCtrl)
conn.EXPECT().ReadFrom(gomock.Any()).Do(func([]byte) { <-(make(chan struct{})) }).MaxTimes(1)
conn.EXPECT().LocalAddr().Return(&net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234}).Times(2)
_, err := getMultiplexer().AddConn(conn, 7, []byte("foobar"), nil)
_, err := getMultiplexer().AddConn(conn, 7, srk1, nil)
Expect(err).ToNot(HaveOccurred())
_, err = getMultiplexer().AddConn(conn, 7, []byte("raboof"), nil)
_, err = getMultiplexer().AddConn(conn, 7, srk2, nil)
Expect(err).To(MatchError("cannot use different stateless reset keys on the same packet conn"))
})