handle WINDOW_UPDATEs for streams and connection separately

In IETF QUIC, stream 0 is a valid stream ID, and is not used to encode
WINDOW_UPDATEs for the connection any more.
This commit is contained in:
Marten Seemann
2017-10-16 18:21:01 +07:00
parent c53a83535e
commit e087ee7e9f
6 changed files with 62 additions and 42 deletions

View File

@@ -228,15 +228,8 @@ func (f *flowControlManager) RemainingConnectionWindowSize() protocol.ByteCount
return f.connFlowController.SendWindowSize()
}
// streamID may be 0 here
func (f *flowControlManager) UpdateWindow(streamID protocol.StreamID, offset protocol.ByteCount) (bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if streamID == 0 {
return f.connFlowController.UpdateSendWindow(offset), nil
}
// streamID must not be 0 here
func (f *flowControlManager) UpdateStreamWindow(streamID protocol.StreamID, offset protocol.ByteCount) (bool, error) {
fc, err := f.getFlowController(streamID)
if err != nil {
return false, err
@@ -244,6 +237,10 @@ func (f *flowControlManager) UpdateWindow(streamID protocol.StreamID, offset pro
return fc.UpdateSendWindow(offset), nil
}
func (f *flowControlManager) UpdateConnectionWindow(offset protocol.ByteCount) bool {
return f.connFlowController.UpdateSendWindow(offset)
}
func (f *flowControlManager) getFlowController(streamID protocol.StreamID) (*streamFlowController, error) {
streamFlowController, ok := f.streamFlowController[streamID]
if !ok {

View File

@@ -302,19 +302,18 @@ var _ = Describe("Flow Control Manager", func() {
Context("window updates", func() {
It("updates the window for a normal stream", func() {
fcm.NewStream(5, true)
updated, err := fcm.UpdateWindow(5, 1000)
updated, err := fcm.UpdateStreamWindow(5, 1000)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
})
It("updates the connection level window", func() {
updated, err := fcm.UpdateWindow(0, 1000)
Expect(err).ToNot(HaveOccurred())
updated := fcm.UpdateConnectionWindow(1000)
Expect(updated).To(BeTrue())
})
It("errors when called for a stream that doesn't exist", func() {
_, err := fcm.UpdateWindow(17, 1000)
_, err := fcm.UpdateStreamWindow(17, 1000)
Expect(err).To(MatchError(errMapAccess))
})
})
@@ -322,7 +321,7 @@ var _ = Describe("Flow Control Manager", func() {
Context("window sizes", func() {
It("gets the window size of a stream", func() {
fcm.NewStream(5, false)
updated, err := fcm.UpdateWindow(5, 1000)
updated, err := fcm.UpdateStreamWindow(5, 1000)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
fcm.AddBytesSent(5, 500)
@@ -333,8 +332,7 @@ var _ = Describe("Flow Control Manager", func() {
It("gets the connection window size", func() {
fcm.NewStream(5, true)
updated, err := fcm.UpdateWindow(0, 1000)
Expect(err).ToNot(HaveOccurred())
updated := fcm.UpdateConnectionWindow(1000)
Expect(updated).To(BeTrue())
fcm.AddBytesSent(5, 500)
size := fcm.RemainingConnectionWindowSize()
@@ -348,10 +346,9 @@ var _ = Describe("Flow Control Manager", func() {
It("limits the stream window size by the connection window size", func() {
fcm.NewStream(5, true)
updated, err := fcm.UpdateWindow(0, 500)
Expect(err).ToNot(HaveOccurred())
updated := fcm.UpdateConnectionWindow(500)
Expect(updated).To(BeTrue())
updated, err = fcm.UpdateWindow(5, 1000)
updated, err := fcm.UpdateStreamWindow(5, 1000)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
size, err := fcm.SendWindowSize(5)
@@ -361,8 +358,7 @@ var _ = Describe("Flow Control Manager", func() {
It("does not reduce the size of the connection level window, if the stream does not contribute", func() {
fcm.NewStream(3, false)
updated, err := fcm.UpdateWindow(0, 1000)
Expect(err).ToNot(HaveOccurred())
updated := fcm.UpdateConnectionWindow(1000)
Expect(updated).To(BeTrue())
fcm.AddBytesSent(3, 456) // WindowSize should return the same value no matter how much was sent
size := fcm.RemainingConnectionWindowSize()

View File

@@ -24,5 +24,6 @@ type FlowControlManager interface {
AddBytesSent(streamID protocol.StreamID, n protocol.ByteCount) error
SendWindowSize(streamID protocol.StreamID) (protocol.ByteCount, error)
RemainingConnectionWindowSize() protocol.ByteCount
UpdateWindow(streamID protocol.StreamID, offset protocol.ByteCount) (bool, error)
UpdateStreamWindow(streamID protocol.StreamID, offset protocol.ByteCount) (bool, error)
UpdateConnectionWindow(offset protocol.ByteCount) bool
}