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() {
|
||||
|
||||
@@ -183,7 +183,7 @@ func (p *packetPacker) composeNextPacket(stopWaitingFrame *frames.StopWaitingFra
|
||||
|
||||
if stopWaitingFrame != nil {
|
||||
payloadFrames = append(payloadFrames, stopWaitingFrame)
|
||||
minLength, err := stopWaitingFrame.MinLength()
|
||||
minLength, err := stopWaitingFrame.MinLength(p.version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (p *packetPacker) composeNextPacket(stopWaitingFrame *frames.StopWaitingFra
|
||||
|
||||
for len(p.controlFrames) > 0 {
|
||||
frame := p.controlFrames[0]
|
||||
minLength, _ := frame.MinLength() // controlFrames does not contain any StopWaitingFrames. So it will *never* return an error
|
||||
minLength, _ := frame.MinLength(p.version) // controlFrames does not contain any StopWaitingFrames. So it will *never* return an error
|
||||
if payloadLength+minLength > maxFrameSize {
|
||||
break
|
||||
}
|
||||
@@ -226,12 +226,12 @@ func (p *packetPacker) composeNextPacket(stopWaitingFrame *frames.StopWaitingFra
|
||||
}
|
||||
frame.DataLenPresent = true // set the dataLen by default. Remove them later if applicable
|
||||
|
||||
frameMinLength, _ := frame.MinLength() // StreamFrame.MinLength *never* returns an error
|
||||
frameMinLength, _ := frame.MinLength(p.version) // StreamFrame.MinLength *never* returns an error
|
||||
payloadLength += frameMinLength - 1 + frame.DataLen()
|
||||
|
||||
blockedFrame := p.blockedManager.GetBlockedFrame(frame.StreamID, frame.Offset+frame.DataLen())
|
||||
if blockedFrame != nil {
|
||||
blockedLength, _ := blockedFrame.MinLength() // BlockedFrame.MinLength *never* returns an error
|
||||
blockedLength, _ := blockedFrame.MinLength(p.version) // BlockedFrame.MinLength *never* returns an error
|
||||
if payloadLength+blockedLength <= maxFrameSize {
|
||||
payloadFrames = append(payloadFrames, blockedFrame)
|
||||
payloadLength += blockedLength
|
||||
|
||||
@@ -190,7 +190,7 @@ var _ = Describe("Packet packer", func() {
|
||||
blockedFrame := &frames.BlockedFrame{
|
||||
StreamID: 0x1337,
|
||||
}
|
||||
minLength, _ := blockedFrame.MinLength()
|
||||
minLength, _ := blockedFrame.MinLength(0)
|
||||
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / int(minLength)
|
||||
var controlFrames []frames.Frame
|
||||
for i := 0; i < maxFramesPerPacket+10; i++ {
|
||||
@@ -233,7 +233,7 @@ var _ = Describe("Packet packer", func() {
|
||||
StreamID: 13,
|
||||
DataLenPresent: false,
|
||||
}
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - minLength
|
||||
f.Data = bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen))
|
||||
packer.AddStreamFrame(f)
|
||||
@@ -307,7 +307,7 @@ var _ = Describe("Packet packer", func() {
|
||||
StreamID: 7,
|
||||
Offset: 1,
|
||||
}
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - minLength + 1 // + 1 since MinceLength is 1 bigger than the actual StreamFrame header
|
||||
f.Data = bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+200)
|
||||
packer.AddStreamFrame(f)
|
||||
@@ -366,7 +366,7 @@ var _ = Describe("Packet packer", func() {
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
}
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
f.Data = bytes.Repeat([]byte{'f'}, int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen-minLength+1)) // + 1 since MinceLength is 1 bigger than the actual StreamFrame header
|
||||
packer.AddStreamFrame(f)
|
||||
p, err := packer.PackPacket(nil, []frames.Frame{})
|
||||
@@ -380,7 +380,7 @@ var _ = Describe("Packet packer", func() {
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
}
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
f.Data = bytes.Repeat([]byte{'f'}, int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen-minLength+2)) // + 2 since MinceLength is 1 bigger than the actual StreamFrame header
|
||||
|
||||
packer.AddStreamFrame(f)
|
||||
@@ -441,12 +441,12 @@ var _ = Describe("Packet packer", func() {
|
||||
|
||||
It("packs a packet with the maximum size with a BlocedFrame", func() {
|
||||
blockedFrame := &frames.BlockedFrame{StreamID: 0x1337}
|
||||
blockedFrameLen, _ := blockedFrame.MinLength()
|
||||
blockedFrameLen, _ := blockedFrame.MinLength(0)
|
||||
f1 := frames.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
}
|
||||
streamFrameHeaderLen, _ := f1.MinLength()
|
||||
streamFrameHeaderLen, _ := f1.MinLength(0)
|
||||
streamFrameHeaderLen-- // - 1 since MinceLength is 1 bigger than the actual StreamFrame header
|
||||
// this is the maximum dataLen of a StreamFrames that fits into one packet
|
||||
dataLen := int(protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - streamFrameHeaderLen - blockedFrameLen)
|
||||
|
||||
@@ -38,6 +38,7 @@ type closeCallback func(id protocol.ConnectionID)
|
||||
// A Session is a QUIC session
|
||||
type Session struct {
|
||||
connectionID protocol.ConnectionID
|
||||
version protocol.VersionNumber
|
||||
|
||||
streamCallback StreamCallback
|
||||
closeCallback closeCallback
|
||||
@@ -94,6 +95,7 @@ func newSession(conn connection, v protocol.VersionNumber, connectionID protocol
|
||||
|
||||
session := &Session{
|
||||
connectionID: connectionID,
|
||||
version: v,
|
||||
conn: conn,
|
||||
streamCallback: streamCallback,
|
||||
closeCallback: closeCallback,
|
||||
@@ -459,7 +461,7 @@ func (s *Session) maybeSendPacket() error {
|
||||
}
|
||||
|
||||
if ack != nil {
|
||||
ackLength, _ := ack.MinLength() // MinLength never errors for an ACK frame
|
||||
ackLength, _ := ack.MinLength(s.version) // MinLength never errors for an ACK frame
|
||||
maxPacketSize += ackLength
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func (q *streamFrameQueue) Pop(maxLength protocol.ByteCount) (*frames.StreamFram
|
||||
}
|
||||
|
||||
// Does the frame fit into the remaining space?
|
||||
frameMinLength, _ := frame.MinLength() // StreamFrame.MinLength *never* returns an error
|
||||
frameMinLength, _ := frame.MinLength(0) // StreamFrame.MinLength *never* returns an error, StreamFrame minLength is independet of protocol version
|
||||
if frameMinLength > maxLength {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func (q *streamFrameQueue) getNextStream() (protocol.StreamID, error) {
|
||||
// maybeSplitOffFrame removes the first n bytes and returns them as a separate frame. If n >= len(n), nil is returned and nothing is modified.
|
||||
// has to be called from a function that has already acquired the mutex
|
||||
func (q *streamFrameQueue) maybeSplitOffFrame(frame *frames.StreamFrame, n protocol.ByteCount) *frames.StreamFrame {
|
||||
minLength, _ := frame.MinLength() // StreamFrame.MinLength *never* errors
|
||||
minLength, _ := frame.MinLength(0) // StreamFrame.MinLength *never* errors, StreamFrame minLength is independent of protocol version
|
||||
if n >= minLength-1+frame.DataLen() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ var _ = Describe("streamFrameQueue", func() {
|
||||
Offset: 3,
|
||||
FinBit: true,
|
||||
}
|
||||
minLength, _ := f.MinLength()
|
||||
minLength, _ := f.MinLength(0)
|
||||
previous := queue.maybeSplitOffFrame(f, minLength-1+3)
|
||||
Expect(previous).ToNot(BeNil())
|
||||
Expect(previous.StreamID).To(Equal(protocol.StreamID(1)))
|
||||
@@ -326,7 +326,7 @@ var _ = Describe("streamFrameQueue", func() {
|
||||
origlen := frame1.DataLen()
|
||||
frame, err := queue.Pop(6)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
minLength, _ := frame.MinLength()
|
||||
minLength, _ := frame.MinLength(0)
|
||||
Expect(minLength - 1 + frame.DataLen()).To(Equal(protocol.ByteCount(6)))
|
||||
Expect(queue.frameMap[frame1.StreamID][0].Data).To(HaveLen(int(origlen - frame.DataLen())))
|
||||
Expect(queue.frameMap[frame1.StreamID][0].Offset).To(Equal(frame.DataLen()))
|
||||
|
||||
Reference in New Issue
Block a user