implement the MAX_DATA and MAX_STREAM_DATA frames

For gQUIC WINDOW_UPDATEs are converted to MAX_DATA and MAX_STREAM_DATA,
respectively.
This commit is contained in:
Marten Seemann 2017-11-01 15:29:15 +07:00
parent ccb2e9a2df
commit 0f1f1c8d41
18 changed files with 512 additions and 168 deletions

View file

@ -0,0 +1,62 @@
package wire
import (
"bytes"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("MAX_STREAM_DATA frame", func() {
Context("parsing", func() {
It("accepts sample frame", func() {
b := bytes.NewReader([]byte{0x5,
0xde, 0xad, 0xbe, 0xef, // stream id
0xde, 0xca, 0xfb, 0xad, 0x11, 0x22, 0x33, 0x44, // byte offset
})
frame, err := ParseMaxStreamDataFrame(b, versionMaxDataFrame)
Expect(err).ToNot(HaveOccurred())
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef)))
Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0xdecafbad11223344)))
Expect(b.Len()).To(BeZero())
})
It("errors on EOFs", func() {
data := []byte{0x5,
0xef, 0xbe, 0xad, 0xde, // stream id
0x44, 0x33, 0x22, 0x11, 0xad, 0xfb, 0xca, 0xde, // byte offset
}
_, err := ParseMaxStreamDataFrame(bytes.NewReader(data), versionMaxDataFrame)
Expect(err).NotTo(HaveOccurred())
for i := range data {
_, err := ParseMaxStreamDataFrame(bytes.NewReader(data[0:i]), versionMaxDataFrame)
Expect(err).To(HaveOccurred())
}
})
})
Context("writing", func() {
It("has proper min length", func() {
f := &MaxStreamDataFrame{
StreamID: 0x1337,
ByteOffset: 0xdeadbeef,
}
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(13)))
})
It("writes a sample frame", func() {
b := &bytes.Buffer{}
f := &MaxStreamDataFrame{
StreamID: 0xdecafbad,
ByteOffset: 0xdeadbeefcafe1337,
}
err := f.Write(b, versionMaxDataFrame)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x5,
0xde, 0xca, 0xfb, 0xad, // stream id
0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37, // byte offset
}))
})
})
})