mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
rename package frames to wire
This commit is contained in:
parent
5281d5b65d
commit
88afad8722
49 changed files with 565 additions and 571 deletions
|
@ -3,18 +3,18 @@ package ackhandler
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
// SentPacketHandler handles ACKs received for outgoing packets
|
||||
type SentPacketHandler interface {
|
||||
// SentPacket may modify the packet
|
||||
SentPacket(packet *Packet) error
|
||||
ReceivedAck(ackFrame *frames.AckFrame, withPacketNumber protocol.PacketNumber, recvTime time.Time) error
|
||||
ReceivedAck(ackFrame *wire.AckFrame, withPacketNumber protocol.PacketNumber, recvTime time.Time) error
|
||||
|
||||
SendingAllowed() bool
|
||||
GetStopWaitingFrame(force bool) *frames.StopWaitingFrame
|
||||
GetStopWaitingFrame(force bool) *wire.StopWaitingFrame
|
||||
ShouldSendRetransmittablePacket() bool
|
||||
DequeuePacketForRetransmission() (packet *Packet)
|
||||
GetLeastUnacked() protocol.PacketNumber
|
||||
|
@ -29,5 +29,5 @@ type ReceivedPacketHandler interface {
|
|||
SetLowerLimit(protocol.PacketNumber)
|
||||
|
||||
GetAlarmTimeout() time.Time
|
||||
GetAckFrame() *frames.AckFrame
|
||||
GetAckFrame() *wire.AckFrame
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@ package ackhandler
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
// A Packet is a packet
|
||||
// +gen linkedlist
|
||||
type Packet struct {
|
||||
PacketNumber protocol.PacketNumber
|
||||
Frames []frames.Frame
|
||||
Frames []wire.Frame
|
||||
Length protocol.ByteCount
|
||||
EncryptionLevel protocol.EncryptionLevel
|
||||
|
||||
|
@ -19,13 +19,13 @@ type Packet struct {
|
|||
}
|
||||
|
||||
// GetFramesForRetransmission gets all the frames for retransmission
|
||||
func (p *Packet) GetFramesForRetransmission() []frames.Frame {
|
||||
var fs []frames.Frame
|
||||
func (p *Packet) GetFramesForRetransmission() []wire.Frame {
|
||||
var fs []wire.Frame
|
||||
for _, frame := range p.Frames {
|
||||
switch frame.(type) {
|
||||
case *frames.AckFrame:
|
||||
case *wire.AckFrame:
|
||||
continue
|
||||
case *frames.StopWaitingFrame:
|
||||
case *wire.StopWaitingFrame:
|
||||
continue
|
||||
}
|
||||
fs = append(fs, frame)
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Packet", func() {
|
||||
Context("getting frames for retransmission", func() {
|
||||
ackFrame := &frames.AckFrame{LargestAcked: 13}
|
||||
stopWaitingFrame := &frames.StopWaitingFrame{LeastUnacked: 7331}
|
||||
windowUpdateFrame := &frames.WindowUpdateFrame{StreamID: 999}
|
||||
ackFrame := &wire.AckFrame{LargestAcked: 13}
|
||||
stopWaitingFrame := &wire.StopWaitingFrame{LeastUnacked: 7331}
|
||||
windowUpdateFrame := &wire.WindowUpdateFrame{StreamID: 999}
|
||||
|
||||
streamFrame := &frames.StreamFrame{
|
||||
streamFrame := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0x13, 0x37},
|
||||
}
|
||||
|
||||
rstStreamFrame := &frames.RstStreamFrame{
|
||||
rstStreamFrame := &wire.RstStreamFrame{
|
||||
StreamID: 555,
|
||||
ErrorCode: 1337,
|
||||
}
|
||||
|
||||
It("returns nil if there are no retransmittable frames", func() {
|
||||
packet := &Packet{
|
||||
Frames: []frames.Frame{ackFrame, stopWaitingFrame},
|
||||
Frames: []wire.Frame{ackFrame, stopWaitingFrame},
|
||||
}
|
||||
Expect(packet.GetFramesForRetransmission()).To(BeNil())
|
||||
})
|
||||
|
||||
It("returns all retransmittable frames", func() {
|
||||
packet := &Packet{
|
||||
Frames: []frames.Frame{
|
||||
Frames: []wire.Frame{
|
||||
windowUpdateFrame,
|
||||
ackFrame,
|
||||
stopWaitingFrame,
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
var errInvalidPacketNumber = errors.New("ReceivedPacketHandler: Invalid packet number")
|
||||
|
@ -23,7 +23,7 @@ type receivedPacketHandler struct {
|
|||
retransmittablePacketsReceivedSinceLastAck int
|
||||
ackQueued bool
|
||||
ackAlarm time.Time
|
||||
lastAck *frames.AckFrame
|
||||
lastAck *wire.AckFrame
|
||||
|
||||
version protocol.VersionNumber
|
||||
}
|
||||
|
@ -113,13 +113,13 @@ func (h *receivedPacketHandler) maybeQueueAck(packetNumber protocol.PacketNumber
|
|||
}
|
||||
}
|
||||
|
||||
func (h *receivedPacketHandler) GetAckFrame() *frames.AckFrame {
|
||||
func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
|
||||
if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(time.Now())) {
|
||||
return nil
|
||||
}
|
||||
|
||||
ackRanges := h.packetHistory.GetAckRanges()
|
||||
ack := &frames.AckFrame{
|
||||
ack := &wire.AckFrame{
|
||||
LargestAcked: h.largestObserved,
|
||||
LowestAcked: ackRanges[len(ackRanges)-1].FirstPacketNumber,
|
||||
PacketReceivedTime: h.largestObservedReceivedTime,
|
||||
|
|
|
@ -3,8 +3,8 @@ package ackhandler
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -221,8 +221,8 @@ var _ = Describe("receivedPacketHandler", func() {
|
|||
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(4)))
|
||||
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(1)))
|
||||
Expect(ack.AckRanges).To(HaveLen(2))
|
||||
Expect(ack.AckRanges[0]).To(Equal(frames.AckRange{FirstPacketNumber: 4, LastPacketNumber: 4}))
|
||||
Expect(ack.AckRanges[1]).To(Equal(frames.AckRange{FirstPacketNumber: 1, LastPacketNumber: 1}))
|
||||
Expect(ack.AckRanges[0]).To(Equal(wire.AckRange{FirstPacketNumber: 4, LastPacketNumber: 4}))
|
||||
Expect(ack.AckRanges[1]).To(Equal(wire.AckRange{FirstPacketNumber: 1, LastPacketNumber: 1}))
|
||||
})
|
||||
|
||||
It("accepts packets below the lower limit", func() {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
// The receivedPacketHistory stores if a packet number has already been received.
|
||||
|
@ -122,22 +122,22 @@ func (h *receivedPacketHistory) IsDuplicate(p protocol.PacketNumber) bool {
|
|||
}
|
||||
|
||||
// GetAckRanges gets a slice of all AckRanges that can be used in an AckFrame
|
||||
func (h *receivedPacketHistory) GetAckRanges() []frames.AckRange {
|
||||
func (h *receivedPacketHistory) GetAckRanges() []wire.AckRange {
|
||||
if h.ranges.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var ackRanges []frames.AckRange
|
||||
var ackRanges []wire.AckRange
|
||||
|
||||
for el := h.ranges.Back(); el != nil; el = el.Prev() {
|
||||
ackRanges = append(ackRanges, frames.AckRange{FirstPacketNumber: el.Value.Start, LastPacketNumber: el.Value.End})
|
||||
ackRanges = append(ackRanges, wire.AckRange{FirstPacketNumber: el.Value.Start, LastPacketNumber: el.Value.End})
|
||||
}
|
||||
|
||||
return ackRanges
|
||||
}
|
||||
|
||||
func (h *receivedPacketHistory) GetHighestAckRange() frames.AckRange {
|
||||
ackRange := frames.AckRange{}
|
||||
func (h *receivedPacketHistory) GetHighestAckRange() wire.AckRange {
|
||||
ackRange := wire.AckRange{}
|
||||
if h.ranges.Len() > 0 {
|
||||
r := h.ranges.Back().Value
|
||||
ackRange.FirstPacketNumber = r.Start
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -298,7 +298,7 @@ var _ = Describe("receivedPacketHistory", func() {
|
|||
hist.ReceivedPacket(5)
|
||||
ackRanges := hist.GetAckRanges()
|
||||
Expect(ackRanges).To(HaveLen(1))
|
||||
Expect(ackRanges[0]).To(Equal(frames.AckRange{FirstPacketNumber: 4, LastPacketNumber: 5}))
|
||||
Expect(ackRanges[0]).To(Equal(wire.AckRange{FirstPacketNumber: 4, LastPacketNumber: 5}))
|
||||
})
|
||||
|
||||
It("gets multiple ACK ranges", func() {
|
||||
|
@ -311,9 +311,9 @@ var _ = Describe("receivedPacketHistory", func() {
|
|||
hist.ReceivedPacket(2)
|
||||
ackRanges := hist.GetAckRanges()
|
||||
Expect(ackRanges).To(HaveLen(3))
|
||||
Expect(ackRanges[0]).To(Equal(frames.AckRange{FirstPacketNumber: 10, LastPacketNumber: 11}))
|
||||
Expect(ackRanges[1]).To(Equal(frames.AckRange{FirstPacketNumber: 4, LastPacketNumber: 6}))
|
||||
Expect(ackRanges[2]).To(Equal(frames.AckRange{FirstPacketNumber: 1, LastPacketNumber: 2}))
|
||||
Expect(ackRanges[0]).To(Equal(wire.AckRange{FirstPacketNumber: 10, LastPacketNumber: 11}))
|
||||
Expect(ackRanges[1]).To(Equal(wire.AckRange{FirstPacketNumber: 4, LastPacketNumber: 6}))
|
||||
Expect(ackRanges[2]).To(Equal(wire.AckRange{FirstPacketNumber: 1, LastPacketNumber: 2}))
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -325,14 +325,14 @@ var _ = Describe("receivedPacketHistory", func() {
|
|||
It("gets a single ACK range", func() {
|
||||
hist.ReceivedPacket(4)
|
||||
hist.ReceivedPacket(5)
|
||||
Expect(hist.GetHighestAckRange()).To(Equal(frames.AckRange{FirstPacketNumber: 4, LastPacketNumber: 5}))
|
||||
Expect(hist.GetHighestAckRange()).To(Equal(wire.AckRange{FirstPacketNumber: 4, LastPacketNumber: 5}))
|
||||
})
|
||||
|
||||
It("gets the highest of multiple ACK ranges", func() {
|
||||
hist.ReceivedPacket(3)
|
||||
hist.ReceivedPacket(6)
|
||||
hist.ReceivedPacket(7)
|
||||
Expect(hist.GetHighestAckRange()).To(Equal(frames.AckRange{FirstPacketNumber: 6, LastPacketNumber: 7}))
|
||||
Expect(hist.GetHighestAckRange()).To(Equal(wire.AckRange{FirstPacketNumber: 6, LastPacketNumber: 7}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
)
|
||||
import "github.com/lucas-clemente/quic-go/wire"
|
||||
|
||||
// Returns a new slice with all non-retransmittable frames deleted.
|
||||
func stripNonRetransmittableFrames(fs []frames.Frame) []frames.Frame {
|
||||
res := make([]frames.Frame, 0, len(fs))
|
||||
func stripNonRetransmittableFrames(fs []wire.Frame) []wire.Frame {
|
||||
res := make([]wire.Frame, 0, len(fs))
|
||||
for _, f := range fs {
|
||||
if IsFrameRetransmittable(f) {
|
||||
res = append(res, f)
|
||||
|
@ -16,11 +14,11 @@ func stripNonRetransmittableFrames(fs []frames.Frame) []frames.Frame {
|
|||
}
|
||||
|
||||
// IsFrameRetransmittable returns true if the frame should be retransmitted.
|
||||
func IsFrameRetransmittable(f frames.Frame) bool {
|
||||
func IsFrameRetransmittable(f wire.Frame) bool {
|
||||
switch f.(type) {
|
||||
case *frames.StopWaitingFrame:
|
||||
case *wire.StopWaitingFrame:
|
||||
return false
|
||||
case *frames.AckFrame:
|
||||
case *wire.AckFrame:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
|
@ -28,7 +26,7 @@ func IsFrameRetransmittable(f frames.Frame) bool {
|
|||
}
|
||||
|
||||
// HasRetransmittableFrames returns true if at least one frame is retransmittable.
|
||||
func HasRetransmittableFrames(fs []frames.Frame) bool {
|
||||
func HasRetransmittableFrames(fs []wire.Frame) bool {
|
||||
for _, f := range fs {
|
||||
if IsFrameRetransmittable(f) {
|
||||
return true
|
||||
|
|
|
@ -3,22 +3,22 @@ package ackhandler
|
|||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("retransmittable frames", func() {
|
||||
for fl, el := range map[frames.Frame]bool{
|
||||
&frames.AckFrame{}: false,
|
||||
&frames.StopWaitingFrame{}: false,
|
||||
&frames.BlockedFrame{}: true,
|
||||
&frames.ConnectionCloseFrame{}: true,
|
||||
&frames.GoawayFrame{}: true,
|
||||
&frames.PingFrame{}: true,
|
||||
&frames.RstStreamFrame{}: true,
|
||||
&frames.StreamFrame{}: true,
|
||||
&frames.WindowUpdateFrame{}: true,
|
||||
for fl, el := range map[wire.Frame]bool{
|
||||
&wire.AckFrame{}: false,
|
||||
&wire.StopWaitingFrame{}: false,
|
||||
&wire.BlockedFrame{}: true,
|
||||
&wire.ConnectionCloseFrame{}: true,
|
||||
&wire.GoawayFrame{}: true,
|
||||
&wire.PingFrame{}: true,
|
||||
&wire.RstStreamFrame{}: true,
|
||||
&wire.StreamFrame{}: true,
|
||||
&wire.WindowUpdateFrame{}: true,
|
||||
} {
|
||||
f := fl
|
||||
e := el
|
||||
|
@ -29,16 +29,16 @@ var _ = Describe("retransmittable frames", func() {
|
|||
})
|
||||
|
||||
It("stripping non-retransmittable frames works for "+fName, func() {
|
||||
s := []frames.Frame{f}
|
||||
s := []wire.Frame{f}
|
||||
if e {
|
||||
Expect(stripNonRetransmittableFrames(s)).To(Equal([]frames.Frame{f}))
|
||||
Expect(stripNonRetransmittableFrames(s)).To(Equal([]wire.Frame{f}))
|
||||
} else {
|
||||
Expect(stripNonRetransmittableFrames(s)).To(BeEmpty())
|
||||
}
|
||||
})
|
||||
|
||||
It("HasRetransmittableFrames works for "+fName, func() {
|
||||
Expect(HasRetransmittableFrames([]frames.Frame{f})).To(Equal(e))
|
||||
Expect(HasRetransmittableFrames([]wire.Frame{f})).To(Equal(e))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -6,10 +6,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/congestion"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -139,7 +139,7 @@ func (h *sentPacketHandler) SentPacket(packet *Packet) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) ReceivedAck(ackFrame *frames.AckFrame, withPacketNumber protocol.PacketNumber, rcvTime time.Time) error {
|
||||
func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumber protocol.PacketNumber, rcvTime time.Time) error {
|
||||
if ackFrame.LargestAcked > h.lastSentPacketNumber {
|
||||
return errAckForUnsentPacket
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *frames.AckFrame, withPacketNum
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) determineNewlyAckedPackets(ackFrame *frames.AckFrame) ([]*PacketElement, error) {
|
||||
func (h *sentPacketHandler) determineNewlyAckedPackets(ackFrame *wire.AckFrame) ([]*PacketElement, error) {
|
||||
var ackedPackets []*PacketElement
|
||||
ackRangeIndex := 0
|
||||
for el := h.packetHistory.Front(); el != nil; el = el.Next() {
|
||||
|
@ -332,7 +332,7 @@ func (h *sentPacketHandler) GetLeastUnacked() protocol.PacketNumber {
|
|||
return h.largestInOrderAcked() + 1
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) GetStopWaitingFrame(force bool) *frames.StopWaitingFrame {
|
||||
func (h *sentPacketHandler) GetStopWaitingFrame(force bool) *wire.StopWaitingFrame {
|
||||
return h.stopWaitingManager.GetStopWaitingFrame(force)
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ func (h *sentPacketHandler) computeRTOTimeout() time.Duration {
|
|||
return utils.MinDuration(rto, maxRTOTimeout)
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) skippedPacketsAcked(ackFrame *frames.AckFrame) bool {
|
||||
func (h *sentPacketHandler) skippedPacketsAcked(ackFrame *wire.AckFrame) bool {
|
||||
for _, p := range h.skippedPackets {
|
||||
if ackFrame.AcksPacket(p) {
|
||||
return true
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/congestion"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -58,23 +58,23 @@ func (m *mockCongestion) OnPacketLost(n protocol.PacketNumber, l protocol.ByteCo
|
|||
}
|
||||
|
||||
func retransmittablePacket(num protocol.PacketNumber) *Packet {
|
||||
return &Packet{PacketNumber: num, Length: 1, Frames: []frames.Frame{&frames.PingFrame{}}}
|
||||
return &Packet{PacketNumber: num, Length: 1, Frames: []wire.Frame{&wire.PingFrame{}}}
|
||||
}
|
||||
|
||||
func nonRetransmittablePacket(num protocol.PacketNumber) *Packet {
|
||||
return &Packet{PacketNumber: num, Length: 1, Frames: []frames.Frame{&frames.AckFrame{}}}
|
||||
return &Packet{PacketNumber: num, Length: 1, Frames: []wire.Frame{&wire.AckFrame{}}}
|
||||
}
|
||||
|
||||
var _ = Describe("SentPacketHandler", func() {
|
||||
var (
|
||||
handler *sentPacketHandler
|
||||
streamFrame frames.StreamFrame
|
||||
streamFrame wire.StreamFrame
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
rttStats := &congestion.RTTStats{}
|
||||
handler = NewSentPacketHandler(rttStats).(*sentPacketHandler)
|
||||
streamFrame = frames.StreamFrame{
|
||||
streamFrame = wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0x13, 0x37},
|
||||
}
|
||||
|
@ -96,8 +96,8 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
Context("registering sent packets", func() {
|
||||
It("accepts two consecutive packets", func() {
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = handler.SentPacket(&packet2)
|
||||
|
@ -110,8 +110,8 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("rejects packets with the same packet number", func() {
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = handler.SentPacket(&packet2)
|
||||
|
@ -123,8 +123,8 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("rejects packets with decreasing packet number", func() {
|
||||
packet1 := Packet{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet1 := Packet{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = handler.SentPacket(&packet2)
|
||||
|
@ -135,7 +135,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("stores the sent time", func() {
|
||||
packet := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
err := handler.SentPacket(&packet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(handler.packetHistory.Front().Value.SendTime.Unix()).To(BeNumerically("~", time.Now().Unix(), 1))
|
||||
|
@ -149,8 +149,8 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
Context("skipped packet numbers", func() {
|
||||
It("works with non-consecutive packet numbers", func() {
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = handler.SentPacket(&packet2)
|
||||
|
@ -166,9 +166,9 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("recognizes multiple skipped packets", func() {
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet3 := Packet{PacketNumber: 5, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
packet3 := Packet{PacketNumber: 5, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = handler.SentPacket(&packet2)
|
||||
|
@ -180,8 +180,8 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("recognizes multiple consecutive skipped packets", func() {
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 4, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 4, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = handler.SentPacket(&packet2)
|
||||
|
@ -192,7 +192,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
It("limits the lengths of the skipped packet slice", func() {
|
||||
for i := 0; i < protocol.MaxTrackedSkippedPackets+5; i++ {
|
||||
packet := Packet{PacketNumber: protocol.PacketNumber(2*i + 1), Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet := Packet{PacketNumber: protocol.PacketNumber(2*i + 1), Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
err := handler.SentPacket(&packet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
@ -269,17 +269,17 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
packets = []*Packet{
|
||||
{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 4, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 5, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 6, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 7, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 8, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 9, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 10, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 12, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 4, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 5, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 6, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 7, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 8, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 9, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 10, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 12, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
}
|
||||
for _, packet := range packets {
|
||||
err := handler.SentPacket(packet)
|
||||
|
@ -293,7 +293,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Context("ACK validation", func() {
|
||||
It("rejects duplicate ACKs", func() {
|
||||
largestAcked := 3
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: protocol.PacketNumber(largestAcked),
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("rejects out of order ACKs", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 3,
|
||||
}
|
||||
err := handler.ReceivedAck(&ack, 1337, time.Now())
|
||||
|
@ -319,7 +319,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("rejects ACKs with a too high LargestAcked packet number", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: packets[len(packets)-1].PacketNumber + 1337,
|
||||
}
|
||||
err := handler.ReceivedAck(&ack, 1, time.Now())
|
||||
|
@ -328,7 +328,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("ignores repeated ACKs", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 3,
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("rejects ACKs for skipped packets", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 12,
|
||||
LowestAcked: 5,
|
||||
}
|
||||
|
@ -351,10 +351,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("accepts an ACK that correctly nacks a skipped packet", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 12,
|
||||
LowestAcked: 5,
|
||||
AckRanges: []frames.AckRange{
|
||||
AckRanges: []wire.AckRange{
|
||||
{FirstPacketNumber: 12, LastPacketNumber: 12},
|
||||
{FirstPacketNumber: 5, LastPacketNumber: 10},
|
||||
},
|
||||
|
@ -367,7 +367,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
Context("acks and nacks the right packets", func() {
|
||||
It("adjusts the LargestAcked", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 5,
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("ACKs all packets for an ACK frame with no missing packets", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 8,
|
||||
LowestAcked: 2,
|
||||
}
|
||||
|
@ -399,10 +399,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("handles an ACK frame with one missing packet range", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 9,
|
||||
LowestAcked: 2,
|
||||
AckRanges: []frames.AckRange{ // packets 4 and 5 were lost
|
||||
AckRanges: []wire.AckRange{ // packets 4 and 5 were lost
|
||||
{FirstPacketNumber: 6, LastPacketNumber: 9},
|
||||
{FirstPacketNumber: 2, LastPacketNumber: 3},
|
||||
},
|
||||
|
@ -421,7 +421,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("Does not ack packets below the LowestAcked", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 8,
|
||||
LowestAcked: 3,
|
||||
}
|
||||
|
@ -435,10 +435,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("handles an ACK with multiple missing packet ranges", func() {
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 9,
|
||||
LowestAcked: 1,
|
||||
AckRanges: []frames.AckRange{ // packets 2, 4 and 5, and 8 were lost
|
||||
AckRanges: []wire.AckRange{ // packets 2, 4 and 5, and 8 were lost
|
||||
{FirstPacketNumber: 9, LastPacketNumber: 9},
|
||||
{FirstPacketNumber: 6, LastPacketNumber: 7},
|
||||
{FirstPacketNumber: 3, LastPacketNumber: 3},
|
||||
|
@ -461,10 +461,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
It("processes an ACK frame that would be sent after a late arrival of a packet", func() {
|
||||
largestObserved := 6
|
||||
ack1 := frames.AckFrame{
|
||||
ack1 := wire.AckFrame{
|
||||
LargestAcked: protocol.PacketNumber(largestObserved),
|
||||
LowestAcked: 1,
|
||||
AckRanges: []frames.AckRange{
|
||||
AckRanges: []wire.AckRange{
|
||||
{FirstPacketNumber: 4, LastPacketNumber: protocol.PacketNumber(largestObserved)},
|
||||
{FirstPacketNumber: 1, LastPacketNumber: 2},
|
||||
},
|
||||
|
@ -474,7 +474,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 5)))
|
||||
el := handler.packetHistory.Front()
|
||||
Expect(el.Value.PacketNumber).To(Equal(protocol.PacketNumber(3)))
|
||||
ack2 := frames.AckFrame{
|
||||
ack2 := wire.AckFrame{
|
||||
LargestAcked: protocol.PacketNumber(largestObserved),
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -485,10 +485,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("processes an ACK frame that would be sent after a late arrival of a packet and another packet", func() {
|
||||
ack1 := frames.AckFrame{
|
||||
ack1 := wire.AckFrame{
|
||||
LargestAcked: 6,
|
||||
LowestAcked: 1,
|
||||
AckRanges: []frames.AckRange{
|
||||
AckRanges: []wire.AckRange{
|
||||
{FirstPacketNumber: 4, LastPacketNumber: 6},
|
||||
{FirstPacketNumber: 1, LastPacketNumber: 2},
|
||||
},
|
||||
|
@ -498,7 +498,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 5)))
|
||||
el := handler.packetHistory.Front()
|
||||
Expect(el.Value.PacketNumber).To(Equal(protocol.PacketNumber(3)))
|
||||
ack2 := frames.AckFrame{
|
||||
ack2 := wire.AckFrame{
|
||||
LargestAcked: 7,
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
})
|
||||
|
||||
It("processes an ACK that contains old ACK ranges", func() {
|
||||
ack1 := frames.AckFrame{
|
||||
ack1 := wire.AckFrame{
|
||||
LargestAcked: 6,
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -517,10 +517,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(handler.packetHistory.Front().Value.PacketNumber).To(Equal(protocol.PacketNumber(7)))
|
||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 6)))
|
||||
ack2 := frames.AckFrame{
|
||||
ack2 := wire.AckFrame{
|
||||
LargestAcked: 10,
|
||||
LowestAcked: 1,
|
||||
AckRanges: []frames.AckRange{
|
||||
AckRanges: []wire.AckRange{
|
||||
{FirstPacketNumber: 8, LastPacketNumber: 10},
|
||||
{FirstPacketNumber: 3, LastPacketNumber: 3},
|
||||
{FirstPacketNumber: 1, LastPacketNumber: 1},
|
||||
|
@ -542,13 +542,13 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
getPacketElement(2).Value.SendTime = now.Add(-5 * time.Minute)
|
||||
getPacketElement(6).Value.SendTime = now.Add(-1 * time.Minute)
|
||||
// Now, check that the proper times are used when calculating the deltas
|
||||
err := handler.ReceivedAck(&frames.AckFrame{LargestAcked: 1}, 1, time.Now())
|
||||
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 1}, 1, time.Now())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 10*time.Minute, 1*time.Second))
|
||||
err = handler.ReceivedAck(&frames.AckFrame{LargestAcked: 2}, 2, time.Now())
|
||||
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2}, 2, time.Now())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second))
|
||||
err = handler.ReceivedAck(&frames.AckFrame{LargestAcked: 6}, 3, time.Now())
|
||||
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 6}, 3, time.Now())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 1*time.Minute, 1*time.Second))
|
||||
})
|
||||
|
@ -556,7 +556,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
It("uses the DelayTime in the ack frame", func() {
|
||||
now := time.Now()
|
||||
getPacketElement(1).Value.SendTime = now.Add(-10 * time.Minute)
|
||||
err := handler.ReceivedAck(&frames.AckFrame{LargestAcked: 1, DelayTime: 5 * time.Minute}, 1, time.Now())
|
||||
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 1, DelayTime: 5 * time.Minute}, 1, time.Now())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second))
|
||||
})
|
||||
|
@ -568,13 +568,13 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
packets = []*Packet{
|
||||
{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 4, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 5, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 6, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 7, Frames: []frames.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 4, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 5, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 6, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
{PacketNumber: 7, Frames: []wire.Frame{&streamFrame}, Length: 1},
|
||||
}
|
||||
for _, packet := range packets {
|
||||
handler.SentPacket(packet)
|
||||
|
@ -582,7 +582,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
// Increase RTT, because the tests would be flaky otherwise
|
||||
handler.rttStats.UpdateRTT(time.Minute, 0, time.Now())
|
||||
// Ack a single packet so that we have non-RTO timings
|
||||
handler.ReceivedAck(&frames.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, time.Now())
|
||||
handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, time.Now())
|
||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(6)))
|
||||
})
|
||||
|
||||
|
@ -604,23 +604,23 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
|
||||
Context("StopWaitings", func() {
|
||||
It("gets a StopWaitingFrame", func() {
|
||||
ack := frames.AckFrame{LargestAcked: 5, LowestAcked: 5}
|
||||
ack := wire.AckFrame{LargestAcked: 5, LowestAcked: 5}
|
||||
err := handler.ReceivedAck(&ack, 2, time.Now())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(handler.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 6}))
|
||||
Expect(handler.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 6}))
|
||||
})
|
||||
|
||||
It("gets a StopWaitingFrame after queueing a retransmission", func() {
|
||||
handler.queuePacketForRetransmission(getPacketElement(5))
|
||||
Expect(handler.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 6}))
|
||||
Expect(handler.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 6}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
It("calculates bytes in flight", func() {
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 2}
|
||||
packet3 := Packet{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 3}
|
||||
packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
|
||||
packet2 := Packet{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 2}
|
||||
packet3 := Packet{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 3}
|
||||
err := handler.SentPacket(&packet1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(1)))
|
||||
|
@ -635,10 +635,10 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
handler.rttStats.UpdateRTT(time.Minute, 0, time.Now())
|
||||
|
||||
// ACK 1 and 3, NACK 2
|
||||
ack := frames.AckFrame{
|
||||
ack := wire.AckFrame{
|
||||
LargestAcked: 3,
|
||||
LowestAcked: 1,
|
||||
AckRanges: []frames.AckRange{
|
||||
AckRanges: []wire.AckRange{
|
||||
{FirstPacketNumber: 3, LastPacketNumber: 3},
|
||||
{FirstPacketNumber: 1, LastPacketNumber: 1},
|
||||
},
|
||||
|
@ -667,7 +667,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
p := &Packet{
|
||||
PacketNumber: 1,
|
||||
Length: 42,
|
||||
Frames: []frames.Frame{&frames.PingFrame{}},
|
||||
Frames: []wire.Frame{&wire.PingFrame{}},
|
||||
}
|
||||
err := handler.SentPacket(p)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -680,7 +680,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
It("should call MaybeExitSlowStart and OnPacketAcked", func() {
|
||||
handler.SentPacket(retransmittablePacket(1))
|
||||
handler.SentPacket(retransmittablePacket(2))
|
||||
err := handler.ReceivedAck(&frames.AckFrame{LargestAcked: 1, LowestAcked: 1}, 1, time.Now())
|
||||
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 1, LowestAcked: 1}, 1, time.Now())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(cong.maybeExitSlowStart).To(BeTrue())
|
||||
Expect(cong.packetsAcked).To(BeEquivalentTo([][]interface{}{
|
||||
|
@ -707,7 +707,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Expect(handler.SendingAllowed()).To(BeTrue())
|
||||
err := handler.SentPacket(&Packet{
|
||||
PacketNumber: 1,
|
||||
Frames: []frames.Frame{&frames.PingFrame{}},
|
||||
Frames: []wire.Frame{&wire.PingFrame{}},
|
||||
Length: protocol.DefaultTCPMSS + 1,
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -723,7 +723,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
It("allows sending if there are retransmisisons outstanding", func() {
|
||||
err := handler.SentPacket(&Packet{
|
||||
PacketNumber: 1,
|
||||
Frames: []frames.Frame{&frames.PingFrame{}},
|
||||
Frames: []wire.Frame{&wire.PingFrame{}},
|
||||
Length: protocol.DefaultTCPMSS + 1,
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -775,7 +775,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
||||
|
||||
err = handler.ReceivedAck(&frames.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, time.Now().Add(time.Hour))
|
||||
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, time.Now().Add(time.Hour))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.lossTime.IsZero()).To(BeFalse())
|
||||
|
||||
|
@ -798,7 +798,7 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
||||
|
||||
err = handler.ReceivedAck(&frames.AckFrame{LargestAcked: 1, LowestAcked: 1}, 1, time.Now().Add(time.Hour))
|
||||
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 1, LowestAcked: 1}, 1, time.Now().Add(time.Hour))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
||||
Expect(handler.GetAlarmTimeout().Sub(time.Now())).To(BeNumerically("~", handler.computeRTOTimeout(), time.Minute))
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
// This stopWaitingManager is not supposed to satisfy the StopWaitingManager interface, which is a remnant of the legacy AckHandler, and should be remove once we drop support for QUIC 33
|
||||
|
@ -10,10 +10,10 @@ type stopWaitingManager struct {
|
|||
largestLeastUnackedSent protocol.PacketNumber
|
||||
nextLeastUnacked protocol.PacketNumber
|
||||
|
||||
lastStopWaitingFrame *frames.StopWaitingFrame
|
||||
lastStopWaitingFrame *wire.StopWaitingFrame
|
||||
}
|
||||
|
||||
func (s *stopWaitingManager) GetStopWaitingFrame(force bool) *frames.StopWaitingFrame {
|
||||
func (s *stopWaitingManager) GetStopWaitingFrame(force bool) *wire.StopWaitingFrame {
|
||||
if s.nextLeastUnacked <= s.largestLeastUnackedSent {
|
||||
if force {
|
||||
return s.lastStopWaitingFrame
|
||||
|
@ -22,14 +22,14 @@ func (s *stopWaitingManager) GetStopWaitingFrame(force bool) *frames.StopWaiting
|
|||
}
|
||||
|
||||
s.largestLeastUnackedSent = s.nextLeastUnacked
|
||||
swf := &frames.StopWaitingFrame{
|
||||
swf := &wire.StopWaitingFrame{
|
||||
LeastUnacked: s.nextLeastUnacked,
|
||||
}
|
||||
s.lastStopWaitingFrame = swf
|
||||
return swf
|
||||
}
|
||||
|
||||
func (s *stopWaitingManager) ReceivedAck(ack *frames.AckFrame) {
|
||||
func (s *stopWaitingManager) ReceivedAck(ack *wire.AckFrame) {
|
||||
if ack.LargestAcked >= s.nextLeastUnacked {
|
||||
s.nextLeastUnacked = ack.LargestAcked + 1
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -18,38 +18,38 @@ var _ = Describe("StopWaitingManager", func() {
|
|||
})
|
||||
|
||||
It("returns a StopWaitingFrame, when a new ACK arrives", func() {
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10})
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 11}))
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
|
||||
})
|
||||
|
||||
It("does not decrease the LeastUnacked", func() {
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10})
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 9})
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 11}))
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 9})
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
|
||||
})
|
||||
|
||||
It("does not send the same StopWaitingFrame twice", func() {
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10})
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
|
||||
Expect(manager.GetStopWaitingFrame(false)).ToNot(BeNil())
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(BeNil())
|
||||
})
|
||||
|
||||
It("gets the same StopWaitingFrame twice, if forced", func() {
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10})
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
|
||||
Expect(manager.GetStopWaitingFrame(false)).ToNot(BeNil())
|
||||
Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil())
|
||||
Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil())
|
||||
})
|
||||
|
||||
It("increases the LeastUnacked when a retransmission is queued", func() {
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10})
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
|
||||
manager.QueuedRetransmissionForPacketNumber(20)
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 21}))
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 21}))
|
||||
})
|
||||
|
||||
It("does not decrease the LeastUnacked when a retransmission is queued", func() {
|
||||
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10})
|
||||
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
|
||||
manager.QueuedRetransmissionForPacketNumber(9)
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 11}))
|
||||
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package frames
|
||||
|
||||
import "github.com/lucas-clemente/quic-go/internal/utils"
|
||||
|
||||
// LogFrame logs a frame, either sent or received
|
||||
func LogFrame(frame Frame, sent bool) {
|
||||
if !utils.Debug() {
|
||||
return
|
||||
}
|
||||
dir := "<-"
|
||||
if sent {
|
||||
dir = "->"
|
||||
}
|
||||
switch f := frame.(type) {
|
||||
case *StreamFrame:
|
||||
utils.Debugf("\t%s &frames.StreamFrame{StreamID: %d, FinBit: %t, Offset: 0x%x, Data length: 0x%x, Offset + Data length: 0x%x}", dir, f.StreamID, f.FinBit, f.Offset, f.DataLen(), f.Offset+f.DataLen())
|
||||
case *StopWaitingFrame:
|
||||
if sent {
|
||||
utils.Debugf("\t%s &frames.StopWaitingFrame{LeastUnacked: 0x%x, PacketNumberLen: 0x%x}", dir, f.LeastUnacked, f.PacketNumberLen)
|
||||
} else {
|
||||
utils.Debugf("\t%s &frames.StopWaitingFrame{LeastUnacked: 0x%x}", dir, f.LeastUnacked)
|
||||
}
|
||||
case *AckFrame:
|
||||
utils.Debugf("\t%s &frames.AckFrame{LargestAcked: 0x%x, LowestAcked: 0x%x, AckRanges: %#v, DelayTime: %s}", dir, f.LargestAcked, f.LowestAcked, f.AckRanges, f.DelayTime.String())
|
||||
default:
|
||||
utils.Debugf("\t%s %#v", dir, frame)
|
||||
}
|
||||
}
|
|
@ -6,15 +6,15 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/ackhandler"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/handshake"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
type packedPacket struct {
|
||||
number protocol.PacketNumber
|
||||
raw []byte
|
||||
frames []frames.Frame
|
||||
frames []wire.Frame
|
||||
encryptionLevel protocol.EncryptionLevel
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,9 @@ type packetPacker struct {
|
|||
connectionParameters handshake.ConnectionParametersManager
|
||||
streamFramer *streamFramer
|
||||
|
||||
controlFrames []frames.Frame
|
||||
stopWaiting *frames.StopWaitingFrame
|
||||
ackFrame *frames.AckFrame
|
||||
controlFrames []wire.Frame
|
||||
stopWaiting *wire.StopWaitingFrame
|
||||
ackFrame *wire.AckFrame
|
||||
leastUnacked protocol.PacketNumber
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ func newPacketPacker(connectionID protocol.ConnectionID,
|
|||
}
|
||||
|
||||
// PackConnectionClose packs a packet that ONLY contains a ConnectionCloseFrame
|
||||
func (p *packetPacker) PackConnectionClose(ccf *frames.ConnectionCloseFrame) (*packedPacket, error) {
|
||||
frames := []frames.Frame{ccf}
|
||||
func (p *packetPacker) PackConnectionClose(ccf *wire.ConnectionCloseFrame) (*packedPacket, error) {
|
||||
frames := []wire.Frame{ccf}
|
||||
encLevel, sealer := p.cryptoSetup.GetSealer()
|
||||
ph := p.getPublicHeader(encLevel)
|
||||
raw, err := p.writeAndSealPacket(ph, frames, sealer)
|
||||
|
@ -72,7 +72,7 @@ func (p *packetPacker) PackAckPacket() (*packedPacket, error) {
|
|||
}
|
||||
encLevel, sealer := p.cryptoSetup.GetSealer()
|
||||
ph := p.getPublicHeader(encLevel)
|
||||
frames := []frames.Frame{p.ackFrame}
|
||||
frames := []wire.Frame{p.ackFrame}
|
||||
if p.stopWaiting != nil {
|
||||
p.stopWaiting.PacketNumber = ph.PacketNumber
|
||||
p.stopWaiting.PacketNumberLen = ph.PacketNumberLen
|
||||
|
@ -104,7 +104,7 @@ func (p *packetPacker) PackHandshakeRetransmission(packet *ackhandler.Packet) (*
|
|||
ph := p.getPublicHeader(packet.EncryptionLevel)
|
||||
p.stopWaiting.PacketNumber = ph.PacketNumber
|
||||
p.stopWaiting.PacketNumberLen = ph.PacketNumberLen
|
||||
frames := append([]frames.Frame{p.stopWaiting}, packet.Frames...)
|
||||
frames := append([]wire.Frame{p.stopWaiting}, packet.Frames...)
|
||||
p.stopWaiting = nil
|
||||
raw, err := p.writeAndSealPacket(ph, frames, sealer)
|
||||
return &packedPacket{
|
||||
|
@ -171,7 +171,7 @@ func (p *packetPacker) packCryptoPacket() (*packedPacket, error) {
|
|||
return nil, err
|
||||
}
|
||||
maxLen := protocol.MaxFrameAndPublicHeaderSize - protocol.NonForwardSecurePacketSizeReduction - publicHeaderLength
|
||||
frames := []frames.Frame{p.streamFramer.PopCryptoStreamFrame(maxLen)}
|
||||
frames := []wire.Frame{p.streamFramer.PopCryptoStreamFrame(maxLen)}
|
||||
raw, err := p.writeAndSealPacket(publicHeader, frames, sealer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -187,9 +187,9 @@ func (p *packetPacker) packCryptoPacket() (*packedPacket, error) {
|
|||
func (p *packetPacker) composeNextPacket(
|
||||
maxFrameSize protocol.ByteCount,
|
||||
canSendStreamFrames bool,
|
||||
) ([]frames.Frame, error) {
|
||||
) ([]wire.Frame, error) {
|
||||
var payloadLength protocol.ByteCount
|
||||
var payloadFrames []frames.Frame
|
||||
var payloadFrames []wire.Frame
|
||||
|
||||
// STOP_WAITING and ACK will always fit
|
||||
if p.stopWaiting != nil {
|
||||
|
@ -253,11 +253,11 @@ func (p *packetPacker) composeNextPacket(
|
|||
return payloadFrames, nil
|
||||
}
|
||||
|
||||
func (p *packetPacker) QueueControlFrame(frame frames.Frame) {
|
||||
func (p *packetPacker) QueueControlFrame(frame wire.Frame) {
|
||||
switch f := frame.(type) {
|
||||
case *frames.StopWaitingFrame:
|
||||
case *wire.StopWaitingFrame:
|
||||
p.stopWaiting = f
|
||||
case *frames.AckFrame:
|
||||
case *wire.AckFrame:
|
||||
p.ackFrame = f
|
||||
default:
|
||||
p.controlFrames = append(p.controlFrames, f)
|
||||
|
@ -287,7 +287,7 @@ func (p *packetPacker) getPublicHeader(encLevel protocol.EncryptionLevel) *Publi
|
|||
|
||||
func (p *packetPacker) writeAndSealPacket(
|
||||
publicHeader *PublicHeader,
|
||||
payloadFrames []frames.Frame,
|
||||
payloadFrames []wire.Frame,
|
||||
sealer handshake.Sealer,
|
||||
) ([]byte, error) {
|
||||
raw := getPacketBuffer()
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
"math"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/ackhandler"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/handshake"
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -86,7 +86,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs single packets", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("stores the encryption level a packet was sealed with", func() {
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionForwardSecure
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a ConnectionClose", func() {
|
||||
ccf := frames.ConnectionCloseFrame{
|
||||
ccf := wire.ConnectionCloseFrame{
|
||||
ErrorCode: 0x1337,
|
||||
ReasonPhrase: "foobar",
|
||||
}
|
||||
|
@ -154,12 +154,12 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("doesn't send any other frames when sending a ConnectionClose", func() {
|
||||
ccf := frames.ConnectionCloseFrame{
|
||||
ccf := wire.ConnectionCloseFrame{
|
||||
ErrorCode: 0x1337,
|
||||
ReasonPhrase: "foobar",
|
||||
}
|
||||
packer.controlFrames = []frames.Frame{&frames.WindowUpdateFrame{StreamID: 37}}
|
||||
streamFramer.AddFrameForRetransmission(&frames.StreamFrame{
|
||||
packer.controlFrames = []wire.Frame{&wire.WindowUpdateFrame{StreamID: 37}}
|
||||
streamFramer.AddFrameForRetransmission(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
|
@ -170,8 +170,8 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs only control frames", func() {
|
||||
packer.QueueControlFrame(&frames.RstStreamFrame{})
|
||||
packer.QueueControlFrame(&frames.WindowUpdateFrame{})
|
||||
packer.QueueControlFrame(&wire.RstStreamFrame{})
|
||||
packer.QueueControlFrame(&wire.WindowUpdateFrame{})
|
||||
p, err := packer.PackPacket()
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -180,11 +180,11 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("increases the packet number", func() {
|
||||
packer.QueueControlFrame(&frames.RstStreamFrame{})
|
||||
packer.QueueControlFrame(&wire.RstStreamFrame{})
|
||||
p1, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p1).ToNot(BeNil())
|
||||
packer.QueueControlFrame(&frames.RstStreamFrame{})
|
||||
packer.QueueControlFrame(&wire.RstStreamFrame{})
|
||||
p2, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p2).ToNot(BeNil())
|
||||
|
@ -193,8 +193,8 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("packs a StopWaitingFrame first", func() {
|
||||
packer.packetNumberGenerator.next = 15
|
||||
swf := &frames.StopWaitingFrame{LeastUnacked: 10}
|
||||
packer.QueueControlFrame(&frames.RstStreamFrame{})
|
||||
swf := &wire.StopWaitingFrame{LeastUnacked: 10}
|
||||
packer.QueueControlFrame(&wire.RstStreamFrame{})
|
||||
packer.QueueControlFrame(swf)
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -206,16 +206,16 @@ var _ = Describe("Packet packer", func() {
|
|||
It("sets the LeastUnackedDelta length of a StopWaitingFrame", func() {
|
||||
packetNumber := protocol.PacketNumber(0xDECAFB) // will result in a 4 byte packet number
|
||||
packer.packetNumberGenerator.next = packetNumber
|
||||
swf := &frames.StopWaitingFrame{LeastUnacked: packetNumber - 0x100}
|
||||
packer.QueueControlFrame(&frames.RstStreamFrame{})
|
||||
swf := &wire.StopWaitingFrame{LeastUnacked: packetNumber - 0x100}
|
||||
packer.QueueControlFrame(&wire.RstStreamFrame{})
|
||||
packer.QueueControlFrame(swf)
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.frames[0].(*frames.StopWaitingFrame).PacketNumberLen).To(Equal(protocol.PacketNumberLen4))
|
||||
Expect(p.frames[0].(*wire.StopWaitingFrame).PacketNumberLen).To(Equal(protocol.PacketNumberLen4))
|
||||
})
|
||||
|
||||
It("does not pack a packet containing only a StopWaitingFrame", func() {
|
||||
swf := &frames.StopWaitingFrame{LeastUnacked: 10}
|
||||
swf := &wire.StopWaitingFrame{LeastUnacked: 10}
|
||||
packer.QueueControlFrame(swf)
|
||||
p, err := packer.PackPacket()
|
||||
Expect(p).To(BeNil())
|
||||
|
@ -223,7 +223,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a packet if it has queued control frames, but no new control frames", func() {
|
||||
packer.controlFrames = []frames.Frame{&frames.BlockedFrame{StreamID: 0}}
|
||||
packer.controlFrames = []wire.Frame{&wire.BlockedFrame{StreamID: 0}}
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p).ToNot(BeNil())
|
||||
|
@ -232,7 +232,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("adds the version flag to the public header before the crypto handshake is finished", func() {
|
||||
packer.perspective = protocol.PerspectiveClient
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure
|
||||
packer.controlFrames = []frames.Frame{&frames.BlockedFrame{StreamID: 0}}
|
||||
packer.controlFrames = []wire.Frame{&wire.BlockedFrame{StreamID: 0}}
|
||||
packer.connectionID = 0x1337
|
||||
packer.version = 123
|
||||
p, err := packer.PackPacket()
|
||||
|
@ -247,7 +247,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("doesn't add the version flag to the public header for forward-secure packets", func() {
|
||||
packer.perspective = protocol.PerspectiveClient
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionForwardSecure
|
||||
packer.controlFrames = []frames.Frame{&frames.BlockedFrame{StreamID: 0}}
|
||||
packer.controlFrames = []wire.Frame{&wire.BlockedFrame{StreamID: 0}}
|
||||
packer.connectionID = 0x1337
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -258,11 +258,11 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs many control frames into 1 packets", func() {
|
||||
f := &frames.AckFrame{LargestAcked: 1}
|
||||
f := &wire.AckFrame{LargestAcked: 1}
|
||||
b := &bytes.Buffer{}
|
||||
f.Write(b, protocol.VersionWhatever)
|
||||
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / b.Len()
|
||||
var controlFrames []frames.Frame
|
||||
var controlFrames []wire.Frame
|
||||
for i := 0; i < maxFramesPerPacket; i++ {
|
||||
controlFrames = append(controlFrames, f)
|
||||
}
|
||||
|
@ -276,12 +276,12 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a lot of control frames into 2 packets if they don't fit into one", func() {
|
||||
blockedFrame := &frames.BlockedFrame{
|
||||
blockedFrame := &wire.BlockedFrame{
|
||||
StreamID: 0x1337,
|
||||
}
|
||||
minLength, _ := blockedFrame.MinLength(0)
|
||||
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / int(minLength)
|
||||
var controlFrames []frames.Frame
|
||||
var controlFrames []wire.Frame
|
||||
for i := 0; i < maxFramesPerPacket+10; i++ {
|
||||
controlFrames = append(controlFrames, blockedFrame)
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(p).To(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packer.packetNumberGenerator.Peek()).To(Equal(protocol.PacketNumber(1)))
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("Stream Frame handling", func() {
|
||||
It("does not splits a stream frame with maximum size", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 1,
|
||||
StreamID: 5,
|
||||
DataLenPresent: false,
|
||||
|
@ -326,7 +326,7 @@ var _ = Describe("Packet packer", func() {
|
|||
payloadFrames, err := packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(payloadFrames).To(HaveLen(1))
|
||||
Expect(payloadFrames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(payloadFrames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
payloadFrames, err = packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(payloadFrames).To(BeEmpty())
|
||||
|
@ -334,12 +334,12 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("correctly handles a stream frame with one byte less than maximum size", func() {
|
||||
maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - (1 + 1 + 2) - 1
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)),
|
||||
}
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
Data: []byte("foobar"),
|
||||
|
@ -350,23 +350,23 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize - 1)))
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
p, err = packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
})
|
||||
|
||||
It("packs multiple small stream frames into single packet", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
|
||||
}
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xBE, 0xEF, 0x13, 0x37},
|
||||
}
|
||||
f3 := &frames.StreamFrame{
|
||||
f3 := &wire.StreamFrame{
|
||||
StreamID: 3,
|
||||
Data: []byte{0xCA, 0xFE},
|
||||
}
|
||||
|
@ -381,16 +381,16 @@ var _ = Describe("Packet packer", func() {
|
|||
f2.Write(b, 0)
|
||||
f3.Write(b, 0)
|
||||
Expect(p.frames).To(HaveLen(3))
|
||||
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeTrue())
|
||||
Expect(p.frames[1].(*frames.StreamFrame).DataLenPresent).To(BeTrue())
|
||||
Expect(p.frames[2].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeTrue())
|
||||
Expect(p.frames[1].(*wire.StreamFrame).DataLenPresent).To(BeTrue())
|
||||
Expect(p.frames[2].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.raw).To(ContainSubstring(string(f1.Data)))
|
||||
Expect(p.raw).To(ContainSubstring(string(f2.Data)))
|
||||
Expect(p.raw).To(ContainSubstring(string(f3.Data)))
|
||||
})
|
||||
|
||||
It("splits one stream frame larger than maximum size", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 7,
|
||||
Offset: 1,
|
||||
}
|
||||
|
@ -401,13 +401,13 @@ var _ = Describe("Packet packer", func() {
|
|||
payloadFrames, err := packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(payloadFrames).To(HaveLen(1))
|
||||
Expect(payloadFrames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(payloadFrames[0].(*frames.StreamFrame).Data).To(HaveLen(int(maxStreamFrameDataLen)))
|
||||
Expect(payloadFrames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(payloadFrames[0].(*wire.StreamFrame).Data).To(HaveLen(int(maxStreamFrameDataLen)))
|
||||
payloadFrames, err = packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(payloadFrames).To(HaveLen(1))
|
||||
Expect(payloadFrames[0].(*frames.StreamFrame).Data).To(HaveLen(200))
|
||||
Expect(payloadFrames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(payloadFrames[0].(*wire.StreamFrame).Data).To(HaveLen(200))
|
||||
Expect(payloadFrames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
payloadFrames, err = packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(payloadFrames).To(BeEmpty())
|
||||
|
@ -415,12 +415,12 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("packs 2 stream frames that are too big for one packet correctly", func() {
|
||||
maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - (1 + 1 + 2)
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+100),
|
||||
Offset: 1,
|
||||
}
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+100),
|
||||
Offset: 1,
|
||||
|
@ -430,17 +430,17 @@ var _ = Describe("Packet packer", func() {
|
|||
p, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize)))
|
||||
p, err = packer.PackPacket()
|
||||
Expect(p.frames).To(HaveLen(2))
|
||||
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeTrue())
|
||||
Expect(p.frames[1].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeTrue())
|
||||
Expect(p.frames[1].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize)))
|
||||
p, err = packer.PackPacket()
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p).ToNot(BeNil())
|
||||
p, err = packer.PackPacket()
|
||||
|
@ -449,7 +449,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a packet that has the maximum packet size when given a large enough stream frame", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("splits a stream frame larger than the maximum size", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("refuses to send unencrypted stream data on a data stream", func() {
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 3,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("sends non forward-secure data as the client", func() {
|
||||
packer.perspective = protocol.PerspectiveClient
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("does not send non forward-secure data as the server", func() {
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.encryptionLevel).To(Equal(protocol.EncryptionUnencrypted))
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(p.frames[0]).To(Equal(&frames.StreamFrame{StreamID: 1, Data: []byte("foobar")}))
|
||||
Expect(p.frames[0]).To(Equal(&wire.StreamFrame{StreamID: 1, Data: []byte("foobar")}))
|
||||
})
|
||||
|
||||
It("sends encrypted stream data on the crypto stream", func() {
|
||||
|
@ -534,38 +534,38 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.encryptionLevel).To(Equal(protocol.EncryptionSecure))
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(p.frames[0]).To(Equal(&frames.StreamFrame{StreamID: 1, Data: []byte("foobar")}))
|
||||
Expect(p.frames[0]).To(Equal(&wire.StreamFrame{StreamID: 1, Data: []byte("foobar")}))
|
||||
})
|
||||
|
||||
It("does not pack stream frames if not allowed", func() {
|
||||
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted
|
||||
packer.QueueControlFrame(&frames.AckFrame{})
|
||||
streamFramer.AddFrameForRetransmission(&frames.StreamFrame{StreamID: 3, Data: []byte("foobar")})
|
||||
packer.QueueControlFrame(&wire.AckFrame{})
|
||||
streamFramer.AddFrameForRetransmission(&wire.StreamFrame{StreamID: 3, Data: []byte("foobar")})
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.frames).To(HaveLen(1))
|
||||
Expect(func() { _ = p.frames[0].(*frames.AckFrame) }).NotTo(Panic())
|
||||
Expect(func() { _ = p.frames[0].(*wire.AckFrame) }).NotTo(Panic())
|
||||
})
|
||||
})
|
||||
|
||||
Context("Blocked frames", func() {
|
||||
It("queues a BLOCKED frame", func() {
|
||||
length := 100
|
||||
streamFramer.blockedFrameQueue = []*frames.BlockedFrame{{StreamID: 5}}
|
||||
f := &frames.StreamFrame{
|
||||
streamFramer.blockedFrameQueue = []*wire.BlockedFrame{{StreamID: 5}}
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: bytes.Repeat([]byte{'f'}, length),
|
||||
}
|
||||
streamFramer.AddFrameForRetransmission(f)
|
||||
_, err := packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packer.controlFrames[0]).To(Equal(&frames.BlockedFrame{StreamID: 5}))
|
||||
Expect(packer.controlFrames[0]).To(Equal(&wire.BlockedFrame{StreamID: 5}))
|
||||
})
|
||||
|
||||
It("removes the dataLen attribute from the last StreamFrame, even if it queued a BLOCKED frame", func() {
|
||||
length := 100
|
||||
streamFramer.blockedFrameQueue = []*frames.BlockedFrame{{StreamID: 5}}
|
||||
f := &frames.StreamFrame{
|
||||
streamFramer.blockedFrameQueue = []*wire.BlockedFrame{{StreamID: 5}}
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: bytes.Repeat([]byte{'f'}, length),
|
||||
}
|
||||
|
@ -573,31 +573,31 @@ var _ = Describe("Packet packer", func() {
|
|||
p, err := packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p).To(HaveLen(1))
|
||||
Expect(p[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
Expect(p[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
|
||||
})
|
||||
|
||||
It("packs a connection-level BlockedFrame", func() {
|
||||
streamFramer.blockedFrameQueue = []*frames.BlockedFrame{{StreamID: 0}}
|
||||
f := &frames.StreamFrame{
|
||||
streamFramer.blockedFrameQueue = []*wire.BlockedFrame{{StreamID: 0}}
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
streamFramer.AddFrameForRetransmission(f)
|
||||
_, err := packer.composeNextPacket(maxFrameSize, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packer.controlFrames[0]).To(Equal(&frames.BlockedFrame{StreamID: 0}))
|
||||
Expect(packer.controlFrames[0]).To(Equal(&wire.BlockedFrame{StreamID: 0}))
|
||||
})
|
||||
})
|
||||
|
||||
It("returns nil if we only have a single STOP_WAITING", func() {
|
||||
packer.QueueControlFrame(&frames.StopWaitingFrame{})
|
||||
packer.QueueControlFrame(&wire.StopWaitingFrame{})
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(p).To(BeNil())
|
||||
})
|
||||
|
||||
It("packs a single ACK", func() {
|
||||
ack := &frames.AckFrame{LargestAcked: 42}
|
||||
ack := &wire.AckFrame{LargestAcked: 42}
|
||||
packer.QueueControlFrame(ack)
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -606,7 +606,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("does not return nil if we only have a single ACK but request it to be sent", func() {
|
||||
ack := &frames.AckFrame{}
|
||||
ack := &wire.AckFrame{}
|
||||
packer.QueueControlFrame(ack)
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -614,7 +614,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("queues a control frame to be sent in the next packet", func() {
|
||||
wuf := &frames.WindowUpdateFrame{StreamID: 5}
|
||||
wuf := &wire.WindowUpdateFrame{StreamID: 5}
|
||||
packer.QueueControlFrame(wuf)
|
||||
p, err := packer.PackPacket()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -623,8 +623,8 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
Context("retransmitting of handshake packets", func() {
|
||||
swf := &frames.StopWaitingFrame{LeastUnacked: 1}
|
||||
sf := &frames.StreamFrame{
|
||||
swf := &wire.StopWaitingFrame{LeastUnacked: 1}
|
||||
sf := &wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -636,7 +636,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("packs a retransmission for a packet sent with no encryption", func() {
|
||||
packet := &ackhandler.Packet{
|
||||
EncryptionLevel: protocol.EncryptionUnencrypted,
|
||||
Frames: []frames.Frame{sf},
|
||||
Frames: []wire.Frame{sf},
|
||||
}
|
||||
p, err := packer.PackHandshakeRetransmission(packet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -650,7 +650,7 @@ var _ = Describe("Packet packer", func() {
|
|||
packer.cryptoSetup.(*mockCryptoSetup).divNonce = nonce
|
||||
packet := &ackhandler.Packet{
|
||||
EncryptionLevel: protocol.EncryptionSecure,
|
||||
Frames: []frames.Frame{sf},
|
||||
Frames: []wire.Frame{sf},
|
||||
}
|
||||
p, err := packer.PackHandshakeRetransmission(packet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -665,7 +665,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("includes the diversification nonce on packets sent with initial encryption", func() {
|
||||
packet := &ackhandler.Packet{
|
||||
EncryptionLevel: protocol.EncryptionSecure,
|
||||
Frames: []frames.Frame{sf},
|
||||
Frames: []wire.Frame{sf},
|
||||
}
|
||||
p, err := packer.PackHandshakeRetransmission(packet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -677,8 +677,8 @@ var _ = Describe("Packet packer", func() {
|
|||
It("refuses to send a packet larger than MaxPacketSize", func() {
|
||||
packet := &ackhandler.Packet{
|
||||
EncryptionLevel: protocol.EncryptionSecure,
|
||||
Frames: []frames.Frame{
|
||||
&frames.StreamFrame{
|
||||
Frames: []wire.Frame{
|
||||
&wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: bytes.Repeat([]byte{'f'}, int(protocol.MaxPacketSize-5)),
|
||||
},
|
||||
|
@ -707,20 +707,20 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("packing ACK packets", func() {
|
||||
It("packs ACK packets", func() {
|
||||
packer.QueueControlFrame(&frames.AckFrame{})
|
||||
packer.QueueControlFrame(&wire.AckFrame{})
|
||||
p, err := packer.PackAckPacket()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(p.frames).To(Equal([]frames.Frame{&frames.AckFrame{DelayTime: math.MaxInt64}}))
|
||||
Expect(p.frames).To(Equal([]wire.Frame{&wire.AckFrame{DelayTime: math.MaxInt64}}))
|
||||
})
|
||||
|
||||
It("packs ACK packets with SWFs", func() {
|
||||
packer.QueueControlFrame(&frames.AckFrame{})
|
||||
packer.QueueControlFrame(&frames.StopWaitingFrame{})
|
||||
packer.QueueControlFrame(&wire.AckFrame{})
|
||||
packer.QueueControlFrame(&wire.StopWaitingFrame{})
|
||||
p, err := packer.PackAckPacket()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(p.frames).To(Equal([]frames.Frame{
|
||||
&frames.AckFrame{DelayTime: math.MaxInt64},
|
||||
&frames.StopWaitingFrame{PacketNumber: 1, PacketNumberLen: 2},
|
||||
Expect(p.frames).To(Equal([]wire.Frame{
|
||||
&wire.AckFrame{DelayTime: math.MaxInt64},
|
||||
&wire.StopWaitingFrame{PacketNumber: 1, PacketNumberLen: 2},
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
type unpackedPacket struct {
|
||||
encryptionLevel protocol.EncryptionLevel
|
||||
frames []frames.Frame
|
||||
frames []wire.Frame
|
||||
}
|
||||
|
||||
type quicAEAD interface {
|
||||
|
@ -38,7 +38,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
|
|||
return nil, qerr.MissingPayload
|
||||
}
|
||||
|
||||
fs := make([]frames.Frame, 0, 2)
|
||||
fs := make([]wire.Frame, 0, 2)
|
||||
|
||||
// Read all frames in the packet
|
||||
for r.Len() > 0 {
|
||||
|
@ -48,19 +48,19 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
|
|||
}
|
||||
r.UnreadByte()
|
||||
|
||||
var frame frames.Frame
|
||||
var frame wire.Frame
|
||||
if typeByte&0x80 == 0x80 {
|
||||
frame, err = frames.ParseStreamFrame(r, u.version)
|
||||
frame, err = wire.ParseStreamFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidStreamData, err.Error())
|
||||
} else {
|
||||
streamID := frame.(*frames.StreamFrame).StreamID
|
||||
streamID := frame.(*wire.StreamFrame).StreamID
|
||||
if streamID != 1 && encryptionLevel <= protocol.EncryptionUnencrypted {
|
||||
err = qerr.Error(qerr.UnencryptedStreamData, fmt.Sprintf("received unencrypted stream data on stream %d", streamID))
|
||||
}
|
||||
}
|
||||
} else if typeByte&0xc0 == 0x40 {
|
||||
frame, err = frames.ParseAckFrame(r, u.version)
|
||||
frame, err = wire.ParseAckFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidAckData, err.Error())
|
||||
}
|
||||
|
@ -69,37 +69,37 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
|
|||
} else {
|
||||
switch typeByte {
|
||||
case 0x01:
|
||||
frame, err = frames.ParseRstStreamFrame(r, u.version)
|
||||
frame, err = wire.ParseRstStreamFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidRstStreamData, err.Error())
|
||||
}
|
||||
case 0x02:
|
||||
frame, err = frames.ParseConnectionCloseFrame(r, u.version)
|
||||
frame, err = wire.ParseConnectionCloseFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidConnectionCloseData, err.Error())
|
||||
}
|
||||
case 0x03:
|
||||
frame, err = frames.ParseGoawayFrame(r, u.version)
|
||||
frame, err = wire.ParseGoawayFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidGoawayData, err.Error())
|
||||
}
|
||||
case 0x04:
|
||||
frame, err = frames.ParseWindowUpdateFrame(r, u.version)
|
||||
frame, err = wire.ParseWindowUpdateFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidWindowUpdateData, err.Error())
|
||||
}
|
||||
case 0x05:
|
||||
frame, err = frames.ParseBlockedFrame(r, u.version)
|
||||
frame, err = wire.ParseBlockedFrame(r, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidBlockedData, err.Error())
|
||||
}
|
||||
case 0x06:
|
||||
frame, err = frames.ParseStopWaitingFrame(r, hdr.PacketNumber, hdr.PacketNumberLen, u.version)
|
||||
frame, err = wire.ParseStopWaitingFrame(r, hdr.PacketNumber, hdr.PacketNumberLen, u.version)
|
||||
if err != nil {
|
||||
err = qerr.Error(qerr.InvalidStopWaitingData, err.Error())
|
||||
}
|
||||
case 0x07:
|
||||
frame, err = frames.ParsePingFrame(r, u.version)
|
||||
frame, err = wire.ParsePingFrame(r, u.version)
|
||||
default:
|
||||
err = qerr.Error(qerr.InvalidFrameData, fmt.Sprintf("unknown type byte 0x%x", typeByte))
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/crypto"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -53,17 +53,17 @@ var _ = Describe("Packet unpacker", func() {
|
|||
}
|
||||
|
||||
It("does not read read a private flag for QUIC Version >= 34", func() {
|
||||
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
f := &wire.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
err := f.Write(buf, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
setData(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{f}))
|
||||
})
|
||||
|
||||
It("saves the encryption level", func() {
|
||||
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
f := &wire.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
err := f.Write(buf, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
setData(buf.Bytes())
|
||||
|
@ -75,7 +75,7 @@ var _ = Describe("Packet unpacker", func() {
|
|||
|
||||
It("unpacks ACK frames", func() {
|
||||
unpacker.version = protocol.VersionWhatever
|
||||
f := &frames.AckFrame{
|
||||
f := &wire.AckFrame{
|
||||
LargestAcked: 0x13,
|
||||
LowestAcked: 1,
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ var _ = Describe("Packet unpacker", func() {
|
|||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(HaveLen(1))
|
||||
readFrame := packet.frames[0].(*frames.AckFrame)
|
||||
readFrame := packet.frames[0].(*wire.AckFrame)
|
||||
Expect(readFrame).ToNot(BeNil())
|
||||
Expect(readFrame.LargestAcked).To(Equal(protocol.PacketNumber(0x13)))
|
||||
})
|
||||
|
@ -104,7 +104,7 @@ var _ = Describe("Packet unpacker", func() {
|
|||
})
|
||||
|
||||
It("handles PADDING between two other frames", func() {
|
||||
f := &frames.PingFrame{}
|
||||
f := &wire.PingFrame{}
|
||||
err := f.Write(buf, protocol.VersionWhatever)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = buf.Write(bytes.Repeat([]byte{0}, 10)) // 10 bytes PADDING
|
||||
|
@ -121,8 +121,8 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData([]byte{0x01, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE, 0x34, 0x12, 0x37, 0x13})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.RstStreamFrame{
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{
|
||||
&wire.RstStreamFrame{
|
||||
StreamID: 0xDEADBEEF,
|
||||
ByteOffset: 0xDECAFBAD11223344,
|
||||
ErrorCode: 0x13371234,
|
||||
|
@ -131,13 +131,13 @@ var _ = Describe("Packet unpacker", func() {
|
|||
})
|
||||
|
||||
It("unpacks CONNECTION_CLOSE frames", func() {
|
||||
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
f := &wire.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
err := f.Write(buf, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
setData(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{f}))
|
||||
})
|
||||
|
||||
It("accepts GOAWAY frames", func() {
|
||||
|
@ -150,8 +150,8 @@ var _ = Describe("Packet unpacker", func() {
|
|||
})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.GoawayFrame{
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{
|
||||
&wire.GoawayFrame{
|
||||
ErrorCode: 1,
|
||||
LastGoodStream: 2,
|
||||
ReasonPhrase: "foo",
|
||||
|
@ -163,8 +163,8 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData([]byte{0x04, 0xEF, 0xBE, 0xAD, 0xDE, 0x37, 0x13, 0, 0, 0, 0, 0xFE, 0xCA})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.WindowUpdateFrame{
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{
|
||||
&wire.WindowUpdateFrame{
|
||||
StreamID: 0xDEADBEEF,
|
||||
ByteOffset: 0xCAFE000000001337,
|
||||
},
|
||||
|
@ -175,10 +175,8 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData([]byte{0x05, 0xEF, 0xBE, 0xAD, 0xDE})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.BlockedFrame{
|
||||
StreamID: 0xDEADBEEF,
|
||||
},
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{
|
||||
&wire.BlockedFrame{StreamID: 0xDEADBEEF},
|
||||
}))
|
||||
})
|
||||
|
||||
|
@ -186,10 +184,8 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData([]byte{0x06, 0x03})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.StopWaitingFrame{
|
||||
LeastUnacked: 7,
|
||||
},
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{
|
||||
&wire.StopWaitingFrame{LeastUnacked: 7},
|
||||
}))
|
||||
})
|
||||
|
||||
|
@ -197,8 +193,8 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData([]byte{0x07})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.PingFrame{},
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{
|
||||
&wire.PingFrame{},
|
||||
}))
|
||||
})
|
||||
|
||||
|
@ -228,7 +224,7 @@ var _ = Describe("Packet unpacker", func() {
|
|||
Context("unpacking STREAM frames", func() {
|
||||
It("unpacks unencrypted STREAM frames on stream 1", func() {
|
||||
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -237,12 +233,12 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{f}))
|
||||
})
|
||||
|
||||
It("unpacks encrypted STREAM frames on stream 1", func() {
|
||||
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionSecure
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -251,12 +247,12 @@ var _ = Describe("Packet unpacker", func() {
|
|||
setData(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
Expect(packet.frames).To(Equal([]wire.Frame{f}))
|
||||
})
|
||||
|
||||
It("does not unpack unencrypted STREAM frames on higher streams", func() {
|
||||
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 3,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
|
52
session.go
52
session.go
|
@ -12,11 +12,11 @@ import (
|
|||
"github.com/lucas-clemente/quic-go/ackhandler"
|
||||
"github.com/lucas-clemente/quic-go/congestion"
|
||||
"github.com/lucas-clemente/quic-go/flowcontrol"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/handshake"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
type unpacker interface {
|
||||
|
@ -313,7 +313,7 @@ runLoop:
|
|||
|
||||
if s.config.KeepAlive && s.handshakeComplete && time.Since(s.lastNetworkActivityTime) >= s.idleTimeout()/2 {
|
||||
// send the PING frame since there is no activity in the session
|
||||
s.packer.QueueControlFrame(&frames.PingFrame{})
|
||||
s.packer.QueueControlFrame(&wire.PingFrame{})
|
||||
s.keepAlivePingSent = true
|
||||
}
|
||||
|
||||
|
@ -434,29 +434,29 @@ func (s *session) handlePacketImpl(p *receivedPacket) error {
|
|||
return s.handleFrames(packet.frames)
|
||||
}
|
||||
|
||||
func (s *session) handleFrames(fs []frames.Frame) error {
|
||||
func (s *session) handleFrames(fs []wire.Frame) error {
|
||||
for _, ff := range fs {
|
||||
var err error
|
||||
frames.LogFrame(ff, false)
|
||||
wire.LogFrame(ff, false)
|
||||
switch frame := ff.(type) {
|
||||
case *frames.StreamFrame:
|
||||
case *wire.StreamFrame:
|
||||
err = s.handleStreamFrame(frame)
|
||||
case *frames.AckFrame:
|
||||
case *wire.AckFrame:
|
||||
err = s.handleAckFrame(frame)
|
||||
case *frames.ConnectionCloseFrame:
|
||||
case *wire.ConnectionCloseFrame:
|
||||
s.closeRemote(qerr.Error(frame.ErrorCode, frame.ReasonPhrase))
|
||||
case *frames.GoawayFrame:
|
||||
case *wire.GoawayFrame:
|
||||
err = errors.New("unimplemented: handling GOAWAY frames")
|
||||
case *frames.StopWaitingFrame:
|
||||
case *wire.StopWaitingFrame:
|
||||
// LeastUnacked is guaranteed to have LeastUnacked > 0
|
||||
// therefore this will never underflow
|
||||
s.receivedPacketHandler.SetLowerLimit(frame.LeastUnacked - 1)
|
||||
case *frames.RstStreamFrame:
|
||||
case *wire.RstStreamFrame:
|
||||
err = s.handleRstStreamFrame(frame)
|
||||
case *frames.WindowUpdateFrame:
|
||||
case *wire.WindowUpdateFrame:
|
||||
err = s.handleWindowUpdateFrame(frame)
|
||||
case *frames.BlockedFrame:
|
||||
case *frames.PingFrame:
|
||||
case *wire.BlockedFrame:
|
||||
case *wire.PingFrame:
|
||||
default:
|
||||
return errors.New("Session BUG: unexpected frame type")
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ func (s *session) handlePacket(p *receivedPacket) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *session) handleStreamFrame(frame *frames.StreamFrame) error {
|
||||
func (s *session) handleStreamFrame(frame *wire.StreamFrame) error {
|
||||
str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -501,7 +501,7 @@ func (s *session) handleStreamFrame(frame *frames.StreamFrame) error {
|
|||
return str.AddStreamFrame(frame)
|
||||
}
|
||||
|
||||
func (s *session) handleWindowUpdateFrame(frame *frames.WindowUpdateFrame) error {
|
||||
func (s *session) handleWindowUpdateFrame(frame *wire.WindowUpdateFrame) error {
|
||||
if frame.StreamID != 0 {
|
||||
str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
|
||||
if err != nil {
|
||||
|
@ -515,7 +515,7 @@ func (s *session) handleWindowUpdateFrame(frame *frames.WindowUpdateFrame) error
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *session) handleRstStreamFrame(frame *frames.RstStreamFrame) error {
|
||||
func (s *session) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
||||
str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -528,7 +528,7 @@ func (s *session) handleRstStreamFrame(frame *frames.RstStreamFrame) error {
|
|||
return s.flowControlManager.ResetStream(frame.StreamID, frame.ByteOffset)
|
||||
}
|
||||
|
||||
func (s *session) handleAckFrame(frame *frames.AckFrame) error {
|
||||
func (s *session) handleAckFrame(frame *wire.AckFrame) error {
|
||||
return s.sentPacketHandler.ReceivedAck(frame, s.lastRcvdPacketNumber, s.lastNetworkActivityTime)
|
||||
}
|
||||
|
||||
|
@ -647,9 +647,9 @@ func (s *session) sendPacket() error {
|
|||
// resend the frames that were in the packet
|
||||
for _, frame := range retransmitPacket.GetFramesForRetransmission() {
|
||||
switch f := frame.(type) {
|
||||
case *frames.StreamFrame:
|
||||
case *wire.StreamFrame:
|
||||
s.streamFramer.AddFrameForRetransmission(f)
|
||||
case *frames.WindowUpdateFrame:
|
||||
case *wire.WindowUpdateFrame:
|
||||
// only retransmit WindowUpdates if the stream is not yet closed and the we haven't sent another WindowUpdate with a higher ByteOffset for the stream
|
||||
currentOffset, err := s.flowControlManager.GetReceiveWindow(f.StreamID)
|
||||
if err == nil && f.ByteOffset >= currentOffset {
|
||||
|
@ -671,7 +671,7 @@ func (s *session) sendPacket() error {
|
|||
}
|
||||
// add a retransmittable frame
|
||||
if s.sentPacketHandler.ShouldSendRetransmittablePacket() {
|
||||
s.packer.QueueControlFrame(&frames.PingFrame{})
|
||||
s.packer.QueueControlFrame(&wire.PingFrame{})
|
||||
}
|
||||
packet, err := s.packer.PackPacket()
|
||||
if err != nil || packet == nil {
|
||||
|
@ -707,7 +707,7 @@ func (s *session) sendPackedPacket(packet *packedPacket) error {
|
|||
|
||||
func (s *session) sendConnectionClose(quicErr *qerr.QuicError) error {
|
||||
s.packer.SetLeastUnacked(s.sentPacketHandler.GetLeastUnacked())
|
||||
packet, err := s.packer.PackConnectionClose(&frames.ConnectionCloseFrame{
|
||||
packet, err := s.packer.PackConnectionClose(&wire.ConnectionCloseFrame{
|
||||
ErrorCode: quicErr.ErrorCode,
|
||||
ReasonPhrase: quicErr.ErrorMessage,
|
||||
})
|
||||
|
@ -725,7 +725,7 @@ func (s *session) logPacket(packet *packedPacket) {
|
|||
}
|
||||
utils.Debugf("-> Sending packet 0x%x (%d bytes) for connection %x, %s", packet.number, len(packet.raw), s.connectionID, packet.encryptionLevel)
|
||||
for _, frame := range packet.frames {
|
||||
frames.LogFrame(frame, true)
|
||||
wire.LogFrame(frame, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -759,7 +759,7 @@ func (s *session) WaitUntilHandshakeComplete() error {
|
|||
}
|
||||
|
||||
func (s *session) queueResetStreamFrame(id protocol.StreamID, offset protocol.ByteCount) {
|
||||
s.packer.QueueControlFrame(&frames.RstStreamFrame{
|
||||
s.packer.QueueControlFrame(&wire.RstStreamFrame{
|
||||
StreamID: id,
|
||||
ByteOffset: offset,
|
||||
})
|
||||
|
@ -830,11 +830,11 @@ func (s *session) tryDecryptingQueuedPackets() {
|
|||
s.undecryptablePackets = s.undecryptablePackets[:0]
|
||||
}
|
||||
|
||||
func (s *session) getWindowUpdateFrames() []*frames.WindowUpdateFrame {
|
||||
func (s *session) getWindowUpdateFrames() []*wire.WindowUpdateFrame {
|
||||
updates := s.flowControlManager.GetWindowUpdates()
|
||||
res := make([]*frames.WindowUpdateFrame, len(updates))
|
||||
res := make([]*wire.WindowUpdateFrame, len(updates))
|
||||
for i, u := range updates {
|
||||
res[i] = &frames.WindowUpdateFrame{StreamID: u.StreamID, ByteOffset: u.Offset}
|
||||
res[i] = &wire.WindowUpdateFrame{StreamID: u.StreamID, ByteOffset: u.Offset}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
134
session_test.go
134
session_test.go
|
@ -16,13 +16,13 @@ import (
|
|||
|
||||
"github.com/lucas-clemente/quic-go/ackhandler"
|
||||
"github.com/lucas-clemente/quic-go/crypto"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/handshake"
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks"
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc"
|
||||
"github.com/lucas-clemente/quic-go/internal/testdata"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
type mockConnection struct {
|
||||
|
@ -83,7 +83,7 @@ func (h *mockSentPacketHandler) SentPacket(packet *ackhandler.Packet) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *mockSentPacketHandler) ReceivedAck(ackFrame *frames.AckFrame, withPacketNumber protocol.PacketNumber, recvTime time.Time) error {
|
||||
func (h *mockSentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumber protocol.PacketNumber, recvTime time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -97,9 +97,9 @@ func (h *mockSentPacketHandler) ShouldSendRetransmittablePacket() bool {
|
|||
return b
|
||||
}
|
||||
|
||||
func (h *mockSentPacketHandler) GetStopWaitingFrame(force bool) *frames.StopWaitingFrame {
|
||||
func (h *mockSentPacketHandler) GetStopWaitingFrame(force bool) *wire.StopWaitingFrame {
|
||||
h.requestedStopWaiting = true
|
||||
return &frames.StopWaitingFrame{LeastUnacked: 0x1337}
|
||||
return &wire.StopWaitingFrame{LeastUnacked: 0x1337}
|
||||
}
|
||||
|
||||
func (h *mockSentPacketHandler) DequeuePacketForRetransmission() *ackhandler.Packet {
|
||||
|
@ -118,11 +118,11 @@ func newMockSentPacketHandler() ackhandler.SentPacketHandler {
|
|||
var _ ackhandler.SentPacketHandler = &mockSentPacketHandler{}
|
||||
|
||||
type mockReceivedPacketHandler struct {
|
||||
nextAckFrame *frames.AckFrame
|
||||
nextAckFrame *wire.AckFrame
|
||||
ackAlarm time.Time
|
||||
}
|
||||
|
||||
func (m *mockReceivedPacketHandler) GetAckFrame() *frames.AckFrame {
|
||||
func (m *mockReceivedPacketHandler) GetAckFrame() *wire.AckFrame {
|
||||
f := m.nextAckFrame
|
||||
m.nextAckFrame = nil
|
||||
return f
|
||||
|
@ -263,7 +263,7 @@ var _ = Describe("Session", func() {
|
|||
|
||||
Context("when handling stream frames", func() {
|
||||
It("makes new streams", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
})
|
||||
|
@ -279,7 +279,7 @@ var _ = Describe("Session", func() {
|
|||
It("does not reject existing streams with even StreamIDs", func() {
|
||||
_, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = sess.handleStreamFrame(&frames.StreamFrame{
|
||||
err = sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
})
|
||||
|
@ -287,12 +287,12 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("handles existing streams", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca},
|
||||
})
|
||||
numOpenStreams := len(sess.streamsMap.openStreams)
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 2,
|
||||
Data: []byte{0xfb, 0xad},
|
||||
|
@ -317,7 +317,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("does not delete streams with FIN bit", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
FinBit: true,
|
||||
|
@ -336,7 +336,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("deletes streams with FIN bit & close", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
FinBit: true,
|
||||
|
@ -369,7 +369,7 @@ var _ = Describe("Session", func() {
|
|||
It("cancels streams with error", func() {
|
||||
sess.garbageCollectStreams()
|
||||
testErr := errors.New("test")
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
})
|
||||
|
@ -413,7 +413,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("ignores STREAM frames for closed streams (client-side)", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
FinBit: true,
|
||||
})
|
||||
|
@ -426,7 +426,7 @@ var _ = Describe("Session", func() {
|
|||
sess.garbageCollectStreams()
|
||||
str, _ = sess.streamsMap.GetOrOpenStream(5)
|
||||
Expect(str).To(BeNil()) // make sure the stream is gone
|
||||
err = sess.handleStreamFrame(&frames.StreamFrame{
|
||||
err = sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
|
@ -437,7 +437,7 @@ var _ = Describe("Session", func() {
|
|||
ostr, err := sess.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(ostr.StreamID()).To(Equal(protocol.StreamID(2)))
|
||||
err = sess.handleStreamFrame(&frames.StreamFrame{
|
||||
err = sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 2,
|
||||
FinBit: true,
|
||||
})
|
||||
|
@ -451,7 +451,7 @@ var _ = Describe("Session", func() {
|
|||
sess.garbageCollectStreams()
|
||||
str, _ = sess.streamsMap.GetOrOpenStream(2)
|
||||
Expect(str).To(BeNil()) // make sure the stream is gone
|
||||
err = sess.handleStreamFrame(&frames.StreamFrame{
|
||||
err = sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 2,
|
||||
FinBit: true,
|
||||
})
|
||||
|
@ -463,7 +463,7 @@ var _ = Describe("Session", func() {
|
|||
It("closes the streams for writing", func() {
|
||||
s, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ErrorCode: 42,
|
||||
})
|
||||
|
@ -476,11 +476,11 @@ var _ = Describe("Session", func() {
|
|||
It("doesn't close the stream for reading", func() {
|
||||
s, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ErrorCode: 42,
|
||||
ByteOffset: 6,
|
||||
|
@ -496,12 +496,12 @@ var _ = Describe("Session", func() {
|
|||
str, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*stream).writeOffset = 0x1337
|
||||
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(sess.packer.controlFrames).To(HaveLen(1))
|
||||
Expect(sess.packer.controlFrames[0].(*frames.RstStreamFrame)).To(Equal(&frames.RstStreamFrame{
|
||||
Expect(sess.packer.controlFrames[0].(*wire.RstStreamFrame)).To(Equal(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1337,
|
||||
}))
|
||||
|
@ -513,7 +513,7 @@ var _ = Describe("Session", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
str.(*stream).sentFin()
|
||||
str.Close()
|
||||
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -526,7 +526,7 @@ var _ = Describe("Session", func() {
|
|||
fcm := mocks_fc.NewMockFlowControlManager(mockCtrl)
|
||||
sess.flowControlManager = fcm
|
||||
fcm.EXPECT().ResetStream(protocol.StreamID(5), protocol.ByteCount(0x1337))
|
||||
err := sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err := sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1337,
|
||||
})
|
||||
|
@ -539,7 +539,7 @@ var _ = Describe("Session", func() {
|
|||
fcm := mocks_fc.NewMockFlowControlManager(mockCtrl)
|
||||
sess.flowControlManager = fcm
|
||||
fcm.EXPECT().ResetStream(protocol.StreamID(5), protocol.ByteCount(0x1337)).Return(testErr)
|
||||
err := sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err := sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1337,
|
||||
})
|
||||
|
@ -547,7 +547,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("ignores the error when the stream is not known", func() {
|
||||
err := sess.handleFrames([]frames.Frame{&frames.RstStreamFrame{
|
||||
err := sess.handleFrames([]wire.Frame{&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ErrorCode: 42,
|
||||
}})
|
||||
|
@ -561,7 +561,7 @@ var _ = Describe("Session", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
str.Reset(testErr)
|
||||
Expect(sess.packer.controlFrames).To(HaveLen(1))
|
||||
Expect(sess.packer.controlFrames[0]).To(Equal(&frames.RstStreamFrame{
|
||||
Expect(sess.packer.controlFrames[0]).To(Equal(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1337,
|
||||
}))
|
||||
|
@ -574,7 +574,7 @@ var _ = Describe("Session", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
str.Reset(testErr)
|
||||
Expect(sess.packer.controlFrames).To(HaveLen(1))
|
||||
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{
|
||||
err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x42,
|
||||
})
|
||||
|
@ -587,7 +587,7 @@ var _ = Describe("Session", func() {
|
|||
It("updates the Flow Control Window of a stream", func() {
|
||||
_, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{
|
||||
err = sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 100,
|
||||
})
|
||||
|
@ -596,7 +596,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("updates the Flow Control Window of the connection", func() {
|
||||
err := sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{
|
||||
err := sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
|
||||
StreamID: 0,
|
||||
ByteOffset: 0x800000,
|
||||
})
|
||||
|
@ -604,7 +604,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("opens a new stream when receiving a WINDOW_UPDATE for an unknown stream", func() {
|
||||
err := sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{
|
||||
err := sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 1337,
|
||||
})
|
||||
|
@ -615,11 +615,11 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("errors when receiving a WindowUpdateFrame for a closed stream", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{StreamID: 5})
|
||||
sess.handleStreamFrame(&wire.StreamFrame{StreamID: 5})
|
||||
err := sess.streamsMap.RemoveStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
sess.garbageCollectStreams()
|
||||
err = sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{
|
||||
err = sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 1337,
|
||||
})
|
||||
|
@ -627,11 +627,11 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("ignores errors when receiving a WindowUpdateFrame for a closed stream", func() {
|
||||
sess.handleStreamFrame(&frames.StreamFrame{StreamID: 5})
|
||||
sess.handleStreamFrame(&wire.StreamFrame{StreamID: 5})
|
||||
err := sess.streamsMap.RemoveStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
sess.garbageCollectStreams()
|
||||
err = sess.handleFrames([]frames.Frame{&frames.WindowUpdateFrame{
|
||||
err = sess.handleFrames([]wire.Frame{&wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 1337,
|
||||
}})
|
||||
|
@ -640,29 +640,29 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("handles PING frames", func() {
|
||||
err := sess.handleFrames([]frames.Frame{&frames.PingFrame{}})
|
||||
err := sess.handleFrames([]wire.Frame{&wire.PingFrame{}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("handles BLOCKED frames", func() {
|
||||
err := sess.handleFrames([]frames.Frame{&frames.BlockedFrame{}})
|
||||
err := sess.handleFrames([]wire.Frame{&wire.BlockedFrame{}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("errors on GOAWAY frames", func() {
|
||||
err := sess.handleFrames([]frames.Frame{&frames.GoawayFrame{}})
|
||||
err := sess.handleFrames([]wire.Frame{&wire.GoawayFrame{}})
|
||||
Expect(err).To(MatchError("unimplemented: handling GOAWAY frames"))
|
||||
})
|
||||
|
||||
It("handles STOP_WAITING frames", func() {
|
||||
err := sess.handleFrames([]frames.Frame{&frames.StopWaitingFrame{LeastUnacked: 10}})
|
||||
err := sess.handleFrames([]wire.Frame{&wire.StopWaitingFrame{LeastUnacked: 10}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("handles CONNECTION_CLOSE frames", func(done Done) {
|
||||
go sess.run()
|
||||
str, _ := sess.GetOrOpenStream(5)
|
||||
err := sess.handleFrames([]frames.Frame{&frames.ConnectionCloseFrame{ErrorCode: 42, ReasonPhrase: "foobar"}})
|
||||
err := sess.handleFrames([]wire.Frame{&wire.ConnectionCloseFrame{ErrorCode: 42, ReasonPhrase: "foobar"}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Eventually(sess.Context().Done()).Should(BeClosed())
|
||||
_, err = str.Read([]byte{0})
|
||||
|
@ -738,7 +738,7 @@ var _ = Describe("Session", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
}()
|
||||
Consistently(func() Stream { return str }).Should(BeNil())
|
||||
sess.handleStreamFrame(&frames.StreamFrame{
|
||||
sess.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: 3,
|
||||
})
|
||||
Eventually(func() Stream { return str }).ShouldNot(BeNil())
|
||||
|
@ -969,7 +969,7 @@ var _ = Describe("Session", func() {
|
|||
err := sess.sendPacket()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mconn.written).To(HaveLen(1))
|
||||
Expect(sess.sentPacketHandler.(*mockSentPacketHandler).sentPackets[0].Frames).To(ContainElement(&frames.PingFrame{}))
|
||||
Expect(sess.sentPacketHandler.(*mockSentPacketHandler).sentPackets[0].Frames).To(ContainElement(&wire.PingFrame{}))
|
||||
})
|
||||
|
||||
It("sends two WindowUpdate frames", func() {
|
||||
|
@ -999,7 +999,7 @@ var _ = Describe("Session", func() {
|
|||
sess.packer.packetNumberGenerator.next = 0x1337 + 9
|
||||
sess.packer.cryptoSetup = &mockCryptoSetup{encLevelSeal: protocol.EncryptionForwardSecure}
|
||||
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -1030,9 +1030,9 @@ var _ = Describe("Session", func() {
|
|||
|
||||
Context("for handshake packets", func() {
|
||||
It("retransmits an unencrypted packet", func() {
|
||||
sf := &frames.StreamFrame{StreamID: 1, Data: []byte("foobar")}
|
||||
sf := &wire.StreamFrame{StreamID: 1, Data: []byte("foobar")}
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{{
|
||||
Frames: []frames.Frame{sf},
|
||||
Frames: []wire.Frame{sf},
|
||||
EncryptionLevel: protocol.EncryptionUnencrypted,
|
||||
}}
|
||||
err := sess.sendPacket()
|
||||
|
@ -1043,14 +1043,14 @@ var _ = Describe("Session", func() {
|
|||
Expect(sentPackets[0].EncryptionLevel).To(Equal(protocol.EncryptionUnencrypted))
|
||||
Expect(sentPackets[0].Frames).To(HaveLen(2))
|
||||
Expect(sentPackets[0].Frames[1]).To(Equal(sf))
|
||||
swf := sentPackets[0].Frames[0].(*frames.StopWaitingFrame)
|
||||
swf := sentPackets[0].Frames[0].(*wire.StopWaitingFrame)
|
||||
Expect(swf.LeastUnacked).To(Equal(protocol.PacketNumber(0x1337)))
|
||||
})
|
||||
|
||||
It("retransmit a packet encrypted with the initial encryption", func() {
|
||||
sf := &frames.StreamFrame{StreamID: 1, Data: []byte("foobar")}
|
||||
sf := &wire.StreamFrame{StreamID: 1, Data: []byte("foobar")}
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{{
|
||||
Frames: []frames.Frame{sf},
|
||||
Frames: []wire.Frame{sf},
|
||||
EncryptionLevel: protocol.EncryptionSecure,
|
||||
}}
|
||||
err := sess.sendPacket()
|
||||
|
@ -1065,9 +1065,9 @@ var _ = Describe("Session", func() {
|
|||
|
||||
It("doesn't retransmit handshake packets when the handshake is complete", func() {
|
||||
sess.handshakeComplete = true
|
||||
sf := &frames.StreamFrame{StreamID: 1, Data: []byte("foobar")}
|
||||
sf := &wire.StreamFrame{StreamID: 1, Data: []byte("foobar")}
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{{
|
||||
Frames: []frames.Frame{sf},
|
||||
Frames: []wire.Frame{sf},
|
||||
EncryptionLevel: protocol.EncryptionSecure,
|
||||
}}
|
||||
err := sess.sendPacket()
|
||||
|
@ -1078,13 +1078,13 @@ var _ = Describe("Session", func() {
|
|||
|
||||
Context("for packets after the handshake", func() {
|
||||
It("sends a StreamFrame from a packet queued for retransmission", func() {
|
||||
f := frames.StreamFrame{
|
||||
f := wire.StreamFrame{
|
||||
StreamID: 0x5,
|
||||
Data: []byte("foobar1234567"),
|
||||
}
|
||||
p := ackhandler.Packet{
|
||||
PacketNumber: 0x1337,
|
||||
Frames: []frames.Frame{&f},
|
||||
Frames: []wire.Frame{&f},
|
||||
EncryptionLevel: protocol.EncryptionForwardSecure,
|
||||
}
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{&p}
|
||||
|
@ -1097,22 +1097,22 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("sends a StreamFrame from a packet queued for retransmission", func() {
|
||||
f1 := frames.StreamFrame{
|
||||
f1 := wire.StreamFrame{
|
||||
StreamID: 0x5,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
f2 := frames.StreamFrame{
|
||||
f2 := wire.StreamFrame{
|
||||
StreamID: 0x7,
|
||||
Data: []byte("loremipsum"),
|
||||
}
|
||||
p1 := ackhandler.Packet{
|
||||
PacketNumber: 0x1337,
|
||||
Frames: []frames.Frame{&f1},
|
||||
Frames: []wire.Frame{&f1},
|
||||
EncryptionLevel: protocol.EncryptionForwardSecure,
|
||||
}
|
||||
p2 := ackhandler.Packet{
|
||||
PacketNumber: 0x1338,
|
||||
Frames: []frames.Frame{&f2},
|
||||
Frames: []wire.Frame{&f2},
|
||||
EncryptionLevel: protocol.EncryptionForwardSecure,
|
||||
}
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{&p1, &p2}
|
||||
|
@ -1126,7 +1126,7 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
It("always attaches a StopWaiting to a packet that contains a retransmission", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 0x5,
|
||||
Data: bytes.Repeat([]byte{'f'}, int(1.5*float32(protocol.MaxPacketSize))),
|
||||
}
|
||||
|
@ -1137,9 +1137,9 @@ var _ = Describe("Session", func() {
|
|||
Expect(mconn.written).To(HaveLen(2))
|
||||
sentPackets := sph.sentPackets
|
||||
Expect(sentPackets).To(HaveLen(2))
|
||||
_, ok := sentPackets[0].Frames[0].(*frames.StopWaitingFrame)
|
||||
_, ok := sentPackets[0].Frames[0].(*wire.StopWaitingFrame)
|
||||
Expect(ok).To(BeTrue())
|
||||
_, ok = sentPackets[1].Frames[0].(*frames.StopWaitingFrame)
|
||||
_, ok = sentPackets[1].Frames[0].(*wire.StopWaitingFrame)
|
||||
Expect(ok).To(BeTrue())
|
||||
})
|
||||
|
||||
|
@ -1150,12 +1150,12 @@ var _ = Describe("Session", func() {
|
|||
sess.flowControlManager = fcm
|
||||
fcm.EXPECT().GetWindowUpdates()
|
||||
fcm.EXPECT().GetReceiveWindow(protocol.StreamID(5)).Return(protocol.ByteCount(0x1000), nil)
|
||||
wuf := &frames.WindowUpdateFrame{
|
||||
wuf := &wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1000,
|
||||
}
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{{
|
||||
Frames: []frames.Frame{wuf},
|
||||
Frames: []wire.Frame{wuf},
|
||||
EncryptionLevel: protocol.EncryptionForwardSecure,
|
||||
}}
|
||||
err = sess.sendPacket()
|
||||
|
@ -1172,7 +1172,7 @@ var _ = Describe("Session", func() {
|
|||
fcm.EXPECT().GetWindowUpdates()
|
||||
fcm.EXPECT().GetReceiveWindow(protocol.StreamID(5)).Return(protocol.ByteCount(0x2000), nil)
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{{
|
||||
Frames: []frames.Frame{&frames.WindowUpdateFrame{
|
||||
Frames: []wire.Frame{&wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1000,
|
||||
}},
|
||||
|
@ -1194,7 +1194,7 @@ var _ = Describe("Session", func() {
|
|||
_, err = sess.flowControlManager.SendWindowSize(5)
|
||||
Expect(err).To(MatchError("Error accessing the flowController map."))
|
||||
sph.retransmissionQueue = []*ackhandler.Packet{{
|
||||
Frames: []frames.Frame{&frames.WindowUpdateFrame{
|
||||
Frames: []wire.Frame{&wire.WindowUpdateFrame{
|
||||
StreamID: 5,
|
||||
ByteOffset: 0x1337,
|
||||
}},
|
||||
|
@ -1219,7 +1219,7 @@ var _ = Describe("Session", func() {
|
|||
err := sess.sentPacketHandler.SentPacket(&ackhandler.Packet{
|
||||
PacketNumber: n,
|
||||
Length: 1,
|
||||
Frames: []frames.Frame{&frames.StreamFrame{
|
||||
Frames: []wire.Frame{&wire.StreamFrame{
|
||||
Data: []byte("foobar"),
|
||||
}},
|
||||
EncryptionLevel: protocol.EncryptionForwardSecure,
|
||||
|
@ -1251,7 +1251,7 @@ var _ = Describe("Session", func() {
|
|||
|
||||
It("sets the timer to the ack timer", func() {
|
||||
rph := &mockReceivedPacketHandler{ackAlarm: time.Now().Add(10 * time.Millisecond)}
|
||||
rph.nextAckFrame = &frames.AckFrame{LargestAcked: 0x1337}
|
||||
rph.nextAckFrame = &wire.AckFrame{LargestAcked: 0x1337}
|
||||
sess.receivedPacketHandler = rph
|
||||
go sess.run()
|
||||
defer sess.Close(nil)
|
||||
|
@ -1628,11 +1628,11 @@ var _ = Describe("Session", func() {
|
|||
PacketNumber: 1,
|
||||
Length: 1,
|
||||
})
|
||||
err := sess.handleFrames([]frames.Frame{&frames.AckFrame{
|
||||
err := sess.handleFrames([]wire.Frame{&wire.AckFrame{
|
||||
LargestAcked: 1,
|
||||
}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = sess.handleFrames([]frames.Frame{&frames.AckFrame{
|
||||
err = sess.handleFrames([]wire.Frame{&wire.AckFrame{
|
||||
LargestAcked: 1,
|
||||
}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/flowcontrol"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
// A Stream assembles the data from StreamFrames and provides a super-convenient Read-Interface
|
||||
|
@ -289,7 +289,7 @@ func (s *stream) sentFin() {
|
|||
}
|
||||
|
||||
// AddStreamFrame adds a new stream frame
|
||||
func (s *stream) AddStreamFrame(frame *frames.StreamFrame) error {
|
||||
func (s *stream) AddStreamFrame(frame *wire.StreamFrame) error {
|
||||
maxOffset := frame.Offset + frame.DataLen()
|
||||
err := s.flowControlManager.UpdateHighestReceived(s.streamID, maxOffset)
|
||||
if err != nil {
|
||||
|
@ -353,7 +353,7 @@ func (s *stream) SetDeadline(t time.Time) error {
|
|||
|
||||
// CloseRemote makes the stream receive a "virtual" FIN stream frame at a given offset
|
||||
func (s *stream) CloseRemote(offset protocol.ByteCount) {
|
||||
s.AddStreamFrame(&frames.StreamFrame{FinBit: true, Offset: offset})
|
||||
s.AddStreamFrame(&wire.StreamFrame{FinBit: true, Offset: offset})
|
||||
}
|
||||
|
||||
// Cancel is called by session to indicate that an error occurred
|
||||
|
|
|
@ -3,13 +3,13 @@ package quic
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
type streamFrameSorter struct {
|
||||
queuedFrames map[protocol.ByteCount]*frames.StreamFrame
|
||||
queuedFrames map[protocol.ByteCount]*wire.StreamFrame
|
||||
readPosition protocol.ByteCount
|
||||
gaps *utils.ByteIntervalList
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ var (
|
|||
func newStreamFrameSorter() *streamFrameSorter {
|
||||
s := streamFrameSorter{
|
||||
gaps: utils.NewByteIntervalList(),
|
||||
queuedFrames: make(map[protocol.ByteCount]*frames.StreamFrame),
|
||||
queuedFrames: make(map[protocol.ByteCount]*wire.StreamFrame),
|
||||
}
|
||||
s.gaps.PushFront(utils.ByteInterval{Start: 0, End: protocol.MaxByteCount})
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s *streamFrameSorter) Push(frame *frames.StreamFrame) error {
|
||||
func (s *streamFrameSorter) Push(frame *wire.StreamFrame) error {
|
||||
if frame.DataLen() == 0 {
|
||||
if frame.FinBit {
|
||||
s.queuedFrames[frame.Offset] = frame
|
||||
|
@ -143,7 +143,7 @@ func (s *streamFrameSorter) Push(frame *frames.StreamFrame) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *streamFrameSorter) Pop() *frames.StreamFrame {
|
||||
func (s *streamFrameSorter) Pop() *wire.StreamFrame {
|
||||
frame := s.Head()
|
||||
if frame != nil {
|
||||
s.readPosition += frame.DataLen()
|
||||
|
@ -152,7 +152,7 @@ func (s *streamFrameSorter) Pop() *frames.StreamFrame {
|
|||
return frame
|
||||
}
|
||||
|
||||
func (s *streamFrameSorter) Head() *frames.StreamFrame {
|
||||
func (s *streamFrameSorter) Head() *wire.StreamFrame {
|
||||
frame, ok := s.queuedFrames[s.readPosition]
|
||||
if ok {
|
||||
return frame
|
||||
|
|
|
@ -3,9 +3,9 @@ package quic
|
|||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
Context("Push", func() {
|
||||
It("inserts and pops a single frame", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("inserts and pops two consecutive frame", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 6,
|
||||
Data: []byte("foobar2"),
|
||||
}
|
||||
|
@ -62,14 +62,14 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("rejects empty frames", func() {
|
||||
f := &frames.StreamFrame{}
|
||||
f := &wire.StreamFrame{}
|
||||
err := s.Push(f)
|
||||
Expect(err).To(MatchError(errEmptyStreamData))
|
||||
})
|
||||
|
||||
Context("FinBit handling", func() {
|
||||
It("saves a FinBit frame at offset 0", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
FinBit: true,
|
||||
}
|
||||
|
@ -79,13 +79,13 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("sets the FinBit if a stream is closed after receiving some data", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 6,
|
||||
FinBit: true,
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
Context("Gap handling", func() {
|
||||
It("finds the first gap", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("correctly sets the first gap for a frame with offset 0", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -123,13 +123,13 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("finds the two gaps", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 20,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -143,13 +143,13 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("finds the two gaps in reverse order", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 20,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -163,13 +163,13 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("shrinks a gap when it is partially filled", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("test"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 4,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -182,13 +182,13 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("deletes a gap at the beginning, when it is filled", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 6,
|
||||
Data: []byte("test"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -200,19 +200,19 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("deletes a gap in the middle, when it is filled", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("test"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("test2"),
|
||||
}
|
||||
err = s.Push(f2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f3 := &frames.StreamFrame{
|
||||
f3 := &wire.StreamFrame{
|
||||
Offset: 4,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -225,13 +225,13 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("splits a gap into two", func() {
|
||||
f1 := &frames.StreamFrame{
|
||||
f1 := &wire.StreamFrame{
|
||||
Offset: 100,
|
||||
Data: []byte("test"),
|
||||
}
|
||||
err := s.Push(f1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f2 := &frames.StreamFrame{
|
||||
f2 := &wire.StreamFrame{
|
||||
Offset: 50,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -248,11 +248,11 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
Context("Overlapping Stream Data detection", func() {
|
||||
// create gaps: 0-5, 10-15, 20-25, 30-inf
|
||||
BeforeEach(func() {
|
||||
err := s.Push(&frames.StreamFrame{Offset: 5, Data: []byte("12345")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 5, Data: []byte("12345")})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = s.Push(&frames.StreamFrame{Offset: 15, Data: []byte("12345")})
|
||||
err = s.Push(&wire.StreamFrame{Offset: 15, Data: []byte("12345")})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = s.Push(&frames.StreamFrame{Offset: 25, Data: []byte("12345")})
|
||||
err = s.Push(&wire.StreamFrame{Offset: 25, Data: []byte("12345")})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
checkGaps([]utils.ByteInterval{
|
||||
{Start: 0, End: 5},
|
||||
|
@ -263,7 +263,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("cuts a frame with offset 0 that overlaps at the end", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("cuts a frame that overlaps at the end", func() {
|
||||
// 4 to 7
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 4,
|
||||
Data: []byte("foo"),
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("cuts a frame that completely fills a gap, but overlaps at the end", func() {
|
||||
// 10 to 16
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("cuts a frame that overlaps at the beginning", func() {
|
||||
// 8 to 14
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 8,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that overlaps at the beginning and at the end, starting in a gap", func() {
|
||||
// 2 to 12
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte("1234567890"),
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that overlaps at the beginning and at the end, starting in a gap, ending in data", func() {
|
||||
// 2 to 17
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte("123456789012345"),
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that overlaps at the beginning and at the end, starting in a gap, ending in data", func() {
|
||||
// 5 to 22
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 5,
|
||||
Data: []byte("12345678901234567"),
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that closes multiple gaps", func() {
|
||||
// 2 to 27
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: bytes.Repeat([]byte{'e'}, 25),
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that closes multiple gaps", func() {
|
||||
// 5 to 27
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 5,
|
||||
Data: bytes.Repeat([]byte{'d'}, 22),
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that covers multiple gaps and ends at the end of a gap", func() {
|
||||
// 1 to 15
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 1,
|
||||
Data: bytes.Repeat([]byte{'f'}, 14),
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("processes a frame that closes all gaps (except for the last one)", func() {
|
||||
// 0 to 32
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: bytes.Repeat([]byte{'f'}, 32),
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("cuts a frame that overlaps at the beginning and at the end, starting in data already received", func() {
|
||||
// 8 to 17
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 8,
|
||||
Data: []byte("123456789"),
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("cuts a frame that completely covers two gaps", func() {
|
||||
// 10 to 20
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Offset: 10,
|
||||
Data: []byte("1234567890"),
|
||||
}
|
||||
|
@ -513,9 +513,9 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
// create gaps: 5-10, 15-inf
|
||||
err := s.Push(&frames.StreamFrame{Offset: 0, Data: []byte("12345")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 0, Data: []byte("12345")})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = s.Push(&frames.StreamFrame{Offset: 10, Data: []byte("12345")})
|
||||
err = s.Push(&wire.StreamFrame{Offset: 10, Data: []byte("12345")})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
checkGaps(expectedGaps)
|
||||
})
|
||||
|
@ -526,21 +526,21 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
})
|
||||
|
||||
It("does not modify data when receiving a duplicate", func() {
|
||||
err := s.Push(&frames.StreamFrame{Offset: 0, Data: []byte("fffff")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 0, Data: []byte("fffff")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[0].Data).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(&frames.StreamFrame{Offset: 10, Data: []byte("12")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 10, Data: []byte("12")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[10].Data).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(&frames.StreamFrame{Offset: 1, Data: []byte("123")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 1, Data: []byte("123")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[0].Data).To(HaveLen(5))
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(1)))
|
||||
|
@ -548,7 +548,7 @@ var _ = Describe("StreamFrame 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(&frames.StreamFrame{Offset: 11, Data: []byte("123")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 11, Data: []byte("123")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[10].Data).To(HaveLen(5))
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(11)))
|
||||
|
@ -556,7 +556,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("detects a duplicate frame that is smaller than the original, with aligned end in the last block", func() {
|
||||
// 11 to 14
|
||||
err := s.Push(&frames.StreamFrame{Offset: 11, Data: []byte("1234")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 11, Data: []byte("1234")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[10].Data).To(HaveLen(5))
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(11)))
|
||||
|
@ -564,7 +564,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
|
||||
It("detects a duplicate frame that is smaller than the original, with aligned end", func() {
|
||||
// 3 to 5
|
||||
err := s.Push(&frames.StreamFrame{Offset: 3, Data: []byte("12")})
|
||||
err := s.Push(&wire.StreamFrame{Offset: 3, Data: []byte("12")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[0].Data).To(HaveLen(5))
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(3)))
|
||||
|
@ -574,7 +574,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
Context("DoS protection", func() {
|
||||
It("errors when too many gaps are created", func() {
|
||||
for i := 0; i < protocol.MaxStreamFrameSorterGaps; i++ {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Data: []byte("foobar"),
|
||||
Offset: protocol.ByteCount(i * 7),
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
Expect(s.gaps.Len()).To(Equal(protocol.MaxStreamFrameSorterGaps))
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
Data: []byte("foobar"),
|
||||
Offset: protocol.ByteCount(protocol.MaxStreamFrameSorterGaps*7) + 100,
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package quic
|
|||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/flowcontrol"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
)
|
||||
|
||||
type streamFramer struct {
|
||||
|
@ -12,8 +12,8 @@ type streamFramer struct {
|
|||
|
||||
flowControlManager flowcontrol.FlowControlManager
|
||||
|
||||
retransmissionQueue []*frames.StreamFrame
|
||||
blockedFrameQueue []*frames.BlockedFrame
|
||||
retransmissionQueue []*wire.StreamFrame
|
||||
blockedFrameQueue []*wire.BlockedFrame
|
||||
}
|
||||
|
||||
func newStreamFramer(streamsMap *streamsMap, flowControlManager flowcontrol.FlowControlManager) *streamFramer {
|
||||
|
@ -23,16 +23,16 @@ func newStreamFramer(streamsMap *streamsMap, flowControlManager flowcontrol.Flow
|
|||
}
|
||||
}
|
||||
|
||||
func (f *streamFramer) AddFrameForRetransmission(frame *frames.StreamFrame) {
|
||||
func (f *streamFramer) AddFrameForRetransmission(frame *wire.StreamFrame) {
|
||||
f.retransmissionQueue = append(f.retransmissionQueue, frame)
|
||||
}
|
||||
|
||||
func (f *streamFramer) PopStreamFrames(maxLen protocol.ByteCount) []*frames.StreamFrame {
|
||||
func (f *streamFramer) PopStreamFrames(maxLen protocol.ByteCount) []*wire.StreamFrame {
|
||||
fs, currentLen := f.maybePopFramesForRetransmission(maxLen)
|
||||
return append(fs, f.maybePopNormalFrames(maxLen-currentLen)...)
|
||||
}
|
||||
|
||||
func (f *streamFramer) PopBlockedFrame() *frames.BlockedFrame {
|
||||
func (f *streamFramer) PopBlockedFrame() *wire.BlockedFrame {
|
||||
if len(f.blockedFrameQueue) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -53,12 +53,12 @@ func (f *streamFramer) HasCryptoStreamFrame() bool {
|
|||
|
||||
// TODO(lclemente): This is somewhat duplicate with the normal path for generating frames.
|
||||
// TODO(#657): Flow control
|
||||
func (f *streamFramer) PopCryptoStreamFrame(maxLen protocol.ByteCount) *frames.StreamFrame {
|
||||
func (f *streamFramer) PopCryptoStreamFrame(maxLen protocol.ByteCount) *wire.StreamFrame {
|
||||
if !f.HasCryptoStreamFrame() {
|
||||
return nil
|
||||
}
|
||||
cs, _ := f.streamsMap.GetOrOpenStream(1)
|
||||
frame := &frames.StreamFrame{
|
||||
frame := &wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Offset: cs.writeOffset,
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func (f *streamFramer) PopCryptoStreamFrame(maxLen protocol.ByteCount) *frames.S
|
|||
return frame
|
||||
}
|
||||
|
||||
func (f *streamFramer) maybePopFramesForRetransmission(maxLen protocol.ByteCount) (res []*frames.StreamFrame, currentLen protocol.ByteCount) {
|
||||
func (f *streamFramer) maybePopFramesForRetransmission(maxLen protocol.ByteCount) (res []*wire.StreamFrame, currentLen protocol.ByteCount) {
|
||||
for len(f.retransmissionQueue) > 0 {
|
||||
frame := f.retransmissionQueue[0]
|
||||
frame.DataLenPresent = true
|
||||
|
@ -93,8 +93,8 @@ func (f *streamFramer) maybePopFramesForRetransmission(maxLen protocol.ByteCount
|
|||
return
|
||||
}
|
||||
|
||||
func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []*frames.StreamFrame) {
|
||||
frame := &frames.StreamFrame{DataLenPresent: true}
|
||||
func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []*wire.StreamFrame) {
|
||||
frame := &wire.StreamFrame{DataLenPresent: true}
|
||||
var currentLen protocol.ByteCount
|
||||
|
||||
fn := func(s *stream) (bool, error) {
|
||||
|
@ -146,10 +146,10 @@ func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []
|
|||
// Finally, check if we are now FC blocked and should queue a BLOCKED frame
|
||||
if f.flowControlManager.RemainingConnectionWindowSize() == 0 {
|
||||
// We are now connection-level FC blocked
|
||||
f.blockedFrameQueue = append(f.blockedFrameQueue, &frames.BlockedFrame{StreamID: 0})
|
||||
f.blockedFrameQueue = append(f.blockedFrameQueue, &wire.BlockedFrame{StreamID: 0})
|
||||
} else if !frame.FinBit && sendWindowSize-frame.DataLen() == 0 {
|
||||
// We are now stream-level FC blocked
|
||||
f.blockedFrameQueue = append(f.blockedFrameQueue, &frames.BlockedFrame{StreamID: s.StreamID()})
|
||||
f.blockedFrameQueue = append(f.blockedFrameQueue, &wire.BlockedFrame{StreamID: s.StreamID()})
|
||||
}
|
||||
|
||||
res = append(res, frame)
|
||||
|
@ -159,7 +159,7 @@ func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []
|
|||
return false, nil
|
||||
}
|
||||
|
||||
frame = &frames.StreamFrame{DataLenPresent: true}
|
||||
frame = &wire.StreamFrame{DataLenPresent: true}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []
|
|||
}
|
||||
|
||||
// maybeSplitOffFrame removes the first n bytes and returns them as a separate frame. If n >= len(frame), nil is returned and nothing is modified.
|
||||
func maybeSplitOffFrame(frame *frames.StreamFrame, n protocol.ByteCount) *frames.StreamFrame {
|
||||
func maybeSplitOffFrame(frame *wire.StreamFrame, n protocol.ByteCount) *wire.StreamFrame {
|
||||
if n >= frame.DataLen() {
|
||||
return nil
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ func maybeSplitOffFrame(frame *frames.StreamFrame, n protocol.ByteCount) *frames
|
|||
frame.Offset += n
|
||||
}()
|
||||
|
||||
return &frames.StreamFrame{
|
||||
return &wire.StreamFrame{
|
||||
FinBit: false,
|
||||
StreamID: frame.StreamID,
|
||||
Offset: frame.Offset,
|
||||
|
|
|
@ -3,9 +3,9 @@ package quic
|
|||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
)
|
||||
|
||||
var (
|
||||
retransmittedFrame1, retransmittedFrame2 *frames.StreamFrame
|
||||
retransmittedFrame1, retransmittedFrame2 *wire.StreamFrame
|
||||
framer *streamFramer
|
||||
streamsMap *streamsMap
|
||||
stream1, stream2 *stream
|
||||
|
@ -25,11 +25,11 @@ var _ = Describe("Stream Framer", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
retransmittedFrame1 = &frames.StreamFrame{
|
||||
retransmittedFrame1 = &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0x13, 0x37},
|
||||
}
|
||||
retransmittedFrame2 = &frames.StreamFrame{
|
||||
retransmittedFrame2 = &wire.StreamFrame{
|
||||
StreamID: 6,
|
||||
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
|
||||
Context("splitting of frames", func() {
|
||||
It("splits off nothing", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("bar"),
|
||||
Offset: 3,
|
||||
|
@ -176,7 +176,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
})
|
||||
|
||||
It("splits off initial frame", func() {
|
||||
f := &frames.StreamFrame{
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("foobar"),
|
||||
DataLenPresent: true,
|
||||
|
@ -210,7 +210,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
|
||||
It("never returns an empty stream frame", func() {
|
||||
// this one frame will be split off from again and again in this test. Therefore, it has to be large enough (checked again at the end)
|
||||
origFrame := &frames.StreamFrame{
|
||||
origFrame := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Offset: 1,
|
||||
FinBit: false,
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
|
||||
"os"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/wire"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/gomega/gbytes"
|
||||
|
@ -78,7 +78,7 @@ var _ = Describe("Stream", func() {
|
|||
It("reads a single StreamFrame", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
|
@ -116,11 +116,11 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
|
||||
frame1 := frames.StreamFrame{
|
||||
frame1 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
frame2 := frames.StreamFrame{
|
||||
frame2 := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
|
@ -139,11 +139,11 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
|
||||
frame1 := frames.StreamFrame{
|
||||
frame1 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
frame2 := frames.StreamFrame{
|
||||
frame2 := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
frame := frames.StreamFrame{Data: []byte{0xDE, 0xAD}}
|
||||
frame := wire.StreamFrame{Data: []byte{0xDE, 0xAD}}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err := str.AddStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -178,11 +178,11 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
|
||||
frame1 := frames.StreamFrame{
|
||||
frame1 := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
frame2 := frames.StreamFrame{
|
||||
frame2 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
|
@ -202,15 +202,15 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
|
||||
frame1 := frames.StreamFrame{
|
||||
frame1 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
frame2 := frames.StreamFrame{
|
||||
frame2 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0x13, 0x37},
|
||||
}
|
||||
frame3 := frames.StreamFrame{
|
||||
frame3 := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
|
@ -232,11 +232,11 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
|
||||
frame1 := frames.StreamFrame{
|
||||
frame1 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte("foob"),
|
||||
}
|
||||
frame2 := frames.StreamFrame{
|
||||
frame2 := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte("obar"),
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ var _ = Describe("Stream", func() {
|
|||
It("calls onData", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
It("returns an error when Read is called after the deadline", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes()
|
||||
f := &frames.StreamFrame{Data: []byte("foobar")}
|
||||
f := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
err := str.AddStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.SetReadDeadline(time.Now().Add(-time.Second))
|
||||
|
@ -332,7 +332,7 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
It("sets a read deadline, when SetDeadline is called", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes()
|
||||
f := &frames.StreamFrame{Data: []byte("foobar")}
|
||||
f := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
err := str.AddStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.SetDeadline(time.Now().Add(-time.Second))
|
||||
|
@ -348,7 +348,7 @@ var _ = Describe("Stream", func() {
|
|||
It("returns EOFs", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
FinBit: true,
|
||||
|
@ -368,12 +368,12 @@ var _ = Describe("Stream", func() {
|
|||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
|
||||
frame1 := frames.StreamFrame{
|
||||
frame1 := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
FinBit: true,
|
||||
}
|
||||
frame2 := frames.StreamFrame{
|
||||
frame2 := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ var _ = Describe("Stream", func() {
|
|||
It("returns EOFs with partial read", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
FinBit: true,
|
||||
|
@ -411,7 +411,7 @@ var _ = Describe("Stream", func() {
|
|||
It("handles immediate FINs", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(0))
|
||||
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(0))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{},
|
||||
FinBit: true,
|
||||
|
@ -484,7 +484,7 @@ var _ = Describe("Stream", func() {
|
|||
Context("reset by the peer", func() {
|
||||
It("continues reading after receiving a remote error", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ var _ = Describe("Stream", func() {
|
|||
It("reads a delayed StreamFrame that arrives after receiving a remote error", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
str.RegisterRemoteError(testErr)
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
|
@ -513,7 +513,7 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
It("returns the error if reading past the offset of the frame received", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
It("returns an EOF when reading past the offset, if the stream received a finbit", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
FinBit: true,
|
||||
|
@ -544,7 +544,7 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
It("continues reading in small chunks after receiving a remote error", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
FinBit: true,
|
||||
|
@ -565,7 +565,7 @@ var _ = Describe("Stream", func() {
|
|||
It("doesn't inform the flow controller about bytes read after receiving the remote error", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
|
||||
// No AddBytesRead()
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 0,
|
||||
StreamID: 5,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
|
@ -685,7 +685,7 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
It("doesn't allow further reads", func() {
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6))
|
||||
str.AddStreamFrame(&frames.StreamFrame{
|
||||
str.AddStreamFrame(&wire.StreamFrame{
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
str.Reset(testErr)
|
||||
|
@ -946,7 +946,7 @@ var _ = Describe("Stream", func() {
|
|||
It("errors when a StreamFrames causes a flow control violation", func() {
|
||||
testErr := errors.New("flow control violation")
|
||||
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(8)).Return(testErr)
|
||||
frame := frames.StreamFrame{
|
||||
frame := wire.StreamFrame{
|
||||
Offset: 2,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
|
@ -958,7 +958,7 @@ var _ = Describe("Stream", func() {
|
|||
testErr := errors.New("testErr")
|
||||
|
||||
finishReading := func() {
|
||||
err := str.AddStreamFrame(&frames.StreamFrame{FinBit: true})
|
||||
err := str.AddStreamFrame(&wire.StreamFrame{FinBit: true})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 100)
|
||||
_, err = strWithTimeout.Read(b)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import "github.com/lucas-clemente/quic-go/protocol"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
28
wire/log.go
Normal file
28
wire/log.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package wire
|
||||
|
||||
import "github.com/lucas-clemente/quic-go/internal/utils"
|
||||
|
||||
// LogFrame logs a frame, either sent or received
|
||||
func LogFrame(frame Frame, sent bool) {
|
||||
if !utils.Debug() {
|
||||
return
|
||||
}
|
||||
dir := "<-"
|
||||
if sent {
|
||||
dir = "->"
|
||||
}
|
||||
switch f := frame.(type) {
|
||||
case *StreamFrame:
|
||||
utils.Debugf("\t%s &wire.StreamFrame{StreamID: %d, FinBit: %t, Offset: 0x%x, Data length: 0x%x, Offset + Data length: 0x%x}", dir, f.StreamID, f.FinBit, f.Offset, f.DataLen(), f.Offset+f.DataLen())
|
||||
case *StopWaitingFrame:
|
||||
if sent {
|
||||
utils.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x, PacketNumberLen: 0x%x}", dir, f.LeastUnacked, f.PacketNumberLen)
|
||||
} else {
|
||||
utils.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x}", dir, f.LeastUnacked)
|
||||
}
|
||||
case *AckFrame:
|
||||
utils.Debugf("\t%s &wire.AckFrame{LargestAcked: 0x%x, LowestAcked: 0x%x, AckRanges: %#v, DelayTime: %s}", dir, f.LargestAcked, f.LowestAcked, f.AckRanges, f.DelayTime.String())
|
||||
default:
|
||||
utils.Debugf("\t%s %#v", dir, frame)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -37,12 +37,12 @@ var _ = Describe("Frame logging", func() {
|
|||
|
||||
It("logs sent frames", func() {
|
||||
LogFrame(&RstStreamFrame{}, true)
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t-> &frames.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t-> &wire.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
|
||||
})
|
||||
|
||||
It("logs received frames", func() {
|
||||
LogFrame(&RstStreamFrame{}, false)
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &frames.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
|
||||
})
|
||||
|
||||
It("logs stream frames", func() {
|
||||
|
@ -52,7 +52,7 @@ var _ = Describe("Frame logging", func() {
|
|||
Data: bytes.Repeat([]byte{'f'}, 0x100),
|
||||
}
|
||||
LogFrame(frame, false)
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &frames.StreamFrame{StreamID: 42, FinBit: false, Offset: 0x1337, Data length: 0x100, Offset + Data length: 0x1437}\n"))
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.StreamFrame{StreamID: 42, FinBit: false, Offset: 0x1337, Data length: 0x100, Offset + Data length: 0x1437}\n"))
|
||||
})
|
||||
|
||||
It("logs ACK frames", func() {
|
||||
|
@ -62,7 +62,7 @@ var _ = Describe("Frame logging", func() {
|
|||
DelayTime: 1 * time.Millisecond,
|
||||
}
|
||||
LogFrame(frame, false)
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &frames.AckFrame{LargestAcked: 0x1337, LowestAcked: 0x42, AckRanges: []frames.AckRange(nil), DelayTime: 1ms}\n"))
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.AckFrame{LargestAcked: 0x1337, LowestAcked: 0x42, AckRanges: []wire.AckRange(nil), DelayTime: 1ms}\n"))
|
||||
})
|
||||
|
||||
It("logs incoming StopWaiting frames", func() {
|
||||
|
@ -70,7 +70,7 @@ var _ = Describe("Frame logging", func() {
|
|||
LeastUnacked: 0x1337,
|
||||
}
|
||||
LogFrame(frame, false)
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &frames.StopWaitingFrame{LeastUnacked: 0x1337}\n"))
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.StopWaitingFrame{LeastUnacked: 0x1337}\n"))
|
||||
})
|
||||
|
||||
It("logs outgoing StopWaiting frames", func() {
|
||||
|
@ -79,6 +79,6 @@ var _ = Describe("Frame logging", func() {
|
|||
PacketNumberLen: protocol.PacketNumberLen4,
|
||||
}
|
||||
LogFrame(frame, true)
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t-> &frames.StopWaitingFrame{LeastUnacked: 0x1337, PacketNumberLen: 0x4}\n"))
|
||||
Expect(buf.Bytes()).To(ContainSubstring("\t-> &wire.StopWaitingFrame{LeastUnacked: 0x1337, PacketNumberLen: 0x4}\n"))
|
||||
})
|
||||
})
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package frames
|
||||
package wire
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
func TestCrypto(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Frames Suite")
|
||||
RunSpecs(t, "Wire Suite")
|
||||
}
|
||||
|
||||
const (
|
Loading…
Add table
Add a link
Reference in a new issue