only use duplicate stream data error internally in the streamFrameSorter

This commit is contained in:
Marten Seemann 2018-08-26 09:49:11 +07:00
parent 8dc4b2d564
commit 53d76b6664
3 changed files with 18 additions and 13 deletions

View file

@ -209,7 +209,7 @@ func (s *receiveStream) handleStreamFrame(frame *wire.StreamFrame) error {
s.mutex.Lock()
defer s.mutex.Unlock()
if err := s.frameQueue.Push(frame.Data, frame.Offset, frame.FinBit); err != nil && err != errDuplicateStreamData {
if err := s.frameQueue.Push(frame.Data, frame.Offset, frame.FinBit); err != nil {
return err
}
s.signalRead()

View file

@ -14,10 +14,7 @@ type streamFrameSorter struct {
gaps *utils.ByteIntervalList
}
var (
errTooManyGapsInReceivedStreamData = errors.New("Too many gaps in received StreamFrame data")
errDuplicateStreamData = errors.New("Duplicate Stream Data")
)
var errDuplicateStreamData = errors.New("Duplicate Stream Data")
func newStreamFrameSorter() *streamFrameSorter {
s := streamFrameSorter{
@ -30,6 +27,14 @@ func newStreamFrameSorter() *streamFrameSorter {
}
func (s *streamFrameSorter) Push(data []byte, offset protocol.ByteCount, fin bool) error {
err := s.push(data, offset, fin)
if err == errDuplicateStreamData {
return nil
}
return err
}
func (s *streamFrameSorter) push(data []byte, offset protocol.ByteCount, fin bool) error {
if fin {
s.finalOffset = offset + protocol.ByteCount(len(data))
}
@ -129,7 +134,7 @@ func (s *streamFrameSorter) Push(data []byte, offset protocol.ByteCount, fin boo
}
if s.gaps.Len() > protocol.MaxStreamFrameSorterGaps {
return errTooManyGapsInReceivedStreamData
return errors.New("Too many gaps in received data")
}
if wasCut {

View file

@ -375,21 +375,21 @@ var _ = Describe("STREAM frame sorter", func() {
})
It("does not modify data when receiving a duplicate", func() {
err := s.Push([]byte("fffff"), 0, false)
err := s.push([]byte("fffff"), 0, false)
Expect(err).To(MatchError(errDuplicateStreamData))
Expect(s.queue[0]).ToNot(Equal([]byte("fffff")))
})
It("detects a duplicate frame that is smaller than the original, starting at the beginning", func() {
// 10 to 12
err := s.Push([]byte("12"), 10, false)
err := s.push([]byte("12"), 10, false)
Expect(err).To(MatchError(errDuplicateStreamData))
Expect(s.queue[10]).To(HaveLen(5))
})
It("detects a duplicate frame that is smaller than the original, somewhere in the middle", func() {
// 1 to 4
err := s.Push([]byte("123"), 1, false)
err := s.push([]byte("123"), 1, false)
Expect(err).To(MatchError(errDuplicateStreamData))
Expect(s.queue[0]).To(HaveLen(5))
Expect(s.queue).ToNot(HaveKey(protocol.ByteCount(1)))
@ -397,7 +397,7 @@ var _ = Describe("STREAM frame sorter", func() {
It("detects a duplicate frame that is smaller than the original, somewhere in the middle in the last block", func() {
// 11 to 14
err := s.Push([]byte("123"), 11, false)
err := s.push([]byte("123"), 11, false)
Expect(err).To(MatchError(errDuplicateStreamData))
Expect(s.queue[10]).To(HaveLen(5))
Expect(s.queue).ToNot(HaveKey(protocol.ByteCount(11)))
@ -405,7 +405,7 @@ var _ = Describe("STREAM frame sorter", func() {
It("detects a duplicate frame that is smaller than the original, with aligned end in the last block", func() {
// 11 to 15
err := s.Push([]byte("1234"), 1, false)
err := s.push([]byte("1234"), 1, false)
Expect(err).To(MatchError(errDuplicateStreamData))
Expect(s.queue[10]).To(HaveLen(5))
Expect(s.queue).ToNot(HaveKey(protocol.ByteCount(11)))
@ -413,7 +413,7 @@ var _ = Describe("STREAM frame sorter", func() {
It("detects a duplicate frame that is smaller than the original, with aligned end", func() {
// 3 to 5
err := s.Push([]byte("12"), 3, false)
err := s.push([]byte("12"), 3, false)
Expect(err).To(MatchError(errDuplicateStreamData))
Expect(s.queue[0]).To(HaveLen(5))
Expect(s.queue).ToNot(HaveKey(protocol.ByteCount(3)))
@ -427,7 +427,7 @@ var _ = Describe("STREAM frame sorter", func() {
}
Expect(s.gaps.Len()).To(Equal(protocol.MaxStreamFrameSorterGaps))
err := s.Push([]byte("foobar"), protocol.ByteCount(protocol.MaxStreamFrameSorterGaps*7)+100, false)
Expect(err).To(MatchError(errTooManyGapsInReceivedStreamData))
Expect(err).To(MatchError("Too many gaps in received data"))
})
})
})