mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
remove counting of streams from the IETF streamsMap
Streams have to be counted to enforce the max stream limit. We don't advertise a max stream limit in the TLS handshake yet, so this never worked for IETF QUIC. Removing this will make implementing unidirectional streams easier.
This commit is contained in:
parent
a20e94ee16
commit
fa4724c8eb
2 changed files with 5 additions and 173 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/lucas-clemente/quic-go/internal/handshake"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/wire"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -43,8 +42,6 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Expect(s).ToNot(BeNil())
|
||||
Expect(s.StreamID()).To(Equal(protocol.StreamID(1)))
|
||||
Expect(m.streams).To(HaveLen(1))
|
||||
Expect(m.numIncomingStreams).To(BeEquivalentTo(1))
|
||||
Expect(m.numOutgoingStreams).To(BeZero())
|
||||
})
|
||||
|
||||
It("rejects streams with even IDs", func() {
|
||||
|
@ -62,11 +59,11 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
It("gets existing streams", func() {
|
||||
s, err := m.GetOrOpenStream(5)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
numStreams := m.numIncomingStreams
|
||||
numStreams := len(m.streams)
|
||||
s, err = m.GetOrOpenStream(5)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(s.StreamID()).To(Equal(protocol.StreamID(5)))
|
||||
Expect(m.numIncomingStreams).To(Equal(numStreams))
|
||||
Expect(m.streams).To(HaveLen(numStreams))
|
||||
})
|
||||
|
||||
It("returns nil for closed streams", func() {
|
||||
|
@ -95,46 +92,14 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(BeNil())
|
||||
})
|
||||
|
||||
Context("counting streams", func() {
|
||||
It("errors when too many streams are opened", func() {
|
||||
for i := uint32(0); i < m.maxIncomingStreams; i++ {
|
||||
_, err := m.GetOrOpenStream(protocol.StreamID(i*2 + 1))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
_, err := m.GetOrOpenStream(protocol.StreamID(2*m.maxIncomingStreams + 3))
|
||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||
})
|
||||
|
||||
It("errors when too many streams are opened implicitely", func() {
|
||||
_, err := m.GetOrOpenStream(protocol.StreamID(m.maxIncomingStreams*2 + 3))
|
||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||
})
|
||||
|
||||
It("does not error when many streams are opened and closed", func() {
|
||||
for i := uint32(2); i < 10*m.maxIncomingStreams; i++ {
|
||||
str, err := m.GetOrOpenStream(protocol.StreamID(i*2 + 1))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
deleteStream(str.StreamID())
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("server-side streams", func() {
|
||||
It("doesn't allow opening streams before receiving the transport parameters", func() {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||
})
|
||||
|
||||
It("opens a stream 2 first", func() {
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: 10000})
|
||||
s, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(s).ToNot(BeNil())
|
||||
Expect(s.StreamID()).To(Equal(protocol.StreamID(2)))
|
||||
Expect(m.numIncomingStreams).To(BeZero())
|
||||
Expect(m.numOutgoingStreams).To(BeEquivalentTo(1))
|
||||
})
|
||||
|
||||
It("returns the error when the streamsMap was closed", func() {
|
||||
|
@ -145,7 +110,6 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
})
|
||||
|
||||
It("doesn't reopen an already closed stream", func() {
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: 10000})
|
||||
str, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str.StreamID()).To(Equal(protocol.StreamID(2)))
|
||||
|
@ -156,96 +120,7 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Expect(str).To(BeNil())
|
||||
})
|
||||
|
||||
Context("counting streams", func() {
|
||||
const maxOutgoingStreams = 50
|
||||
|
||||
BeforeEach(func() {
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: maxOutgoingStreams})
|
||||
|
||||
})
|
||||
|
||||
It("errors when too many streams are opened", func() {
|
||||
for i := 1; i <= maxOutgoingStreams; i++ {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||
})
|
||||
|
||||
It("does not error when many streams are opened and closed", func() {
|
||||
for i := 2; i < 10*maxOutgoingStreams; i++ {
|
||||
str, err := m.OpenStream()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
deleteStream(str.StreamID())
|
||||
}
|
||||
})
|
||||
|
||||
It("allows many server- and client-side streams at the same time", func() {
|
||||
for i := 1; i < maxOutgoingStreams; i++ {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
for i := 0; i < maxOutgoingStreams; i++ {
|
||||
_, err := m.GetOrOpenStream(protocol.StreamID(2*i + 1))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Context("opening streams synchronously", func() {
|
||||
const maxOutgoingStreams = 10
|
||||
|
||||
BeforeEach(func() {
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: maxOutgoingStreams})
|
||||
})
|
||||
|
||||
openMaxNumStreams := func() {
|
||||
for i := 1; i <= maxOutgoingStreams; i++ {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||
}
|
||||
|
||||
It("waits until another stream is closed", func() {
|
||||
openMaxNumStreams()
|
||||
var str Stream
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
var err error
|
||||
str, err = m.OpenStreamSync()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
close(done)
|
||||
}()
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
deleteStream(6)
|
||||
Eventually(done).Should(BeClosed())
|
||||
Expect(str.StreamID()).To(Equal(protocol.StreamID(2*maxOutgoingStreams + 2)))
|
||||
})
|
||||
|
||||
It("stops waiting when an error is registered", func() {
|
||||
testErr := errors.New("test error")
|
||||
openMaxNumStreams()
|
||||
for _, str := range m.streams {
|
||||
str.(*MockStreamI).EXPECT().closeForShutdown(testErr)
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
_, err := m.OpenStreamSync()
|
||||
Expect(err).To(MatchError(testErr))
|
||||
close(done)
|
||||
}()
|
||||
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
m.CloseWithError(testErr)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("immediately returns when OpenStreamSync is called after an error was registered", func() {
|
||||
testErr := errors.New("test error")
|
||||
m.CloseWithError(testErr)
|
||||
|
@ -404,7 +279,6 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Context("as a client", func() {
|
||||
BeforeEach(func() {
|
||||
setNewStreamsMap(protocol.PerspectiveClient)
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: 10000})
|
||||
})
|
||||
|
||||
Context("server-side streams", func() {
|
||||
|
@ -425,8 +299,6 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(s.StreamID()).To(Equal(protocol.StreamID(2)))
|
||||
Expect(m.streams).To(HaveLen(1))
|
||||
Expect(m.numOutgoingStreams).To(BeZero())
|
||||
Expect(m.numIncomingStreams).To(BeEquivalentTo(1))
|
||||
})
|
||||
|
||||
It("opens skipped streams", func() {
|
||||
|
@ -435,8 +307,6 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Expect(m.streams).To(HaveKey(protocol.StreamID(2)))
|
||||
Expect(m.streams).To(HaveKey(protocol.StreamID(4)))
|
||||
Expect(m.streams).To(HaveKey(protocol.StreamID(6)))
|
||||
Expect(m.numOutgoingStreams).To(BeZero())
|
||||
Expect(m.numIncomingStreams).To(BeEquivalentTo(3))
|
||||
})
|
||||
|
||||
It("doesn't reopen an already closed stream", func() {
|
||||
|
@ -454,13 +324,10 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
Context("client-side streams", func() {
|
||||
It("starts with stream 1", func() {
|
||||
setNewStreamsMap(protocol.PerspectiveClient)
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: 10000})
|
||||
s, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(s).ToNot(BeNil())
|
||||
Expect(s.StreamID()).To(BeEquivalentTo(1))
|
||||
Expect(m.numOutgoingStreams).To(BeEquivalentTo(1))
|
||||
Expect(m.numIncomingStreams).To(BeZero())
|
||||
})
|
||||
|
||||
It("opens multiple streams", func() {
|
||||
|
@ -510,24 +377,19 @@ var _ = Describe("Streams Map (for IETF QUIC)", func() {
|
|||
It("deletes an incoming stream", func() {
|
||||
_, err := m.GetOrOpenStream(3) // open stream 1 and 3
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(m.numIncomingStreams).To(BeEquivalentTo(2))
|
||||
err = m.DeleteStream(1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(m.streams).To(HaveLen(1))
|
||||
Expect(m.streams).To(HaveKey(protocol.StreamID(3)))
|
||||
Expect(m.numIncomingStreams).To(BeEquivalentTo(1))
|
||||
})
|
||||
|
||||
It("deletes an outgoing stream", func() {
|
||||
m.UpdateLimits(&handshake.TransportParameters{MaxStreams: 10000})
|
||||
_, err := m.OpenStream() // open stream 2
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(m.numOutgoingStreams).To(BeEquivalentTo(2))
|
||||
err = m.DeleteStream(2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(m.numOutgoingStreams).To(BeEquivalentTo(1))
|
||||
})
|
||||
|
||||
It("errors when the stream doesn't exist", func() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue