introduce a type for the stream number

This commit is contained in:
Marten Seemann 2019-06-05 15:21:46 +08:00
parent 0dd26f4a4c
commit a8633a952c
23 changed files with 100 additions and 97 deletions

View file

@ -354,8 +354,8 @@ func (c *client) createNewTLSSession(version protocol.VersionNumber) error {
InitialMaxStreamDataUni: protocol.InitialMaxStreamData,
InitialMaxData: protocol.InitialMaxData,
IdleTimeout: c.config.IdleTimeout,
MaxBidiStreams: uint64(c.config.MaxIncomingStreams),
MaxUniStreams: uint64(c.config.MaxIncomingUniStreams),
MaxBidiStreamNum: protocol.StreamNum(c.config.MaxIncomingStreams),
MaxUniStreamNum: protocol.StreamNum(c.config.MaxIncomingUniStreams),
MaxAckDelay: protocol.MaxAckDelayInclGranularity,
AckDelayExponent: protocol.AckDelayExponent,
DisableMigration: true,

View file

@ -26,15 +26,15 @@ var _ = Describe("Transport Parameters", func() {
InitialMaxStreamDataBidiRemote: 0x2345,
InitialMaxStreamDataUni: 0x3456,
InitialMaxData: 0x4567,
MaxBidiStreams: 1337,
MaxUniStreams: 7331,
MaxBidiStreamNum: 1337,
MaxUniStreamNum: 7331,
IdleTimeout: 42 * time.Second,
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
AckDelayExponent: 14,
MaxAckDelay: 37 * time.Millisecond,
StatelessResetToken: &[16]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00},
}
Expect(p.String()).To(Equal("&handshake.TransportParameters{OriginalConnectionID: 0xdeadbeef, InitialMaxStreamDataBidiLocal: 0x1234, InitialMaxStreamDataBidiRemote: 0x2345, InitialMaxStreamDataUni: 0x3456, InitialMaxData: 0x4567, MaxBidiStreams: 1337, MaxUniStreams: 7331, IdleTimeout: 42s, AckDelayExponent: 14, MaxAckDelay: 37ms, StatelessResetToken: 0x112233445566778899aabbccddeeff00}"))
Expect(p.String()).To(Equal("&handshake.TransportParameters{OriginalConnectionID: 0xdeadbeef, InitialMaxStreamDataBidiLocal: 0x1234, InitialMaxStreamDataBidiRemote: 0x2345, InitialMaxStreamDataUni: 0x3456, InitialMaxData: 0x4567, MaxBidiStreamNum: 1337, MaxUniStreamNum: 7331, IdleTimeout: 42s, AckDelayExponent: 14, MaxAckDelay: 37ms, StatelessResetToken: 0x112233445566778899aabbccddeeff00}"))
})
It("has a string representation, if there's no stateless reset token", func() {
@ -43,14 +43,14 @@ var _ = Describe("Transport Parameters", func() {
InitialMaxStreamDataBidiRemote: 0x2345,
InitialMaxStreamDataUni: 0x3456,
InitialMaxData: 0x4567,
MaxBidiStreams: 1337,
MaxUniStreams: 7331,
MaxBidiStreamNum: 1337,
MaxUniStreamNum: 7331,
IdleTimeout: 42 * time.Second,
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
AckDelayExponent: 14,
MaxAckDelay: 37 * time.Second,
}
Expect(p.String()).To(Equal("&handshake.TransportParameters{OriginalConnectionID: 0xdeadbeef, InitialMaxStreamDataBidiLocal: 0x1234, InitialMaxStreamDataBidiRemote: 0x2345, InitialMaxStreamDataUni: 0x3456, InitialMaxData: 0x4567, MaxBidiStreams: 1337, MaxUniStreams: 7331, IdleTimeout: 42s, AckDelayExponent: 14, MaxAckDelay: 37s}"))
Expect(p.String()).To(Equal("&handshake.TransportParameters{OriginalConnectionID: 0xdeadbeef, InitialMaxStreamDataBidiLocal: 0x1234, InitialMaxStreamDataBidiRemote: 0x2345, InitialMaxStreamDataUni: 0x3456, InitialMaxData: 0x4567, MaxBidiStreamNum: 1337, MaxUniStreamNum: 7331, IdleTimeout: 42s, AckDelayExponent: 14, MaxAckDelay: 37s}"))
})
It("marshals and unmarshals", func() {
@ -68,8 +68,8 @@ var _ = Describe("Transport Parameters", func() {
InitialMaxStreamDataUni: protocol.ByteCount(getRandomValue()),
InitialMaxData: protocol.ByteCount(getRandomValue()),
IdleTimeout: 0xcafe * time.Second,
MaxBidiStreams: getRandomValue(),
MaxUniStreams: getRandomValue(),
MaxBidiStreamNum: protocol.StreamNum(getRandomValue()),
MaxUniStreamNum: protocol.StreamNum(getRandomValue()),
DisableMigration: true,
StatelessResetToken: &token,
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
@ -84,8 +84,8 @@ var _ = Describe("Transport Parameters", func() {
Expect(p.InitialMaxStreamDataBidiRemote).To(Equal(params.InitialMaxStreamDataBidiRemote))
Expect(p.InitialMaxStreamDataUni).To(Equal(params.InitialMaxStreamDataUni))
Expect(p.InitialMaxData).To(Equal(params.InitialMaxData))
Expect(p.MaxUniStreams).To(Equal(params.MaxUniStreams))
Expect(p.MaxBidiStreams).To(Equal(params.MaxBidiStreams))
Expect(p.MaxUniStreamNum).To(Equal(params.MaxUniStreamNum))
Expect(p.MaxBidiStreamNum).To(Equal(params.MaxBidiStreamNum))
Expect(p.IdleTimeout).To(Equal(params.IdleTimeout))
Expect(p.DisableMigration).To(Equal(params.DisableMigration))
Expect(p.StatelessResetToken).To(Equal(params.StatelessResetToken))

View file

@ -43,8 +43,8 @@ type TransportParameters struct {
MaxPacketSize protocol.ByteCount
MaxUniStreams uint64
MaxBidiStreams uint64
MaxUniStreamNum protocol.StreamNum
MaxBidiStreamNum protocol.StreamNum
IdleTimeout time.Duration
DisableMigration bool
@ -172,9 +172,9 @@ func (p *TransportParameters) readNumericTransportParameter(
case initialMaxDataParameterID:
p.InitialMaxData = protocol.ByteCount(val)
case initialMaxStreamsBidiParameterID:
p.MaxBidiStreams = val
p.MaxBidiStreamNum = protocol.StreamNum(val)
case initialMaxStreamsUniParameterID:
p.MaxUniStreams = val
p.MaxUniStreamNum = protocol.StreamNum(val)
case idleTimeoutParameterID:
p.IdleTimeout = utils.MaxDuration(protocol.MinRemoteIdleTimeout, time.Duration(val)*time.Millisecond)
case maxPacketSizeParameterID:
@ -213,9 +213,9 @@ func (p *TransportParameters) Marshal() []byte {
// initial_max_data
p.marshalVarintParam(b, initialMaxDataParameterID, uint64(p.InitialMaxData))
// initial_max_bidi_streams
p.marshalVarintParam(b, initialMaxStreamsBidiParameterID, p.MaxBidiStreams)
p.marshalVarintParam(b, initialMaxStreamsBidiParameterID, uint64(p.MaxBidiStreamNum))
// initial_max_uni_streams
p.marshalVarintParam(b, initialMaxStreamsUniParameterID, p.MaxUniStreams)
p.marshalVarintParam(b, initialMaxStreamsUniParameterID, uint64(p.MaxUniStreamNum))
// idle_timeout
p.marshalVarintParam(b, idleTimeoutParameterID, uint64(p.IdleTimeout/time.Millisecond))
// max_packet_size
@ -260,8 +260,8 @@ func (p *TransportParameters) marshalVarintParam(b *bytes.Buffer, id transportPa
// String returns a string representation, intended for logging.
func (p *TransportParameters) String() string {
logString := "&handshake.TransportParameters{OriginalConnectionID: %s, InitialMaxStreamDataBidiLocal: %#x, InitialMaxStreamDataBidiRemote: %#x, InitialMaxStreamDataUni: %#x, InitialMaxData: %#x, MaxBidiStreams: %d, MaxUniStreams: %d, IdleTimeout: %s, AckDelayExponent: %d, MaxAckDelay: %s"
logParams := []interface{}{p.OriginalConnectionID, p.InitialMaxStreamDataBidiLocal, p.InitialMaxStreamDataBidiRemote, p.InitialMaxStreamDataUni, p.InitialMaxData, p.MaxBidiStreams, p.MaxUniStreams, p.IdleTimeout, p.AckDelayExponent, p.MaxAckDelay}
logString := "&handshake.TransportParameters{OriginalConnectionID: %s, InitialMaxStreamDataBidiLocal: %#x, InitialMaxStreamDataBidiRemote: %#x, InitialMaxStreamDataUni: %#x, InitialMaxData: %#x, MaxBidiStreamNum: %d, MaxUniStreamNum: %d, IdleTimeout: %s, AckDelayExponent: %d, MaxAckDelay: %s"
logParams := []interface{}{p.OriginalConnectionID, p.InitialMaxStreamDataBidiLocal, p.InitialMaxStreamDataBidiRemote, p.InitialMaxStreamDataUni, p.InitialMaxData, p.MaxBidiStreamNum, p.MaxUniStreamNum, p.IdleTimeout, p.AckDelayExponent, p.MaxAckDelay}
if p.StatelessResetToken != nil { // the client never sends a stateless reset token
logString += ", StatelessResetToken: %#x"
logParams = append(logParams, *p.StatelessResetToken)

View file

@ -62,10 +62,6 @@ const MinStatelessResetSize = 1 /* first byte */ + 22 /* random bytes */ + 16 /*
// MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet.
const MinConnectionIDLenInitial = 8
// MaxStreamCount is the maximum stream count value that can be sent in MAX_STREAMS frames
// and as the stream count in the transport parameters
const MaxStreamCount = 1 << 60
// DefaultAckDelayExponent is the default ack delay exponent
const DefaultAckDelayExponent = 3

View file

@ -7,6 +7,13 @@ type StreamID int64
// The first valid stream ID in QUIC is 0.
const InvalidStreamID StreamID = -1
// StreamNum is the stream number
type StreamNum int64
// MaxStreamCount is the maximum stream count value that can be sent in MAX_STREAMS frames
// and as the stream count in the transport parameters
const MaxStreamCount StreamNum = 1 << 60
// StreamType encodes if this is a unidirectional or bidirectional stream
type StreamType uint8
@ -35,13 +42,13 @@ func (s StreamID) Type() StreamType {
// StreamNum returns how many streams in total are below this
// Example: for stream 9 it returns 3 (i.e. streams 1, 5 and 9)
func (s StreamID) StreamNum() uint64 {
return uint64(s/4) + 1
func (s StreamID) StreamNum() StreamNum {
return StreamNum(s/4) + 1
}
// MaxStreamID is the highest stream ID that a peer is allowed to open,
// when it is allowed to open numStreams.
func MaxStreamID(stype StreamType, numStreams uint64, pers Perspective) StreamID {
func MaxStreamID(stype StreamType, numStreams StreamNum, pers Perspective) StreamID {
if numStreams == 0 {
return InvalidStreamID
}

View file

@ -168,8 +168,8 @@ var _ = Describe("Frame parsing", func() {
It("unpacks MAX_STREAMS frames", func() {
f := &MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: 0x1337,
Type: protocol.StreamTypeBidi,
MaxStreamNum: 0x1337,
}
buf := &bytes.Buffer{}
err := f.Write(buf, versionIETFFrames)

View file

@ -36,9 +36,9 @@ func LogFrame(logger utils.Logger, frame Frame, sent bool) {
case *MaxStreamsFrame:
switch f.Type {
case protocol.StreamTypeUni:
logger.Debugf("\t%s &wire.MaxStreamsFrame{Type: uni, MaxStreams: %d}", dir, f.MaxStreams)
logger.Debugf("\t%s &wire.MaxStreamsFrame{Type: uni, MaxStreamNum: %d}", dir, f.MaxStreamNum)
case protocol.StreamTypeBidi:
logger.Debugf("\t%s &wire.MaxStreamsFrame{Type: bidi, MaxStreams: %d}", dir, f.MaxStreams)
logger.Debugf("\t%s &wire.MaxStreamsFrame{Type: bidi, MaxStreamNum: %d}", dir, f.MaxStreamNum)
}
case *StreamsBlockedFrame:
switch f.Type {

View file

@ -89,11 +89,11 @@ var _ = Describe("Frame logging", func() {
It("logs MAX_STREAMS frames", func() {
frame := &MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: 42,
Type: protocol.StreamTypeBidi,
MaxStreamNum: 42,
}
LogFrame(logger, frame, false)
Expect(buf.String()).To(ContainSubstring("\t<- &wire.MaxStreamsFrame{Type: bidi, MaxStreams: 42}\n"))
Expect(buf.String()).To(ContainSubstring("\t<- &wire.MaxStreamsFrame{Type: bidi, MaxStreamNum: 42}\n"))
})
It("logs STREAMS_BLOCKED frames", func() {

View file

@ -9,8 +9,8 @@ import (
// A MaxStreamsFrame is a MAX_STREAMS frame
type MaxStreamsFrame struct {
Type protocol.StreamType
MaxStreams uint64
Type protocol.StreamType
MaxStreamNum protocol.StreamNum
}
func parseMaxStreamsFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStreamsFrame, error) {
@ -30,7 +30,7 @@ func parseMaxStreamsFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStream
if err != nil {
return nil, err
}
f.MaxStreams = streamID
f.MaxStreamNum = protocol.StreamNum(streamID)
return f, nil
}
@ -41,11 +41,11 @@ func (f *MaxStreamsFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) error
case protocol.StreamTypeUni:
b.WriteByte(0x13)
}
utils.WriteVarInt(b, f.MaxStreams)
utils.WriteVarInt(b, uint64(f.MaxStreamNum))
return nil
}
// Length of a written frame
func (f *MaxStreamsFrame) Length(protocol.VersionNumber) protocol.ByteCount {
return 1 + utils.VarIntLen(f.MaxStreams)
return 1 + utils.VarIntLen(uint64(f.MaxStreamNum))
}

View file

@ -18,7 +18,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
f, err := parseMaxStreamsFrame(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
Expect(f.Type).To(Equal(protocol.StreamTypeBidi))
Expect(f.MaxStreams).To(BeEquivalentTo(0xdecaf))
Expect(f.MaxStreamNum).To(BeEquivalentTo(0xdecaf))
Expect(b.Len()).To(BeZero())
})
@ -29,7 +29,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
f, err := parseMaxStreamsFrame(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
Expect(f.Type).To(Equal(protocol.StreamTypeUni))
Expect(f.MaxStreams).To(BeEquivalentTo(0xdecaf))
Expect(f.MaxStreamNum).To(BeEquivalentTo(0xdecaf))
Expect(b.Len()).To(BeZero())
})
@ -48,8 +48,8 @@ var _ = Describe("MAX_STREAMS frame", func() {
Context("writing", func() {
It("for a bidirectional stream", func() {
f := &MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: 0xdeadbeef,
Type: protocol.StreamTypeBidi,
MaxStreamNum: 0xdeadbeef,
}
b := &bytes.Buffer{}
Expect(f.Write(b, protocol.VersionWhatever)).To(Succeed())
@ -60,8 +60,8 @@ var _ = Describe("MAX_STREAMS frame", func() {
It("for a unidirectional stream", func() {
f := &MaxStreamsFrame{
Type: protocol.StreamTypeUni,
MaxStreams: 0xdecafbad,
Type: protocol.StreamTypeUni,
MaxStreamNum: 0xdecafbad,
}
b := &bytes.Buffer{}
Expect(f.Write(b, protocol.VersionWhatever)).To(Succeed())
@ -71,7 +71,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
})
It("has the correct min length", func() {
frame := MaxStreamsFrame{MaxStreams: 0x1337}
frame := MaxStreamsFrame{MaxStreamNum: 0x1337}
Expect(frame.Length(protocol.VersionWhatever)).To(Equal(1 + utils.VarIntLen(0x1337)))
})
})

View file

@ -10,7 +10,7 @@ import (
// A StreamsBlockedFrame is a STREAMS_BLOCKED frame
type StreamsBlockedFrame struct {
Type protocol.StreamType
StreamLimit uint64
StreamLimit protocol.StreamNum
}
func parseStreamsBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*StreamsBlockedFrame, error) {
@ -30,7 +30,7 @@ func parseStreamsBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*Strea
if err != nil {
return nil, err
}
f.StreamLimit = streamLimit
f.StreamLimit = protocol.StreamNum(streamLimit)
return f, nil
}
@ -42,11 +42,11 @@ func (f *StreamsBlockedFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) e
case protocol.StreamTypeUni:
b.WriteByte(0x17)
}
utils.WriteVarInt(b, f.StreamLimit)
utils.WriteVarInt(b, uint64(f.StreamLimit))
return nil
}
// Length of a written frame
func (f *StreamsBlockedFrame) Length(_ protocol.VersionNumber) protocol.ByteCount {
return 1 + utils.VarIntLen(f.StreamLimit)
return 1 + utils.VarIntLen(uint64(f.StreamLimit))
}

View file

@ -448,8 +448,8 @@ func (s *server) createNewSession(
InitialMaxStreamDataUni: protocol.InitialMaxStreamData,
InitialMaxData: protocol.InitialMaxData,
IdleTimeout: s.config.IdleTimeout,
MaxBidiStreams: uint64(s.config.MaxIncomingStreams),
MaxUniStreams: uint64(s.config.MaxIncomingUniStreams),
MaxBidiStreamNum: protocol.StreamNum(s.config.MaxIncomingStreams),
MaxUniStreamNum: protocol.StreamNum(s.config.MaxIncomingUniStreams),
MaxAckDelay: protocol.MaxAckDelayInclGranularity,
AckDelayExponent: protocol.AckDelayExponent,
DisableMigration: true,

View file

@ -250,8 +250,8 @@ var _ = Describe("Session", func() {
Context("handling MAX_STREAM_ID frames", func() {
It("passes the frame to the streamsMap", func() {
f := &wire.MaxStreamsFrame{
Type: protocol.StreamTypeUni,
MaxStreams: 10,
Type: protocol.StreamTypeUni,
MaxStreamNum: 10,
}
streamManager.EXPECT().HandleMaxStreamsFrame(f)
err := sess.handleMaxStreamsFrame(f)
@ -259,7 +259,7 @@ var _ = Describe("Session", func() {
})
It("returns errors", func() {
f := &wire.MaxStreamsFrame{MaxStreams: 10}
f := &wire.MaxStreamsFrame{MaxStreamNum: 10}
testErr := errors.New("test error")
streamManager.EXPECT().HandleMaxStreamsFrame(f).Return(testErr)
err := sess.handleMaxStreamsFrame(f)

View file

@ -39,7 +39,7 @@ var _ streamManager = &streamsMap{}
func newStreamsMap(
sender streamSender,
newFlowController func(protocol.StreamID) flowcontrol.StreamFlowController,
maxIncomingStreams uint64,
maxIncomingBidiStreams uint64,
maxIncomingUniStreams uint64,
perspective protocol.Perspective,
version protocol.VersionNumber,
@ -65,8 +65,8 @@ func newStreamsMap(
)
m.incomingBidiStreams = newIncomingBidiStreamsMap(
protocol.FirstStream(protocol.StreamTypeBidi, perspective.Opposite()),
protocol.MaxStreamID(protocol.StreamTypeBidi, maxIncomingStreams, perspective.Opposite()),
maxIncomingStreams,
protocol.MaxStreamID(protocol.StreamTypeBidi, protocol.StreamNum(maxIncomingBidiStreams), perspective.Opposite()),
maxIncomingBidiStreams,
sender.queueControlFrame,
newBidiStream,
)
@ -77,7 +77,7 @@ func newStreamsMap(
)
m.incomingUniStreams = newIncomingUniStreamsMap(
protocol.FirstStream(protocol.StreamTypeUni, perspective.Opposite()),
protocol.MaxStreamID(protocol.StreamTypeUni, maxIncomingUniStreams, perspective.Opposite()),
protocol.MaxStreamID(protocol.StreamTypeUni, protocol.StreamNum(maxIncomingUniStreams), perspective.Opposite()),
maxIncomingUniStreams,
sender.queueControlFrame,
newUniReceiveStream,
@ -160,10 +160,10 @@ func (m *streamsMap) GetOrOpenSendStream(id protocol.StreamID) (sendStreamI, err
}
func (m *streamsMap) HandleMaxStreamsFrame(f *wire.MaxStreamsFrame) error {
if f.MaxStreams > protocol.MaxStreamCount {
if f.MaxStreamNum > protocol.MaxStreamCount {
return qerr.StreamLimitError
}
id := protocol.MaxStreamID(f.Type, f.MaxStreams, m.perspective)
id := protocol.MaxStreamID(f.Type, f.MaxStreamNum, m.perspective)
switch id.Type() {
case protocol.StreamTypeUni:
m.outgoingUniStreams.SetMaxStream(id)
@ -174,12 +174,13 @@ func (m *streamsMap) HandleMaxStreamsFrame(f *wire.MaxStreamsFrame) error {
}
func (m *streamsMap) UpdateLimits(p *handshake.TransportParameters) error {
if p.MaxBidiStreams > protocol.MaxStreamCount || p.MaxUniStreams > protocol.MaxStreamCount {
if p.MaxBidiStreamNum > protocol.MaxStreamCount ||
p.MaxUniStreamNum > protocol.MaxStreamCount {
return qerr.StreamLimitError
}
// Max{Uni,Bidi}StreamID returns the highest stream ID that the peer is allowed to open.
m.outgoingBidiStreams.SetMaxStream(protocol.MaxStreamID(protocol.StreamTypeBidi, p.MaxBidiStreams, m.perspective))
m.outgoingUniStreams.SetMaxStream(protocol.MaxStreamID(protocol.StreamTypeUni, p.MaxUniStreams, m.perspective))
m.outgoingBidiStreams.SetMaxStream(protocol.MaxStreamID(protocol.StreamTypeBidi, p.MaxBidiStreamNum, m.perspective))
m.outgoingUniStreams.SetMaxStream(protocol.MaxStreamID(protocol.StreamTypeUni, p.MaxUniStreamNum, m.perspective))
return nil
}

View file

@ -144,8 +144,8 @@ func (m *incomingBidiStreamsMap) deleteStream(id protocol.StreamID) error {
numNewStreams := m.maxNumStreams - uint64(len(m.streams))
m.maxStream = m.nextStreamToOpen + protocol.StreamID((numNewStreams-1)*4)
m.queueMaxStreamID(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: m.maxStream.StreamNum(),
Type: protocol.StreamTypeBidi,
MaxStreamNum: m.maxStream.StreamNum(),
})
}
return nil

View file

@ -142,8 +142,8 @@ func (m *incomingItemsMap) deleteStream(id protocol.StreamID) error {
numNewStreams := m.maxNumStreams - uint64(len(m.streams))
m.maxStream = m.nextStreamToOpen + protocol.StreamID((numNewStreams-1)*4)
m.queueMaxStreamID(&wire.MaxStreamsFrame{
Type: streamTypeGeneric,
MaxStreams: m.maxStream.StreamNum(),
Type: streamTypeGeneric,
MaxStreamNum: m.maxStream.StreamNum(),
})
}
return nil

View file

@ -212,11 +212,11 @@ var _ = Describe("Streams Map (incoming)", func() {
Expect(err).ToNot(HaveOccurred())
}
mockSender.EXPECT().queueControlFrame(gomock.Any()).Do(func(f wire.Frame) {
Expect(f.(*wire.MaxStreamsFrame).MaxStreams).To(Equal(maxNumStreams + 1))
Expect(f.(*wire.MaxStreamsFrame).MaxStreamNum).To(Equal(protocol.StreamNum(maxNumStreams + 1)))
})
Expect(m.DeleteStream(firstNewStream + 2*4)).To(Succeed())
mockSender.EXPECT().queueControlFrame(gomock.Any()).Do(func(f wire.Frame) {
Expect(f.(*wire.MaxStreamsFrame).MaxStreams).To(Equal(maxNumStreams + 2))
Expect(f.(*wire.MaxStreamsFrame).MaxStreamNum).To(Equal(protocol.StreamNum(maxNumStreams + 2)))
})
Expect(m.DeleteStream(firstNewStream + 3*4)).To(Succeed())
})

View file

@ -144,8 +144,8 @@ func (m *incomingUniStreamsMap) deleteStream(id protocol.StreamID) error {
numNewStreams := m.maxNumStreams - uint64(len(m.streams))
m.maxStream = m.nextStreamToOpen + protocol.StreamID((numNewStreams-1)*4)
m.queueMaxStreamID(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeUni,
MaxStreams: m.maxStream.StreamNum(),
Type: protocol.StreamTypeUni,
MaxStreamNum: m.maxStream.StreamNum(),
})
}
return nil

View file

@ -82,7 +82,7 @@ func (m *outgoingBidiStreamsMap) OpenStreamSync() (streamI, error) {
func (m *outgoingBidiStreamsMap) openStreamImpl() (streamI, error) {
if m.nextStream > m.maxStream {
if !m.blockedSent {
var streamNum uint64
var streamNum protocol.StreamNum
if m.maxStream != protocol.InvalidStreamID {
streamNum = m.maxStream.StreamNum()
}

View file

@ -80,7 +80,7 @@ func (m *outgoingItemsMap) OpenStreamSync() (item, error) {
func (m *outgoingItemsMap) openStreamImpl() (item, error) {
if m.nextStream > m.maxStream {
if !m.blockedSent {
var streamNum uint64
var streamNum protocol.StreamNum
if m.maxStream != protocol.InvalidStreamID {
streamNum = m.maxStream.StreamNum()
}

View file

@ -82,7 +82,7 @@ func (m *outgoingUniStreamsMap) OpenStreamSync() (sendStreamI, error) {
func (m *outgoingUniStreamsMap) openStreamImpl() (sendStreamI, error) {
if m.nextStream > m.maxStream {
if !m.blockedSent {
var streamNum uint64
var streamNum protocol.StreamNum
if m.maxStream != protocol.InvalidStreamID {
streamNum = m.maxStream.StreamNum()
}

View file

@ -3,7 +3,6 @@ package quic
import (
"errors"
"fmt"
"math"
"net"
"github.com/golang/mock/gomock"
@ -68,20 +67,20 @@ var _ = Describe("Streams Map", func() {
)
const (
maxBidiStreams = 111
maxUniStreams = 222
MaxBidiStreamNum = 111
MaxUniStreamNum = 222
)
allowUnlimitedStreams := func() {
m.UpdateLimits(&handshake.TransportParameters{
MaxBidiStreams: math.MaxUint16,
MaxUniStreams: math.MaxUint16,
MaxBidiStreamNum: protocol.MaxStreamCount,
MaxUniStreamNum: protocol.MaxStreamCount,
})
}
BeforeEach(func() {
mockSender = NewMockStreamSender(mockCtrl)
m = newStreamsMap(mockSender, newFlowController, maxBidiStreams, maxUniStreams, perspective, protocol.VersionWhatever).(*streamsMap)
m = newStreamsMap(mockSender, newFlowController, MaxBidiStreamNum, MaxUniStreamNum, perspective, protocol.VersionWhatever).(*streamsMap)
})
Context("opening", func() {
@ -301,8 +300,8 @@ var _ = Describe("Streams Map", func() {
_, err := m.OpenStream()
expectTooManyStreamsError(err)
Expect(m.UpdateLimits(&handshake.TransportParameters{
MaxBidiStreams: 5,
MaxUniStreams: 5,
MaxBidiStreamNum: 5,
MaxUniStreamNum: 5,
})).To(Succeed())
Expect(m.outgoingBidiStreams.maxStream).To(Equal(protocol.StreamID(17)))
Expect(m.outgoingUniStreams.maxStream).To(Equal(protocol.StreamID(19)))
@ -314,8 +313,8 @@ var _ = Describe("Streams Map", func() {
_, err := m.OpenUniStream()
expectTooManyStreamsError(err)
Expect(m.UpdateLimits(&handshake.TransportParameters{
MaxBidiStreams: 5,
MaxUniStreams: 5,
MaxBidiStreamNum: 5,
MaxUniStreamNum: 5,
})).To(Succeed())
Expect(m.outgoingBidiStreams.maxStream).To(Equal(protocol.StreamID(16)))
Expect(m.outgoingUniStreams.maxStream).To(Equal(protocol.StreamID(18)))
@ -323,13 +322,13 @@ var _ = Describe("Streams Map", func() {
It("rejects parameters with too large unidirectional stream counts", func() {
Expect(m.UpdateLimits(&handshake.TransportParameters{
MaxUniStreams: protocol.MaxStreamCount + 1,
MaxUniStreamNum: protocol.MaxStreamCount + 1,
})).To(MatchError(qerr.StreamLimitError))
})
It("rejects parameters with too large unidirectional stream counts", func() {
Expect(m.UpdateLimits(&handshake.TransportParameters{
MaxBidiStreams: protocol.MaxStreamCount + 1,
MaxBidiStreamNum: protocol.MaxStreamCount + 1,
})).To(MatchError(qerr.StreamLimitError))
})
})
@ -343,8 +342,8 @@ var _ = Describe("Streams Map", func() {
_, err := m.OpenStream()
expectTooManyStreamsError(err)
Expect(m.HandleMaxStreamsFrame(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: 1,
Type: protocol.StreamTypeBidi,
MaxStreamNum: 1,
})).To(Succeed())
str, err := m.OpenStream()
Expect(err).ToNot(HaveOccurred())
@ -357,8 +356,8 @@ var _ = Describe("Streams Map", func() {
_, err := m.OpenUniStream()
expectTooManyStreamsError(err)
Expect(m.HandleMaxStreamsFrame(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeUni,
MaxStreams: 1,
Type: protocol.StreamTypeUni,
MaxStreamNum: 1,
})).To(Succeed())
str, err := m.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
@ -369,8 +368,8 @@ var _ = Describe("Streams Map", func() {
It("rejects MAX_STREAMS frames with too large values", func() {
Expect(m.HandleMaxStreamsFrame(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: protocol.MaxStreamCount + 1,
Type: protocol.StreamTypeBidi,
MaxStreamNum: protocol.MaxStreamCount + 1,
})).To(MatchError(qerr.StreamLimitError))
})
})
@ -382,8 +381,8 @@ var _ = Describe("Streams Map", func() {
_, err = m.AcceptStream()
Expect(err).ToNot(HaveOccurred())
mockSender.EXPECT().queueControlFrame(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeBidi,
MaxStreams: maxBidiStreams + 1,
Type: protocol.StreamTypeBidi,
MaxStreamNum: MaxBidiStreamNum + 1,
})
Expect(m.DeleteStream(ids.firstIncomingBidiStream)).To(Succeed())
})
@ -394,8 +393,8 @@ var _ = Describe("Streams Map", func() {
_, err = m.AcceptUniStream()
Expect(err).ToNot(HaveOccurred())
mockSender.EXPECT().queueControlFrame(&wire.MaxStreamsFrame{
Type: protocol.StreamTypeUni,
MaxStreams: maxUniStreams + 1,
Type: protocol.StreamTypeUni,
MaxStreamNum: MaxUniStreamNum + 1,
})
Expect(m.DeleteStream(ids.firstIncomingUniStream)).To(Succeed())
})