forked from quic-go/quic-go
implement some stream ID helper functions
This commit is contained in:
@@ -3,6 +3,19 @@ package protocol
|
|||||||
// A StreamID in QUIC
|
// A StreamID in QUIC
|
||||||
type StreamID uint64
|
type StreamID uint64
|
||||||
|
|
||||||
|
// InitiatedBy says if the stream was initiated by the client or by the server
|
||||||
|
func (s StreamID) InitiatedBy() Perspective {
|
||||||
|
if s%2 == 0 {
|
||||||
|
return PerspectiveClient
|
||||||
|
}
|
||||||
|
return PerspectiveServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsUniDirectional says if this is a unidirectional stream (true) or not (false)
|
||||||
|
func (s StreamID) IsUniDirectional() bool {
|
||||||
|
return s%4 >= 2
|
||||||
|
}
|
||||||
|
|
||||||
// MaxBidiStreamID is the highest stream ID that the peer is allowed to open,
|
// MaxBidiStreamID is the highest stream ID that the peer is allowed to open,
|
||||||
// when it is allowed to open numStreams bidirectional streams.
|
// when it is allowed to open numStreams bidirectional streams.
|
||||||
func MaxBidiStreamID(numStreams int, pers Perspective) StreamID {
|
func MaxBidiStreamID(numStreams int, pers Perspective) StreamID {
|
||||||
|
|||||||
@@ -6,6 +6,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Stream ID", func() {
|
var _ = Describe("Stream ID", func() {
|
||||||
|
It("says who initiated a stream", func() {
|
||||||
|
Expect(StreamID(4).InitiatedBy()).To(Equal(PerspectiveClient))
|
||||||
|
Expect(StreamID(5).InitiatedBy()).To(Equal(PerspectiveServer))
|
||||||
|
Expect(StreamID(6).InitiatedBy()).To(Equal(PerspectiveClient))
|
||||||
|
Expect(StreamID(7).InitiatedBy()).To(Equal(PerspectiveServer))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("tells the directionality", func() {
|
||||||
|
Expect(StreamID(4).IsUniDirectional()).To(BeFalse())
|
||||||
|
Expect(StreamID(5).IsUniDirectional()).To(BeFalse())
|
||||||
|
Expect(StreamID(6).IsUniDirectional()).To(BeTrue())
|
||||||
|
Expect(StreamID(7).IsUniDirectional()).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("maximum stream IDs", func() {
|
||||||
Context("bidirectional streams", func() {
|
Context("bidirectional streams", func() {
|
||||||
It("doesn't allow any", func() {
|
It("doesn't allow any", func() {
|
||||||
Expect(MaxBidiStreamID(0, PerspectiveClient)).To(Equal(StreamID(0)))
|
Expect(MaxBidiStreamID(0, PerspectiveClient)).To(Equal(StreamID(0)))
|
||||||
@@ -40,3 +55,4 @@ var _ = Describe("Stream ID", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user