forked from quic-go/quic-go
check that all new Streams initiated by the client have an odd StreamID
work towards #78
This commit is contained in:
13
session.go
13
session.go
@@ -23,6 +23,7 @@ type receivedPacket struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
errInvalidStreamID = errors.New("STREAM_FRAME with invalid StreamID received")
|
||||||
errRstStreamOnInvalidStream = errors.New("RST_STREAM received for unknown stream")
|
errRstStreamOnInvalidStream = errors.New("RST_STREAM received for unknown stream")
|
||||||
errWindowUpdateOnInvalidStream = errors.New("WINDOW_UPDATE received for unknown stream")
|
errWindowUpdateOnInvalidStream = errors.New("WINDOW_UPDATE received for unknown stream")
|
||||||
)
|
)
|
||||||
@@ -225,9 +226,10 @@ func (s *Session) HandlePacket(remoteAddr interface{}, publicHeader *PublicHeade
|
|||||||
|
|
||||||
// TODO: Ignore data for closed streams
|
// TODO: Ignore data for closed streams
|
||||||
func (s *Session) handleStreamFrame(frame *frames.StreamFrame) error {
|
func (s *Session) handleStreamFrame(frame *frames.StreamFrame) error {
|
||||||
if frame.StreamID == 0 {
|
if !s.isValidStreamID(frame.StreamID) {
|
||||||
return errors.New("Session: 0 is not a valid Stream ID")
|
return errInvalidStreamID
|
||||||
}
|
}
|
||||||
|
|
||||||
s.streamsMutex.RLock()
|
s.streamsMutex.RLock()
|
||||||
str, streamExists := s.streams[frame.StreamID]
|
str, streamExists := s.streams[frame.StreamID]
|
||||||
s.streamsMutex.RUnlock()
|
s.streamsMutex.RUnlock()
|
||||||
@@ -249,6 +251,13 @@ func (s *Session) handleStreamFrame(frame *frames.StreamFrame) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) isValidStreamID(streamID protocol.StreamID) bool {
|
||||||
|
if streamID%2 != 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) handleWindowUpdateFrame(frame *frames.WindowUpdateFrame) error {
|
func (s *Session) handleWindowUpdateFrame(frame *frames.WindowUpdateFrame) error {
|
||||||
if frame.StreamID == 0 {
|
if frame.StreamID == 0 {
|
||||||
// TODO: handle connection level WindowUpdateFrames
|
// TODO: handle connection level WindowUpdateFrames
|
||||||
|
|||||||
@@ -113,6 +113,15 @@ var _ = Describe("Session", func() {
|
|||||||
Expect(p).To(Equal([]byte{0xde, 0xca, 0xfb, 0xad}))
|
Expect(p).To(Equal([]byte{0xde, 0xca, 0xfb, 0xad}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("rejects streams with even StreamIDs", func() {
|
||||||
|
err := session.handleStreamFrame(&frames.StreamFrame{
|
||||||
|
StreamID: 4,
|
||||||
|
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||||
|
})
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(err).To(Equal(errInvalidStreamID))
|
||||||
|
})
|
||||||
|
|
||||||
It("handles existing streams", func() {
|
It("handles existing streams", func() {
|
||||||
session.handleStreamFrame(&frames.StreamFrame{
|
session.handleStreamFrame(&frames.StreamFrame{
|
||||||
StreamID: 5,
|
StreamID: 5,
|
||||||
|
|||||||
Reference in New Issue
Block a user