forked from quic-go/quic-go
@@ -115,7 +115,7 @@ func (f *AckFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *AckFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *AckFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
l := 1 + 1 + 2 + 1 + 1 + 4 // 1 TypeByte, 1 Entropy, 2 ACK delay time, 1 Num Timestamp, 1 Delta Largest Observed, 4 FirstTimestamp
|
||||
l += int(protocol.GetPacketNumberLength(f.LargestObserved))
|
||||
l += (1 + 2) * 0 /* TODO: num_timestamps */
|
||||
|
||||
@@ -500,7 +500,7 @@ var _ = Describe("AckFrame", func() {
|
||||
LargestObserved: 1,
|
||||
}
|
||||
f.Write(b, 2)
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(b.Len())))
|
||||
})
|
||||
|
||||
It("has proper min length with a large LargestObserved", func() {
|
||||
@@ -509,7 +509,7 @@ var _ = Describe("AckFrame", func() {
|
||||
LargestObserved: 0xDEADBEEFCAFE,
|
||||
}
|
||||
f.Write(b, 2)
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(b.Len())))
|
||||
})
|
||||
|
||||
It("has proper min length with nack ranges", func() {
|
||||
@@ -520,7 +520,7 @@ var _ = Describe("AckFrame", func() {
|
||||
}
|
||||
err := f.Write(b, protocol.Version31)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(b.Len())))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ func (f *BlockedFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) er
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *BlockedFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *BlockedFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
return 1 + 4, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ var _ = Describe("BlockedFrame", func() {
|
||||
|
||||
It("has the correct min length", func() {
|
||||
frame := BlockedFrame{StreamID: 3}
|
||||
Expect(frame.MinLength()).To(Equal(protocol.ByteCount(5)))
|
||||
Expect(frame.MinLength(0)).To(Equal(protocol.ByteCount(5)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -52,7 +52,7 @@ func ParseConnectionCloseFrame(r *bytes.Reader) (*ConnectionCloseFrame, error) {
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *ConnectionCloseFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *ConnectionCloseFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
return 1 + 4 + 2 + protocol.ByteCount(len(f.ReasonPhrase)), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
||||
ReasonPhrase: "foobar",
|
||||
}
|
||||
f.Write(b, 0)
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(b.Len())))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ import (
|
||||
// A Frame in QUIC
|
||||
type Frame interface {
|
||||
Write(b *bytes.Buffer, version protocol.VersionNumber) error
|
||||
MinLength() (protocol.ByteCount, error)
|
||||
MinLength(version protocol.VersionNumber) (protocol.ByteCount, error)
|
||||
}
|
||||
|
||||
@@ -68,6 +68,6 @@ func (f *GoawayFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) err
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *GoawayFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *GoawayFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
return protocol.ByteCount(1 + 4 + 4 + 2 + len(f.ReasonPhrase)), nil
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ var _ = Describe("GoawayFrame", func() {
|
||||
frame := GoawayFrame{
|
||||
ReasonPhrase: "foo",
|
||||
}
|
||||
Expect(frame.MinLength()).To(Equal(protocol.ByteCount(14)))
|
||||
Expect(frame.MinLength(0)).To(Equal(protocol.ByteCount(14)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -28,6 +28,6 @@ func (f *PingFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *PingFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *PingFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ var _ = Describe("PingFrame", func() {
|
||||
|
||||
It("has the correct min length", func() {
|
||||
frame := PingFrame{}
|
||||
Expect(frame.MinLength()).To(Equal(protocol.ByteCount(1)))
|
||||
Expect(frame.MinLength(0)).To(Equal(protocol.ByteCount(1)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@ func (f *RstStreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber)
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *RstStreamFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *RstStreamFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
return 1 + 4 + 8 + 4, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ var _ = Describe("RstStreamFrame", func() {
|
||||
ByteOffset: 0x1000,
|
||||
ErrorCode: 0xDE,
|
||||
}
|
||||
Expect(rst.MinLength()).To(Equal(protocol.ByteCount(17)))
|
||||
Expect(rst.MinLength(0)).To(Equal(protocol.ByteCount(17)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ func (f *StopWaitingFrame) Write(b *bytes.Buffer, version protocol.VersionNumber
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *StopWaitingFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *StopWaitingFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
if f.PacketNumberLen == protocol.PacketNumberLenInvalid {
|
||||
return 0, errPacketNumberLenNotSet
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ var _ = Describe("StopWaitingFrame", func() {
|
||||
LeastUnacked: 10,
|
||||
PacketNumberLen: length,
|
||||
}
|
||||
Expect(frame.MinLength()).To(Equal(protocol.ByteCount(length + 2)))
|
||||
Expect(frame.MinLength(0)).To(Equal(protocol.ByteCount(length + 2)))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -140,7 +140,7 @@ var _ = Describe("StopWaitingFrame", func() {
|
||||
frame := &StopWaitingFrame{
|
||||
LeastUnacked: 10,
|
||||
}
|
||||
_, err := frame.MinLength()
|
||||
_, err := frame.MinLength(0)
|
||||
Expect(err).To(MatchError(errPacketNumberLenNotSet))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -191,7 +191,7 @@ func (f *StreamFrame) getOffsetLength() protocol.ByteCount {
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *StreamFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *StreamFrame) MinLength(protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
if f.streamIDLen == 0 {
|
||||
f.calculateStreamIDLength()
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
}
|
||||
err := f.Write(b, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(b.Len())))
|
||||
})
|
||||
|
||||
It("has proper min length for a long StreamID and a big offset", func() {
|
||||
@@ -99,7 +99,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
}
|
||||
err := f.Write(b, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(b.Len())))
|
||||
})
|
||||
|
||||
Context("data length field", func() {
|
||||
@@ -114,7 +114,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
}
|
||||
err := f.Write(b, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
headerLength := minLength - 1
|
||||
Expect(b.Bytes()[0] & 0x20).To(Equal(uint8(0x20)))
|
||||
Expect(b.Bytes()[headerLength-2 : headerLength]).To(Equal([]byte{0x37, 0x13}))
|
||||
@@ -133,9 +133,9 @@ var _ = Describe("StreamFrame", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(b.Bytes()[0] & 0x20).To(Equal(uint8(0)))
|
||||
Expect(b.Bytes()[1 : b.Len()-dataLen]).ToNot(ContainSubstring(string([]byte{0x37, 0x13})))
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
f.DataLenPresent = true
|
||||
minLengthWithoutDataLen, _ := f.MinLength()
|
||||
minLengthWithoutDataLen, _ := f.MinLength(0)
|
||||
Expect(minLength).To(Equal(minLengthWithoutDataLen - 2))
|
||||
})
|
||||
|
||||
@@ -146,9 +146,9 @@ var _ = Describe("StreamFrame", func() {
|
||||
DataLenPresent: false,
|
||||
Offset: 0xDEADBEEF,
|
||||
}
|
||||
minLengthWithoutDataLen, _ := f.MinLength()
|
||||
minLengthWithoutDataLen, _ := f.MinLength(0)
|
||||
f.DataLenPresent = true
|
||||
Expect(f.MinLength()).To(Equal(minLengthWithoutDataLen + 2))
|
||||
Expect(f.MinLength(0)).To(Equal(minLengthWithoutDataLen + 2))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -309,7 +309,7 @@ var _ = Describe("StreamFrame", func() {
|
||||
StreamID: 0xDECAFBAD,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
frame.MinLength()
|
||||
frame.MinLength(0)
|
||||
err := frame.Write(b, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x3)))
|
||||
|
||||
@@ -24,7 +24,7 @@ func (f *WindowUpdateFrame) Write(b *bytes.Buffer, version protocol.VersionNumbe
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *WindowUpdateFrame) MinLength() (protocol.ByteCount, error) {
|
||||
func (f *WindowUpdateFrame) MinLength(version protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
return 1 + 4 + 8, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ var _ = Describe("WindowUpdateFrame", func() {
|
||||
StreamID: 0x1337,
|
||||
ByteOffset: 0xDEADBEEF,
|
||||
}
|
||||
Expect(f.MinLength()).To(Equal(protocol.ByteCount(13)))
|
||||
Expect(f.MinLength(0)).To(Equal(protocol.ByteCount(13)))
|
||||
})
|
||||
|
||||
It("writes a sample frame", func() {
|
||||
|
||||
Reference in New Issue
Block a user