detect stream flow control violations

fixes #97
This commit is contained in:
Marten Seemann
2016-05-16 18:15:40 +07:00
parent 4de41d0737
commit 0d4dd8869d
3 changed files with 86 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
package quic
import (
"errors"
"io"
"sync"
"sync/atomic"
@@ -16,6 +17,8 @@ type streamHandler interface {
updateReceiveFlowControlWindow(streamID protocol.StreamID, byteOffset protocol.ByteCount) error
}
var errFlowControlViolation = errors.New("flow control violation")
// A Stream assembles the data from StreamFrames and provides a super-convenient Read-Interface
type stream struct {
streamID protocol.StreamID
@@ -208,7 +211,11 @@ func (s *stream) Close() error {
// AddStreamFrame adds a new stream frame
func (s *stream) AddStreamFrame(frame *frames.StreamFrame) error {
// TODO: return flow control window violation here
maxOffset := frame.Offset + protocol.ByteCount(len(frame.Data))
if maxOffset > s.receiveFlowControlWindow {
return errFlowControlViolation
}
s.mutex.Lock()
s.frameQueue.Push(frame)
s.mutex.Unlock()