implement some stream ID helper functions

This commit is contained in:
Marten Seemann
2018-10-30 11:27:42 +07:00
parent a1acfc3045
commit 14a4464266
2 changed files with 55 additions and 26 deletions

View File

@@ -3,6 +3,19 @@ package protocol
// A StreamID in QUIC
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,
// when it is allowed to open numStreams bidirectional streams.
func MaxBidiStreamID(numStreams int, pers Perspective) StreamID {