change fcm.SendWindowSize to include conn window to simplify framer

This commit is contained in:
Lucas Clemente
2016-07-26 17:06:54 +02:00
parent ebf41d9f26
commit 5f774c8e03
6 changed files with 49 additions and 39 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/utils"
)
type flowControlManager struct {
@@ -146,8 +147,17 @@ func (f *flowControlManager) SendWindowSize(streamID protocol.StreamID) (protoco
if err != nil {
return 0, err
}
res := streamFlowController.SendWindowSize()
return streamFlowController.SendWindowOffset(), nil
contributes, ok := f.contributesToConnectionFlowControl[streamID]
if !ok {
return 0, errMapAccess
}
if contributes {
res = utils.MinByteCount(res, f.streamFlowController[0].SendWindowSize())
}
return res, nil
}
func (f *flowControlManager) RemainingConnectionWindowSize() protocol.ByteCount {

View File

@@ -141,24 +141,37 @@ var _ = Describe("Flow Control Manager", func() {
Context("window sizes", func() {
It("gets the window size of a stream", func() {
fcm.NewStream(5, true)
fcm.NewStream(5, false)
updated, err := fcm.UpdateWindow(5, 0x1000)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
fcm.AddBytesSent(5, 0x500) // WindowSize should return the same value no matter how much was sent
fcm.AddBytesSent(5, 0x500)
size, err := fcm.SendWindowSize(5)
Expect(err).ToNot(HaveOccurred())
Expect(size).To(Equal(protocol.ByteCount(0x1000)))
Expect(size).To(Equal(protocol.ByteCount(0x1000 - 0x500)))
})
It("gets the window size of a stream", func() {
It("gets the connection window size", func() {
fcm.NewStream(5, true)
updated, err := fcm.UpdateWindow(0, 0x1000)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
fcm.AddBytesSent(5, 0x456) // WindowSize should return the same value no matter how much was sent
fcm.AddBytesSent(5, 0x500)
size := fcm.RemainingConnectionWindowSize()
Expect(size).To(Equal(protocol.ByteCount(0x1000 - 0x456)))
Expect(size).To(Equal(protocol.ByteCount(0x1000 - 0x500)))
})
It("limits the stream window size by the connection window size", func() {
fcm.NewStream(5, true)
updated, err := fcm.UpdateWindow(0, 0x500)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
updated, err = fcm.UpdateWindow(5, 0x1000)
Expect(err).ToNot(HaveOccurred())
Expect(updated).To(BeTrue())
size, err := fcm.SendWindowSize(5)
Expect(err).NotTo(HaveOccurred())
Expect(size).To(Equal(protocol.ByteCount(0x500)))
})
It("does not reduce the size of the connection level window, if the stream does not contribute", func() {