From 1f644debd4b26bd812b83838e6d1b24ac083f2d1 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 1 Nov 2017 14:32:03 +0700 Subject: [PATCH] set if a stream contributes to connection flow control This depends on the version. In gQUIC, stream 1 and 3 don't contribute, in IETF QUIC only stream 0 doesn't contribute. --- internal/protocol/version.go | 11 +++++++++++ internal/protocol/version_test.go | 15 +++++++++++++++ session.go | 7 +------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/internal/protocol/version.go b/internal/protocol/version.go index f9bfef36..bf206c01 100644 --- a/internal/protocol/version.go +++ b/internal/protocol/version.go @@ -68,6 +68,17 @@ func (vn VersionNumber) CryptoStreamID() StreamID { return 0 } +// StreamContributesToConnectionFlowControl says if a stream contributes to connection-level flow control +func (vn VersionNumber) StreamContributesToConnectionFlowControl(id StreamID) bool { + if id == vn.CryptoStreamID() { + return false + } + if vn.isGQUIC() && id == 3 { + return false + } + return true +} + func (vn VersionNumber) isGQUIC() bool { return vn > gquicVersion0 && vn <= maxGquicVersion } diff --git a/internal/protocol/version_test.go b/internal/protocol/version_test.go index 5a23aea4..6d9fff3e 100644 --- a/internal/protocol/version_test.go +++ b/internal/protocol/version_test.go @@ -52,6 +52,21 @@ var _ = Describe("Version", func() { Expect(VersionTLS.CryptoStreamID()).To(Equal(StreamID(0))) }) + It("says if a stream contributes to connection-level flowcontrol, for gQUIC", func() { + Expect(Version39.StreamContributesToConnectionFlowControl(1)).To(BeFalse()) + Expect(Version39.StreamContributesToConnectionFlowControl(2)).To(BeTrue()) + Expect(Version39.StreamContributesToConnectionFlowControl(3)).To(BeFalse()) + Expect(Version39.StreamContributesToConnectionFlowControl(4)).To(BeTrue()) + Expect(Version39.StreamContributesToConnectionFlowControl(5)).To(BeTrue()) + }) + + It("says if a stream contributes to connection-level flowcontrol, for TLS", func() { + Expect(VersionTLS.StreamContributesToConnectionFlowControl(0)).To(BeFalse()) + Expect(VersionTLS.StreamContributesToConnectionFlowControl(1)).To(BeTrue()) + Expect(VersionTLS.StreamContributesToConnectionFlowControl(2)).To(BeTrue()) + Expect(VersionTLS.StreamContributesToConnectionFlowControl(3)).To(BeTrue()) + }) + It("recognizes supported versions", func() { Expect(IsSupportedVersion(SupportedVersions, 0)).To(BeFalse()) Expect(IsSupportedVersion(SupportedVersions, SupportedVersions[0])).To(BeTrue()) diff --git a/session.go b/session.go index b9211012..34c820a3 100644 --- a/session.go +++ b/session.go @@ -818,18 +818,13 @@ func (s *session) queueResetStreamFrame(id protocol.StreamID, offset protocol.By } func (s *session) newStream(id protocol.StreamID) streamI { - // TODO: find a better solution for determining which streams contribute to connection level flow control - var contributesToConnection bool - if id != 0 && id != 1 && id != 3 { - contributesToConnection = true - } var initialSendWindow protocol.ByteCount if s.peerParams != nil { initialSendWindow = s.peerParams.StreamFlowControlWindow } flowController := flowcontrol.NewStreamFlowController( id, - contributesToConnection, + s.version.StreamContributesToConnectionFlowControl(id), s.connFlowController, protocol.ReceiveStreamFlowControlWindow, protocol.ByteCount(s.config.MaxReceiveStreamFlowControlWindow),