rename package frames to wire

This commit is contained in:
Marten Seemann 2017-08-29 23:27:15 +07:00
parent 5281d5b65d
commit 88afad8722
49 changed files with 565 additions and 571 deletions

View file

@ -3,18 +3,18 @@ package ackhandler
import ( import (
"time" "time"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
) )
// SentPacketHandler handles ACKs received for outgoing packets // SentPacketHandler handles ACKs received for outgoing packets
type SentPacketHandler interface { type SentPacketHandler interface {
// SentPacket may modify the packet // SentPacket may modify the packet
SentPacket(packet *Packet) error 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 SendingAllowed() bool
GetStopWaitingFrame(force bool) *frames.StopWaitingFrame GetStopWaitingFrame(force bool) *wire.StopWaitingFrame
ShouldSendRetransmittablePacket() bool ShouldSendRetransmittablePacket() bool
DequeuePacketForRetransmission() (packet *Packet) DequeuePacketForRetransmission() (packet *Packet)
GetLeastUnacked() protocol.PacketNumber GetLeastUnacked() protocol.PacketNumber
@ -29,5 +29,5 @@ type ReceivedPacketHandler interface {
SetLowerLimit(protocol.PacketNumber) SetLowerLimit(protocol.PacketNumber)
GetAlarmTimeout() time.Time GetAlarmTimeout() time.Time
GetAckFrame() *frames.AckFrame GetAckFrame() *wire.AckFrame
} }

View file

@ -3,15 +3,15 @@ package ackhandler
import ( import (
"time" "time"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
) )
// A Packet is a packet // A Packet is a packet
// +gen linkedlist // +gen linkedlist
type Packet struct { type Packet struct {
PacketNumber protocol.PacketNumber PacketNumber protocol.PacketNumber
Frames []frames.Frame Frames []wire.Frame
Length protocol.ByteCount Length protocol.ByteCount
EncryptionLevel protocol.EncryptionLevel EncryptionLevel protocol.EncryptionLevel
@ -19,13 +19,13 @@ type Packet struct {
} }
// GetFramesForRetransmission gets all the frames for retransmission // GetFramesForRetransmission gets all the frames for retransmission
func (p *Packet) GetFramesForRetransmission() []frames.Frame { func (p *Packet) GetFramesForRetransmission() []wire.Frame {
var fs []frames.Frame var fs []wire.Frame
for _, frame := range p.Frames { for _, frame := range p.Frames {
switch frame.(type) { switch frame.(type) {
case *frames.AckFrame: case *wire.AckFrame:
continue continue
case *frames.StopWaitingFrame: case *wire.StopWaitingFrame:
continue continue
} }
fs = append(fs, frame) fs = append(fs, frame)

View file

@ -1,37 +1,37 @@
package ackhandler package ackhandler
import ( import (
"github.com/lucas-clemente/quic-go/frames" "github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
var _ = Describe("Packet", func() { var _ = Describe("Packet", func() {
Context("getting frames for retransmission", func() { Context("getting frames for retransmission", func() {
ackFrame := &frames.AckFrame{LargestAcked: 13} ackFrame := &wire.AckFrame{LargestAcked: 13}
stopWaitingFrame := &frames.StopWaitingFrame{LeastUnacked: 7331} stopWaitingFrame := &wire.StopWaitingFrame{LeastUnacked: 7331}
windowUpdateFrame := &frames.WindowUpdateFrame{StreamID: 999} windowUpdateFrame := &wire.WindowUpdateFrame{StreamID: 999}
streamFrame := &frames.StreamFrame{ streamFrame := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0x13, 0x37}, Data: []byte{0x13, 0x37},
} }
rstStreamFrame := &frames.RstStreamFrame{ rstStreamFrame := &wire.RstStreamFrame{
StreamID: 555, StreamID: 555,
ErrorCode: 1337, ErrorCode: 1337,
} }
It("returns nil if there are no retransmittable frames", func() { It("returns nil if there are no retransmittable frames", func() {
packet := &Packet{ packet := &Packet{
Frames: []frames.Frame{ackFrame, stopWaitingFrame}, Frames: []wire.Frame{ackFrame, stopWaitingFrame},
} }
Expect(packet.GetFramesForRetransmission()).To(BeNil()) Expect(packet.GetFramesForRetransmission()).To(BeNil())
}) })
It("returns all retransmittable frames", func() { It("returns all retransmittable frames", func() {
packet := &Packet{ packet := &Packet{
Frames: []frames.Frame{ Frames: []wire.Frame{
windowUpdateFrame, windowUpdateFrame,
ackFrame, ackFrame,
stopWaitingFrame, stopWaitingFrame,

View file

@ -4,8 +4,8 @@ import (
"errors" "errors"
"time" "time"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
) )
var errInvalidPacketNumber = errors.New("ReceivedPacketHandler: Invalid packet number") var errInvalidPacketNumber = errors.New("ReceivedPacketHandler: Invalid packet number")
@ -23,7 +23,7 @@ type receivedPacketHandler struct {
retransmittablePacketsReceivedSinceLastAck int retransmittablePacketsReceivedSinceLastAck int
ackQueued bool ackQueued bool
ackAlarm time.Time ackAlarm time.Time
lastAck *frames.AckFrame lastAck *wire.AckFrame
version protocol.VersionNumber 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())) { if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(time.Now())) {
return nil return nil
} }
ackRanges := h.packetHistory.GetAckRanges() ackRanges := h.packetHistory.GetAckRanges()
ack := &frames.AckFrame{ ack := &wire.AckFrame{
LargestAcked: h.largestObserved, LargestAcked: h.largestObserved,
LowestAcked: ackRanges[len(ackRanges)-1].FirstPacketNumber, LowestAcked: ackRanges[len(ackRanges)-1].FirstPacketNumber,
PacketReceivedTime: h.largestObservedReceivedTime, PacketReceivedTime: h.largestObservedReceivedTime,

View file

@ -3,8 +3,8 @@ package ackhandler
import ( import (
"time" "time"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -221,8 +221,8 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(4))) Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(4)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(1))) Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(ack.AckRanges).To(HaveLen(2)) Expect(ack.AckRanges).To(HaveLen(2))
Expect(ack.AckRanges[0]).To(Equal(frames.AckRange{FirstPacketNumber: 4, LastPacketNumber: 4})) Expect(ack.AckRanges[0]).To(Equal(wire.AckRange{FirstPacketNumber: 4, LastPacketNumber: 4}))
Expect(ack.AckRanges[1]).To(Equal(frames.AckRange{FirstPacketNumber: 1, LastPacketNumber: 1})) Expect(ack.AckRanges[1]).To(Equal(wire.AckRange{FirstPacketNumber: 1, LastPacketNumber: 1}))
}) })
It("accepts packets below the lower limit", func() { It("accepts packets below the lower limit", func() {

View file

@ -1,10 +1,10 @@
package ackhandler package ackhandler
import ( import (
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "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. // 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 // 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 { if h.ranges.Len() == 0 {
return nil return nil
} }
var ackRanges []frames.AckRange var ackRanges []wire.AckRange
for el := h.ranges.Back(); el != nil; el = el.Prev() { 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 return ackRanges
} }
func (h *receivedPacketHistory) GetHighestAckRange() frames.AckRange { func (h *receivedPacketHistory) GetHighestAckRange() wire.AckRange {
ackRange := frames.AckRange{} ackRange := wire.AckRange{}
if h.ranges.Len() > 0 { if h.ranges.Len() > 0 {
r := h.ranges.Back().Value r := h.ranges.Back().Value
ackRange.FirstPacketNumber = r.Start ackRange.FirstPacketNumber = r.Start

View file

@ -1,9 +1,9 @@
package ackhandler package ackhandler
import ( import (
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -298,7 +298,7 @@ var _ = Describe("receivedPacketHistory", func() {
hist.ReceivedPacket(5) hist.ReceivedPacket(5)
ackRanges := hist.GetAckRanges() ackRanges := hist.GetAckRanges()
Expect(ackRanges).To(HaveLen(1)) 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() { It("gets multiple ACK ranges", func() {
@ -311,9 +311,9 @@ var _ = Describe("receivedPacketHistory", func() {
hist.ReceivedPacket(2) hist.ReceivedPacket(2)
ackRanges := hist.GetAckRanges() ackRanges := hist.GetAckRanges()
Expect(ackRanges).To(HaveLen(3)) Expect(ackRanges).To(HaveLen(3))
Expect(ackRanges[0]).To(Equal(frames.AckRange{FirstPacketNumber: 10, LastPacketNumber: 11})) Expect(ackRanges[0]).To(Equal(wire.AckRange{FirstPacketNumber: 10, LastPacketNumber: 11}))
Expect(ackRanges[1]).To(Equal(frames.AckRange{FirstPacketNumber: 4, LastPacketNumber: 6})) Expect(ackRanges[1]).To(Equal(wire.AckRange{FirstPacketNumber: 4, LastPacketNumber: 6}))
Expect(ackRanges[2]).To(Equal(frames.AckRange{FirstPacketNumber: 1, LastPacketNumber: 2})) 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() { It("gets a single ACK range", func() {
hist.ReceivedPacket(4) hist.ReceivedPacket(4)
hist.ReceivedPacket(5) 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() { It("gets the highest of multiple ACK ranges", func() {
hist.ReceivedPacket(3) hist.ReceivedPacket(3)
hist.ReceivedPacket(6) hist.ReceivedPacket(6)
hist.ReceivedPacket(7) 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}))
}) })
}) })
}) })

View file

@ -1,12 +1,10 @@
package ackhandler package ackhandler
import ( import "github.com/lucas-clemente/quic-go/wire"
"github.com/lucas-clemente/quic-go/frames"
)
// Returns a new slice with all non-retransmittable frames deleted. // Returns a new slice with all non-retransmittable frames deleted.
func stripNonRetransmittableFrames(fs []frames.Frame) []frames.Frame { func stripNonRetransmittableFrames(fs []wire.Frame) []wire.Frame {
res := make([]frames.Frame, 0, len(fs)) res := make([]wire.Frame, 0, len(fs))
for _, f := range fs { for _, f := range fs {
if IsFrameRetransmittable(f) { if IsFrameRetransmittable(f) {
res = append(res, 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. // IsFrameRetransmittable returns true if the frame should be retransmitted.
func IsFrameRetransmittable(f frames.Frame) bool { func IsFrameRetransmittable(f wire.Frame) bool {
switch f.(type) { switch f.(type) {
case *frames.StopWaitingFrame: case *wire.StopWaitingFrame:
return false return false
case *frames.AckFrame: case *wire.AckFrame:
return false return false
default: default:
return true return true
@ -28,7 +26,7 @@ func IsFrameRetransmittable(f frames.Frame) bool {
} }
// HasRetransmittableFrames returns true if at least one frame is retransmittable. // 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 { for _, f := range fs {
if IsFrameRetransmittable(f) { if IsFrameRetransmittable(f) {
return true return true

View file

@ -3,22 +3,22 @@ package ackhandler
import ( import (
"reflect" "reflect"
"github.com/lucas-clemente/quic-go/frames" "github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
var _ = Describe("retransmittable frames", func() { var _ = Describe("retransmittable frames", func() {
for fl, el := range map[frames.Frame]bool{ for fl, el := range map[wire.Frame]bool{
&frames.AckFrame{}: false, &wire.AckFrame{}: false,
&frames.StopWaitingFrame{}: false, &wire.StopWaitingFrame{}: false,
&frames.BlockedFrame{}: true, &wire.BlockedFrame{}: true,
&frames.ConnectionCloseFrame{}: true, &wire.ConnectionCloseFrame{}: true,
&frames.GoawayFrame{}: true, &wire.GoawayFrame{}: true,
&frames.PingFrame{}: true, &wire.PingFrame{}: true,
&frames.RstStreamFrame{}: true, &wire.RstStreamFrame{}: true,
&frames.StreamFrame{}: true, &wire.StreamFrame{}: true,
&frames.WindowUpdateFrame{}: true, &wire.WindowUpdateFrame{}: true,
} { } {
f := fl f := fl
e := el e := el
@ -29,16 +29,16 @@ var _ = Describe("retransmittable frames", func() {
}) })
It("stripping non-retransmittable frames works for "+fName, func() { It("stripping non-retransmittable frames works for "+fName, func() {
s := []frames.Frame{f} s := []wire.Frame{f}
if e { if e {
Expect(stripNonRetransmittableFrames(s)).To(Equal([]frames.Frame{f})) Expect(stripNonRetransmittableFrames(s)).To(Equal([]wire.Frame{f}))
} else { } else {
Expect(stripNonRetransmittableFrames(s)).To(BeEmpty()) Expect(stripNonRetransmittableFrames(s)).To(BeEmpty())
} }
}) })
It("HasRetransmittableFrames works for "+fName, func() { It("HasRetransmittableFrames works for "+fName, func() {
Expect(HasRetransmittableFrames([]frames.Frame{f})).To(Equal(e)) Expect(HasRetransmittableFrames([]wire.Frame{f})).To(Equal(e))
}) })
} }
}) })

View file

@ -6,10 +6,10 @@ import (
"time" "time"
"github.com/lucas-clemente/quic-go/congestion" "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/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
"github.com/lucas-clemente/quic-go/wire"
) )
const ( const (
@ -139,7 +139,7 @@ func (h *sentPacketHandler) SentPacket(packet *Packet) error {
return nil 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 { if ackFrame.LargestAcked > h.lastSentPacketNumber {
return errAckForUnsentPacket return errAckForUnsentPacket
} }
@ -187,7 +187,7 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *frames.AckFrame, withPacketNum
return nil return nil
} }
func (h *sentPacketHandler) determineNewlyAckedPackets(ackFrame *frames.AckFrame) ([]*PacketElement, error) { func (h *sentPacketHandler) determineNewlyAckedPackets(ackFrame *wire.AckFrame) ([]*PacketElement, error) {
var ackedPackets []*PacketElement var ackedPackets []*PacketElement
ackRangeIndex := 0 ackRangeIndex := 0
for el := h.packetHistory.Front(); el != nil; el = el.Next() { for el := h.packetHistory.Front(); el != nil; el = el.Next() {
@ -332,7 +332,7 @@ func (h *sentPacketHandler) GetLeastUnacked() protocol.PacketNumber {
return h.largestInOrderAcked() + 1 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) return h.stopWaitingManager.GetStopWaitingFrame(force)
} }
@ -391,7 +391,7 @@ func (h *sentPacketHandler) computeRTOTimeout() time.Duration {
return utils.MinDuration(rto, maxRTOTimeout) 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 { for _, p := range h.skippedPackets {
if ackFrame.AcksPacket(p) { if ackFrame.AcksPacket(p) {
return true return true

View file

@ -4,8 +4,8 @@ import (
"time" "time"
"github.com/lucas-clemente/quic-go/congestion" "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/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -58,23 +58,23 @@ func (m *mockCongestion) OnPacketLost(n protocol.PacketNumber, l protocol.ByteCo
} }
func retransmittablePacket(num protocol.PacketNumber) *Packet { 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 { 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 _ = Describe("SentPacketHandler", func() {
var ( var (
handler *sentPacketHandler handler *sentPacketHandler
streamFrame frames.StreamFrame streamFrame wire.StreamFrame
) )
BeforeEach(func() { BeforeEach(func() {
rttStats := &congestion.RTTStats{} rttStats := &congestion.RTTStats{}
handler = NewSentPacketHandler(rttStats).(*sentPacketHandler) handler = NewSentPacketHandler(rttStats).(*sentPacketHandler)
streamFrame = frames.StreamFrame{ streamFrame = wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0x13, 0x37}, Data: []byte{0x13, 0x37},
} }
@ -96,8 +96,8 @@ var _ = Describe("SentPacketHandler", func() {
Context("registering sent packets", func() { Context("registering sent packets", func() {
It("accepts two consecutive packets", func() { It("accepts two consecutive packets", func() {
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 2}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.SentPacket(&packet2) err = handler.SentPacket(&packet2)
@ -110,8 +110,8 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("rejects packets with the same packet number", func() { It("rejects packets with the same packet number", func() {
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 2}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.SentPacket(&packet2) err = handler.SentPacket(&packet2)
@ -123,8 +123,8 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("rejects packets with decreasing packet number", func() { It("rejects packets with decreasing packet number", func() {
packet1 := Packet{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 2}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.SentPacket(&packet2) err = handler.SentPacket(&packet2)
@ -135,7 +135,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("stores the sent time", 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) err := handler.SentPacket(&packet)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory.Front().Value.SendTime.Unix()).To(BeNumerically("~", time.Now().Unix(), 1)) 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() { Context("skipped packet numbers", func() {
It("works with non-consecutive packet numbers", func() { It("works with non-consecutive packet numbers", func() {
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 2}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.SentPacket(&packet2) err = handler.SentPacket(&packet2)
@ -166,9 +166,9 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("recognizes multiple skipped packets", func() { It("recognizes multiple skipped packets", func() {
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 2}
packet3 := Packet{PacketNumber: 5, Frames: []frames.Frame{&streamFrame}, Length: 2} packet3 := Packet{PacketNumber: 5, Frames: []wire.Frame{&streamFrame}, Length: 2}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.SentPacket(&packet2) err = handler.SentPacket(&packet2)
@ -180,8 +180,8 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("recognizes multiple consecutive skipped packets", func() { It("recognizes multiple consecutive skipped packets", func() {
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 4, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 4, Frames: []wire.Frame{&streamFrame}, Length: 2}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.SentPacket(&packet2) err = handler.SentPacket(&packet2)
@ -192,7 +192,7 @@ var _ = Describe("SentPacketHandler", func() {
It("limits the lengths of the skipped packet slice", func() { It("limits the lengths of the skipped packet slice", func() {
for i := 0; i < protocol.MaxTrackedSkippedPackets+5; i++ { 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) err := handler.SentPacket(&packet)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
} }
@ -269,17 +269,17 @@ var _ = Describe("SentPacketHandler", func() {
BeforeEach(func() { BeforeEach(func() {
packets = []*Packet{ packets = []*Packet{
{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 4, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 4, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 5, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 5, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 6, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 6, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 7, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 7, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 8, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 8, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 9, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 9, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 10, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 10, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 12, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 12, Frames: []wire.Frame{&streamFrame}, Length: 1},
} }
for _, packet := range packets { for _, packet := range packets {
err := handler.SentPacket(packet) err := handler.SentPacket(packet)
@ -293,7 +293,7 @@ var _ = Describe("SentPacketHandler", func() {
Context("ACK validation", func() { Context("ACK validation", func() {
It("rejects duplicate ACKs", func() { It("rejects duplicate ACKs", func() {
largestAcked := 3 largestAcked := 3
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: protocol.PacketNumber(largestAcked), LargestAcked: protocol.PacketNumber(largestAcked),
LowestAcked: 1, LowestAcked: 1,
} }
@ -306,7 +306,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("rejects out of order ACKs", func() { It("rejects out of order ACKs", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 3, LargestAcked: 3,
} }
err := handler.ReceivedAck(&ack, 1337, time.Now()) 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() { It("rejects ACKs with a too high LargestAcked packet number", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: packets[len(packets)-1].PacketNumber + 1337, LargestAcked: packets[len(packets)-1].PacketNumber + 1337,
} }
err := handler.ReceivedAck(&ack, 1, time.Now()) err := handler.ReceivedAck(&ack, 1, time.Now())
@ -328,7 +328,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("ignores repeated ACKs", func() { It("ignores repeated ACKs", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 3, LargestAcked: 3,
LowestAcked: 1, LowestAcked: 1,
} }
@ -342,7 +342,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("rejects ACKs for skipped packets", func() { It("rejects ACKs for skipped packets", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 12, LargestAcked: 12,
LowestAcked: 5, LowestAcked: 5,
} }
@ -351,10 +351,10 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("accepts an ACK that correctly nacks a skipped packet", func() { It("accepts an ACK that correctly nacks a skipped packet", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 12, LargestAcked: 12,
LowestAcked: 5, LowestAcked: 5,
AckRanges: []frames.AckRange{ AckRanges: []wire.AckRange{
{FirstPacketNumber: 12, LastPacketNumber: 12}, {FirstPacketNumber: 12, LastPacketNumber: 12},
{FirstPacketNumber: 5, LastPacketNumber: 10}, {FirstPacketNumber: 5, LastPacketNumber: 10},
}, },
@ -367,7 +367,7 @@ var _ = Describe("SentPacketHandler", func() {
Context("acks and nacks the right packets", func() { Context("acks and nacks the right packets", func() {
It("adjusts the LargestAcked", func() { It("adjusts the LargestAcked", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 5, LargestAcked: 5,
LowestAcked: 1, LowestAcked: 1,
} }
@ -383,7 +383,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("ACKs all packets for an ACK frame with no missing packets", func() { It("ACKs all packets for an ACK frame with no missing packets", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 8, LargestAcked: 8,
LowestAcked: 2, LowestAcked: 2,
} }
@ -399,10 +399,10 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("handles an ACK frame with one missing packet range", func() { It("handles an ACK frame with one missing packet range", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 9, LargestAcked: 9,
LowestAcked: 2, 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: 6, LastPacketNumber: 9},
{FirstPacketNumber: 2, LastPacketNumber: 3}, {FirstPacketNumber: 2, LastPacketNumber: 3},
}, },
@ -421,7 +421,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("Does not ack packets below the LowestAcked", func() { It("Does not ack packets below the LowestAcked", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 8, LargestAcked: 8,
LowestAcked: 3, LowestAcked: 3,
} }
@ -435,10 +435,10 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("handles an ACK with multiple missing packet ranges", func() { It("handles an ACK with multiple missing packet ranges", func() {
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 9, LargestAcked: 9,
LowestAcked: 1, 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: 9, LastPacketNumber: 9},
{FirstPacketNumber: 6, LastPacketNumber: 7}, {FirstPacketNumber: 6, LastPacketNumber: 7},
{FirstPacketNumber: 3, LastPacketNumber: 3}, {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() { It("processes an ACK frame that would be sent after a late arrival of a packet", func() {
largestObserved := 6 largestObserved := 6
ack1 := frames.AckFrame{ ack1 := wire.AckFrame{
LargestAcked: protocol.PacketNumber(largestObserved), LargestAcked: protocol.PacketNumber(largestObserved),
LowestAcked: 1, LowestAcked: 1,
AckRanges: []frames.AckRange{ AckRanges: []wire.AckRange{
{FirstPacketNumber: 4, LastPacketNumber: protocol.PacketNumber(largestObserved)}, {FirstPacketNumber: 4, LastPacketNumber: protocol.PacketNumber(largestObserved)},
{FirstPacketNumber: 1, LastPacketNumber: 2}, {FirstPacketNumber: 1, LastPacketNumber: 2},
}, },
@ -474,7 +474,7 @@ var _ = Describe("SentPacketHandler", func() {
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 5))) Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 5)))
el := handler.packetHistory.Front() el := handler.packetHistory.Front()
Expect(el.Value.PacketNumber).To(Equal(protocol.PacketNumber(3))) Expect(el.Value.PacketNumber).To(Equal(protocol.PacketNumber(3)))
ack2 := frames.AckFrame{ ack2 := wire.AckFrame{
LargestAcked: protocol.PacketNumber(largestObserved), LargestAcked: protocol.PacketNumber(largestObserved),
LowestAcked: 1, 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() { 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, LargestAcked: 6,
LowestAcked: 1, LowestAcked: 1,
AckRanges: []frames.AckRange{ AckRanges: []wire.AckRange{
{FirstPacketNumber: 4, LastPacketNumber: 6}, {FirstPacketNumber: 4, LastPacketNumber: 6},
{FirstPacketNumber: 1, LastPacketNumber: 2}, {FirstPacketNumber: 1, LastPacketNumber: 2},
}, },
@ -498,7 +498,7 @@ var _ = Describe("SentPacketHandler", func() {
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 5))) Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 5)))
el := handler.packetHistory.Front() el := handler.packetHistory.Front()
Expect(el.Value.PacketNumber).To(Equal(protocol.PacketNumber(3))) Expect(el.Value.PacketNumber).To(Equal(protocol.PacketNumber(3)))
ack2 := frames.AckFrame{ ack2 := wire.AckFrame{
LargestAcked: 7, LargestAcked: 7,
LowestAcked: 1, LowestAcked: 1,
} }
@ -509,7 +509,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
It("processes an ACK that contains old ACK ranges", func() { It("processes an ACK that contains old ACK ranges", func() {
ack1 := frames.AckFrame{ ack1 := wire.AckFrame{
LargestAcked: 6, LargestAcked: 6,
LowestAcked: 1, LowestAcked: 1,
} }
@ -517,10 +517,10 @@ var _ = Describe("SentPacketHandler", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory.Front().Value.PacketNumber).To(Equal(protocol.PacketNumber(7))) Expect(handler.packetHistory.Front().Value.PacketNumber).To(Equal(protocol.PacketNumber(7)))
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 6))) Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(len(packets) - 6)))
ack2 := frames.AckFrame{ ack2 := wire.AckFrame{
LargestAcked: 10, LargestAcked: 10,
LowestAcked: 1, LowestAcked: 1,
AckRanges: []frames.AckRange{ AckRanges: []wire.AckRange{
{FirstPacketNumber: 8, LastPacketNumber: 10}, {FirstPacketNumber: 8, LastPacketNumber: 10},
{FirstPacketNumber: 3, LastPacketNumber: 3}, {FirstPacketNumber: 3, LastPacketNumber: 3},
{FirstPacketNumber: 1, LastPacketNumber: 1}, {FirstPacketNumber: 1, LastPacketNumber: 1},
@ -542,13 +542,13 @@ var _ = Describe("SentPacketHandler", func() {
getPacketElement(2).Value.SendTime = now.Add(-5 * time.Minute) getPacketElement(2).Value.SendTime = now.Add(-5 * time.Minute)
getPacketElement(6).Value.SendTime = now.Add(-1 * time.Minute) getPacketElement(6).Value.SendTime = now.Add(-1 * time.Minute)
// Now, check that the proper times are used when calculating the deltas // 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(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 10*time.Minute, 1*time.Second)) 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(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second)) 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(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 1*time.Minute, 1*time.Second)) 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() { It("uses the DelayTime in the ack frame", func() {
now := time.Now() now := time.Now()
getPacketElement(1).Value.SendTime = now.Add(-10 * time.Minute) 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(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second)) Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second))
}) })
@ -568,13 +568,13 @@ var _ = Describe("SentPacketHandler", func() {
BeforeEach(func() { BeforeEach(func() {
packets = []*Packet{ packets = []*Packet{
{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 4, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 4, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 5, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 5, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 6, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 6, Frames: []wire.Frame{&streamFrame}, Length: 1},
{PacketNumber: 7, Frames: []frames.Frame{&streamFrame}, Length: 1}, {PacketNumber: 7, Frames: []wire.Frame{&streamFrame}, Length: 1},
} }
for _, packet := range packets { for _, packet := range packets {
handler.SentPacket(packet) handler.SentPacket(packet)
@ -582,7 +582,7 @@ var _ = Describe("SentPacketHandler", func() {
// Increase RTT, because the tests would be flaky otherwise // Increase RTT, because the tests would be flaky otherwise
handler.rttStats.UpdateRTT(time.Minute, 0, time.Now()) handler.rttStats.UpdateRTT(time.Minute, 0, time.Now())
// Ack a single packet so that we have non-RTO timings // 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))) Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(6)))
}) })
@ -604,23 +604,23 @@ var _ = Describe("SentPacketHandler", func() {
Context("StopWaitings", func() { Context("StopWaitings", func() {
It("gets a StopWaitingFrame", 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()) err := handler.ReceivedAck(&ack, 2, time.Now())
Expect(err).ToNot(HaveOccurred()) 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() { It("gets a StopWaitingFrame after queueing a retransmission", func() {
handler.queuePacketForRetransmission(getPacketElement(5)) 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() { It("calculates bytes in flight", func() {
packet1 := Packet{PacketNumber: 1, Frames: []frames.Frame{&streamFrame}, Length: 1} packet1 := Packet{PacketNumber: 1, Frames: []wire.Frame{&streamFrame}, Length: 1}
packet2 := Packet{PacketNumber: 2, Frames: []frames.Frame{&streamFrame}, Length: 2} packet2 := Packet{PacketNumber: 2, Frames: []wire.Frame{&streamFrame}, Length: 2}
packet3 := Packet{PacketNumber: 3, Frames: []frames.Frame{&streamFrame}, Length: 3} packet3 := Packet{PacketNumber: 3, Frames: []wire.Frame{&streamFrame}, Length: 3}
err := handler.SentPacket(&packet1) err := handler.SentPacket(&packet1)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(1))) Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(1)))
@ -635,10 +635,10 @@ var _ = Describe("SentPacketHandler", func() {
handler.rttStats.UpdateRTT(time.Minute, 0, time.Now()) handler.rttStats.UpdateRTT(time.Minute, 0, time.Now())
// ACK 1 and 3, NACK 2 // ACK 1 and 3, NACK 2
ack := frames.AckFrame{ ack := wire.AckFrame{
LargestAcked: 3, LargestAcked: 3,
LowestAcked: 1, LowestAcked: 1,
AckRanges: []frames.AckRange{ AckRanges: []wire.AckRange{
{FirstPacketNumber: 3, LastPacketNumber: 3}, {FirstPacketNumber: 3, LastPacketNumber: 3},
{FirstPacketNumber: 1, LastPacketNumber: 1}, {FirstPacketNumber: 1, LastPacketNumber: 1},
}, },
@ -667,7 +667,7 @@ var _ = Describe("SentPacketHandler", func() {
p := &Packet{ p := &Packet{
PacketNumber: 1, PacketNumber: 1,
Length: 42, Length: 42,
Frames: []frames.Frame{&frames.PingFrame{}}, Frames: []wire.Frame{&wire.PingFrame{}},
} }
err := handler.SentPacket(p) err := handler.SentPacket(p)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -680,7 +680,7 @@ var _ = Describe("SentPacketHandler", func() {
It("should call MaybeExitSlowStart and OnPacketAcked", func() { It("should call MaybeExitSlowStart and OnPacketAcked", func() {
handler.SentPacket(retransmittablePacket(1)) handler.SentPacket(retransmittablePacket(1))
handler.SentPacket(retransmittablePacket(2)) 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(err).NotTo(HaveOccurred())
Expect(cong.maybeExitSlowStart).To(BeTrue()) Expect(cong.maybeExitSlowStart).To(BeTrue())
Expect(cong.packetsAcked).To(BeEquivalentTo([][]interface{}{ Expect(cong.packetsAcked).To(BeEquivalentTo([][]interface{}{
@ -707,7 +707,7 @@ var _ = Describe("SentPacketHandler", func() {
Expect(handler.SendingAllowed()).To(BeTrue()) Expect(handler.SendingAllowed()).To(BeTrue())
err := handler.SentPacket(&Packet{ err := handler.SentPacket(&Packet{
PacketNumber: 1, PacketNumber: 1,
Frames: []frames.Frame{&frames.PingFrame{}}, Frames: []wire.Frame{&wire.PingFrame{}},
Length: protocol.DefaultTCPMSS + 1, Length: protocol.DefaultTCPMSS + 1,
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -723,7 +723,7 @@ var _ = Describe("SentPacketHandler", func() {
It("allows sending if there are retransmisisons outstanding", func() { It("allows sending if there are retransmisisons outstanding", func() {
err := handler.SentPacket(&Packet{ err := handler.SentPacket(&Packet{
PacketNumber: 1, PacketNumber: 1,
Frames: []frames.Frame{&frames.PingFrame{}}, Frames: []wire.Frame{&wire.PingFrame{}},
Length: protocol.DefaultTCPMSS + 1, Length: protocol.DefaultTCPMSS + 1,
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -775,7 +775,7 @@ var _ = Describe("SentPacketHandler", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(handler.lossTime.IsZero()).To(BeTrue()) 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(err).NotTo(HaveOccurred())
Expect(handler.lossTime.IsZero()).To(BeFalse()) Expect(handler.lossTime.IsZero()).To(BeFalse())
@ -798,7 +798,7 @@ var _ = Describe("SentPacketHandler", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(handler.lossTime.IsZero()).To(BeTrue()) 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(err).NotTo(HaveOccurred())
Expect(handler.lossTime.IsZero()).To(BeTrue()) Expect(handler.lossTime.IsZero()).To(BeTrue())
Expect(handler.GetAlarmTimeout().Sub(time.Now())).To(BeNumerically("~", handler.computeRTOTimeout(), time.Minute)) Expect(handler.GetAlarmTimeout().Sub(time.Now())).To(BeNumerically("~", handler.computeRTOTimeout(), time.Minute))

View file

@ -1,8 +1,8 @@
package ackhandler package ackhandler
import ( import (
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol" "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 // 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 largestLeastUnackedSent protocol.PacketNumber
nextLeastUnacked 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 s.nextLeastUnacked <= s.largestLeastUnackedSent {
if force { if force {
return s.lastStopWaitingFrame return s.lastStopWaitingFrame
@ -22,14 +22,14 @@ func (s *stopWaitingManager) GetStopWaitingFrame(force bool) *frames.StopWaiting
} }
s.largestLeastUnackedSent = s.nextLeastUnacked s.largestLeastUnackedSent = s.nextLeastUnacked
swf := &frames.StopWaitingFrame{ swf := &wire.StopWaitingFrame{
LeastUnacked: s.nextLeastUnacked, LeastUnacked: s.nextLeastUnacked,
} }
s.lastStopWaitingFrame = swf s.lastStopWaitingFrame = swf
return swf return swf
} }
func (s *stopWaitingManager) ReceivedAck(ack *frames.AckFrame) { func (s *stopWaitingManager) ReceivedAck(ack *wire.AckFrame) {
if ack.LargestAcked >= s.nextLeastUnacked { if ack.LargestAcked >= s.nextLeastUnacked {
s.nextLeastUnacked = ack.LargestAcked + 1 s.nextLeastUnacked = ack.LargestAcked + 1
} }

View file

@ -1,7 +1,7 @@
package ackhandler package ackhandler
import ( import (
"github.com/lucas-clemente/quic-go/frames" "github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -18,38 +18,38 @@ var _ = Describe("StopWaitingManager", func() {
}) })
It("returns a StopWaitingFrame, when a new ACK arrives", func() { It("returns a StopWaitingFrame, when a new ACK arrives", func() {
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10}) manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 11})) Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
}) })
It("does not decrease the LeastUnacked", func() { It("does not decrease the LeastUnacked", func() {
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 10}) manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&frames.AckFrame{LargestAcked: 9}) manager.ReceivedAck(&wire.AckFrame{LargestAcked: 9})
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 11})) Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
}) })
It("does not send the same StopWaitingFrame twice", func() { 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)).ToNot(BeNil())
Expect(manager.GetStopWaitingFrame(false)).To(BeNil()) Expect(manager.GetStopWaitingFrame(false)).To(BeNil())
}) })
It("gets the same StopWaitingFrame twice, if forced", func() { 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(false)).ToNot(BeNil())
Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil()) Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil())
Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil()) Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil())
}) })
It("increases the LeastUnacked when a retransmission is queued", func() { 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) 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() { 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) manager.QueuedRetransmissionForPacketNumber(9)
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&frames.StopWaitingFrame{LeastUnacked: 11})) Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
}) })
}) })

View file

@ -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)
}
}

View file

@ -6,15 +6,15 @@ import (
"fmt" "fmt"
"github.com/lucas-clemente/quic-go/ackhandler" "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/handshake"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
) )
type packedPacket struct { type packedPacket struct {
number protocol.PacketNumber number protocol.PacketNumber
raw []byte raw []byte
frames []frames.Frame frames []wire.Frame
encryptionLevel protocol.EncryptionLevel encryptionLevel protocol.EncryptionLevel
} }
@ -28,9 +28,9 @@ type packetPacker struct {
connectionParameters handshake.ConnectionParametersManager connectionParameters handshake.ConnectionParametersManager
streamFramer *streamFramer streamFramer *streamFramer
controlFrames []frames.Frame controlFrames []wire.Frame
stopWaiting *frames.StopWaitingFrame stopWaiting *wire.StopWaitingFrame
ackFrame *frames.AckFrame ackFrame *wire.AckFrame
leastUnacked protocol.PacketNumber leastUnacked protocol.PacketNumber
} }
@ -53,8 +53,8 @@ func newPacketPacker(connectionID protocol.ConnectionID,
} }
// PackConnectionClose packs a packet that ONLY contains a ConnectionCloseFrame // PackConnectionClose packs a packet that ONLY contains a ConnectionCloseFrame
func (p *packetPacker) PackConnectionClose(ccf *frames.ConnectionCloseFrame) (*packedPacket, error) { func (p *packetPacker) PackConnectionClose(ccf *wire.ConnectionCloseFrame) (*packedPacket, error) {
frames := []frames.Frame{ccf} frames := []wire.Frame{ccf}
encLevel, sealer := p.cryptoSetup.GetSealer() encLevel, sealer := p.cryptoSetup.GetSealer()
ph := p.getPublicHeader(encLevel) ph := p.getPublicHeader(encLevel)
raw, err := p.writeAndSealPacket(ph, frames, sealer) raw, err := p.writeAndSealPacket(ph, frames, sealer)
@ -72,7 +72,7 @@ func (p *packetPacker) PackAckPacket() (*packedPacket, error) {
} }
encLevel, sealer := p.cryptoSetup.GetSealer() encLevel, sealer := p.cryptoSetup.GetSealer()
ph := p.getPublicHeader(encLevel) ph := p.getPublicHeader(encLevel)
frames := []frames.Frame{p.ackFrame} frames := []wire.Frame{p.ackFrame}
if p.stopWaiting != nil { if p.stopWaiting != nil {
p.stopWaiting.PacketNumber = ph.PacketNumber p.stopWaiting.PacketNumber = ph.PacketNumber
p.stopWaiting.PacketNumberLen = ph.PacketNumberLen p.stopWaiting.PacketNumberLen = ph.PacketNumberLen
@ -104,7 +104,7 @@ func (p *packetPacker) PackHandshakeRetransmission(packet *ackhandler.Packet) (*
ph := p.getPublicHeader(packet.EncryptionLevel) ph := p.getPublicHeader(packet.EncryptionLevel)
p.stopWaiting.PacketNumber = ph.PacketNumber p.stopWaiting.PacketNumber = ph.PacketNumber
p.stopWaiting.PacketNumberLen = ph.PacketNumberLen p.stopWaiting.PacketNumberLen = ph.PacketNumberLen
frames := append([]frames.Frame{p.stopWaiting}, packet.Frames...) frames := append([]wire.Frame{p.stopWaiting}, packet.Frames...)
p.stopWaiting = nil p.stopWaiting = nil
raw, err := p.writeAndSealPacket(ph, frames, sealer) raw, err := p.writeAndSealPacket(ph, frames, sealer)
return &packedPacket{ return &packedPacket{
@ -171,7 +171,7 @@ func (p *packetPacker) packCryptoPacket() (*packedPacket, error) {
return nil, err return nil, err
} }
maxLen := protocol.MaxFrameAndPublicHeaderSize - protocol.NonForwardSecurePacketSizeReduction - publicHeaderLength 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) raw, err := p.writeAndSealPacket(publicHeader, frames, sealer)
if err != nil { if err != nil {
return nil, err return nil, err
@ -187,9 +187,9 @@ func (p *packetPacker) packCryptoPacket() (*packedPacket, error) {
func (p *packetPacker) composeNextPacket( func (p *packetPacker) composeNextPacket(
maxFrameSize protocol.ByteCount, maxFrameSize protocol.ByteCount,
canSendStreamFrames bool, canSendStreamFrames bool,
) ([]frames.Frame, error) { ) ([]wire.Frame, error) {
var payloadLength protocol.ByteCount var payloadLength protocol.ByteCount
var payloadFrames []frames.Frame var payloadFrames []wire.Frame
// STOP_WAITING and ACK will always fit // STOP_WAITING and ACK will always fit
if p.stopWaiting != nil { if p.stopWaiting != nil {
@ -253,11 +253,11 @@ func (p *packetPacker) composeNextPacket(
return payloadFrames, nil return payloadFrames, nil
} }
func (p *packetPacker) QueueControlFrame(frame frames.Frame) { func (p *packetPacker) QueueControlFrame(frame wire.Frame) {
switch f := frame.(type) { switch f := frame.(type) {
case *frames.StopWaitingFrame: case *wire.StopWaitingFrame:
p.stopWaiting = f p.stopWaiting = f
case *frames.AckFrame: case *wire.AckFrame:
p.ackFrame = f p.ackFrame = f
default: default:
p.controlFrames = append(p.controlFrames, f) p.controlFrames = append(p.controlFrames, f)
@ -287,7 +287,7 @@ func (p *packetPacker) getPublicHeader(encLevel protocol.EncryptionLevel) *Publi
func (p *packetPacker) writeAndSealPacket( func (p *packetPacker) writeAndSealPacket(
publicHeader *PublicHeader, publicHeader *PublicHeader,
payloadFrames []frames.Frame, payloadFrames []wire.Frame,
sealer handshake.Sealer, sealer handshake.Sealer,
) ([]byte, error) { ) ([]byte, error) {
raw := getPacketBuffer() raw := getPacketBuffer()

View file

@ -5,10 +5,10 @@ import (
"math" "math"
"github.com/lucas-clemente/quic-go/ackhandler" "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/handshake"
"github.com/lucas-clemente/quic-go/internal/mocks" "github.com/lucas-clemente/quic-go/internal/mocks"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -86,7 +86,7 @@ var _ = Describe("Packet packer", func() {
}) })
It("packs single packets", func() { It("packs single packets", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD}, 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() { It("stores the encryption level a packet was sealed with", func() {
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionForwardSecure packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionForwardSecure
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -143,7 +143,7 @@ var _ = Describe("Packet packer", func() {
}) })
It("packs a ConnectionClose", func() { It("packs a ConnectionClose", func() {
ccf := frames.ConnectionCloseFrame{ ccf := wire.ConnectionCloseFrame{
ErrorCode: 0x1337, ErrorCode: 0x1337,
ReasonPhrase: "foobar", ReasonPhrase: "foobar",
} }
@ -154,12 +154,12 @@ var _ = Describe("Packet packer", func() {
}) })
It("doesn't send any other frames when sending a ConnectionClose", func() { It("doesn't send any other frames when sending a ConnectionClose", func() {
ccf := frames.ConnectionCloseFrame{ ccf := wire.ConnectionCloseFrame{
ErrorCode: 0x1337, ErrorCode: 0x1337,
ReasonPhrase: "foobar", ReasonPhrase: "foobar",
} }
packer.controlFrames = []frames.Frame{&frames.WindowUpdateFrame{StreamID: 37}} packer.controlFrames = []wire.Frame{&wire.WindowUpdateFrame{StreamID: 37}}
streamFramer.AddFrameForRetransmission(&frames.StreamFrame{ streamFramer.AddFrameForRetransmission(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
}) })
@ -170,8 +170,8 @@ var _ = Describe("Packet packer", func() {
}) })
It("packs only control frames", func() { It("packs only control frames", func() {
packer.QueueControlFrame(&frames.RstStreamFrame{}) packer.QueueControlFrame(&wire.RstStreamFrame{})
packer.QueueControlFrame(&frames.WindowUpdateFrame{}) packer.QueueControlFrame(&wire.WindowUpdateFrame{})
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(p).ToNot(BeNil()) Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -180,11 +180,11 @@ var _ = Describe("Packet packer", func() {
}) })
It("increases the packet number", func() { It("increases the packet number", func() {
packer.QueueControlFrame(&frames.RstStreamFrame{}) packer.QueueControlFrame(&wire.RstStreamFrame{})
p1, err := packer.PackPacket() p1, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p1).ToNot(BeNil()) Expect(p1).ToNot(BeNil())
packer.QueueControlFrame(&frames.RstStreamFrame{}) packer.QueueControlFrame(&wire.RstStreamFrame{})
p2, err := packer.PackPacket() p2, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p2).ToNot(BeNil()) Expect(p2).ToNot(BeNil())
@ -193,8 +193,8 @@ var _ = Describe("Packet packer", func() {
It("packs a StopWaitingFrame first", func() { It("packs a StopWaitingFrame first", func() {
packer.packetNumberGenerator.next = 15 packer.packetNumberGenerator.next = 15
swf := &frames.StopWaitingFrame{LeastUnacked: 10} swf := &wire.StopWaitingFrame{LeastUnacked: 10}
packer.QueueControlFrame(&frames.RstStreamFrame{}) packer.QueueControlFrame(&wire.RstStreamFrame{})
packer.QueueControlFrame(swf) packer.QueueControlFrame(swf)
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -206,16 +206,16 @@ var _ = Describe("Packet packer", func() {
It("sets the LeastUnackedDelta length of a StopWaitingFrame", func() { It("sets the LeastUnackedDelta length of a StopWaitingFrame", func() {
packetNumber := protocol.PacketNumber(0xDECAFB) // will result in a 4 byte packet number packetNumber := protocol.PacketNumber(0xDECAFB) // will result in a 4 byte packet number
packer.packetNumberGenerator.next = packetNumber packer.packetNumberGenerator.next = packetNumber
swf := &frames.StopWaitingFrame{LeastUnacked: packetNumber - 0x100} swf := &wire.StopWaitingFrame{LeastUnacked: packetNumber - 0x100}
packer.QueueControlFrame(&frames.RstStreamFrame{}) packer.QueueControlFrame(&wire.RstStreamFrame{})
packer.QueueControlFrame(swf) packer.QueueControlFrame(swf)
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) 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() { It("does not pack a packet containing only a StopWaitingFrame", func() {
swf := &frames.StopWaitingFrame{LeastUnacked: 10} swf := &wire.StopWaitingFrame{LeastUnacked: 10}
packer.QueueControlFrame(swf) packer.QueueControlFrame(swf)
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(p).To(BeNil()) 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() { 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() p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil()) 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() { It("adds the version flag to the public header before the crypto handshake is finished", func() {
packer.perspective = protocol.PerspectiveClient packer.perspective = protocol.PerspectiveClient
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure 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.connectionID = 0x1337
packer.version = 123 packer.version = 123
p, err := packer.PackPacket() 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() { It("doesn't add the version flag to the public header for forward-secure packets", func() {
packer.perspective = protocol.PerspectiveClient packer.perspective = protocol.PerspectiveClient
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionForwardSecure 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 packer.connectionID = 0x1337
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -258,11 +258,11 @@ var _ = Describe("Packet packer", func() {
}) })
It("packs many control frames into 1 packets", func() { It("packs many control frames into 1 packets", func() {
f := &frames.AckFrame{LargestAcked: 1} f := &wire.AckFrame{LargestAcked: 1}
b := &bytes.Buffer{} b := &bytes.Buffer{}
f.Write(b, protocol.VersionWhatever) f.Write(b, protocol.VersionWhatever)
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / b.Len() maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / b.Len()
var controlFrames []frames.Frame var controlFrames []wire.Frame
for i := 0; i < maxFramesPerPacket; i++ { for i := 0; i < maxFramesPerPacket; i++ {
controlFrames = append(controlFrames, f) 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() { 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, StreamID: 0x1337,
} }
minLength, _ := blockedFrame.MinLength(0) minLength, _ := blockedFrame.MinLength(0)
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / int(minLength) maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / int(minLength)
var controlFrames []frames.Frame var controlFrames []wire.Frame
for i := 0; i < maxFramesPerPacket+10; i++ { for i := 0; i < maxFramesPerPacket+10; i++ {
controlFrames = append(controlFrames, blockedFrame) controlFrames = append(controlFrames, blockedFrame)
} }
@ -300,7 +300,7 @@ var _ = Describe("Packet packer", func() {
Expect(p).To(BeNil()) Expect(p).To(BeNil())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packer.packetNumberGenerator.Peek()).To(Equal(protocol.PacketNumber(1))) Expect(packer.packetNumberGenerator.Peek()).To(Equal(protocol.PacketNumber(1)))
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD}, Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
} }
@ -314,7 +314,7 @@ var _ = Describe("Packet packer", func() {
Context("Stream Frame handling", func() { Context("Stream Frame handling", func() {
It("does not splits a stream frame with maximum size", func() { It("does not splits a stream frame with maximum size", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 1, Offset: 1,
StreamID: 5, StreamID: 5,
DataLenPresent: false, DataLenPresent: false,
@ -326,7 +326,7 @@ var _ = Describe("Packet packer", func() {
payloadFrames, err := packer.composeNextPacket(maxFrameSize, true) payloadFrames, err := packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(payloadFrames).To(HaveLen(1)) 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) payloadFrames, err = packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(payloadFrames).To(BeEmpty()) 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() { It("correctly handles a stream frame with one byte less than maximum size", func() {
maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - (1 + 1 + 2) - 1 maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - (1 + 1 + 2) - 1
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Offset: 1, Offset: 1,
Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)), Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)),
} }
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Offset: 1, Offset: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
@ -350,23 +350,23 @@ var _ = Describe("Packet packer", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize - 1))) Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize - 1)))
Expect(p.frames).To(HaveLen(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() p, err = packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.frames).To(HaveLen(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())
}) })
It("packs multiple small stream frames into single packet", func() { It("packs multiple small stream frames into single packet", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD}, Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
} }
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xBE, 0xEF, 0x13, 0x37}, Data: []byte{0xBE, 0xEF, 0x13, 0x37},
} }
f3 := &frames.StreamFrame{ f3 := &wire.StreamFrame{
StreamID: 3, StreamID: 3,
Data: []byte{0xCA, 0xFE}, Data: []byte{0xCA, 0xFE},
} }
@ -381,16 +381,16 @@ var _ = Describe("Packet packer", func() {
f2.Write(b, 0) f2.Write(b, 0)
f3.Write(b, 0) f3.Write(b, 0)
Expect(p.frames).To(HaveLen(3)) Expect(p.frames).To(HaveLen(3))
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeTrue()) Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeTrue())
Expect(p.frames[1].(*frames.StreamFrame).DataLenPresent).To(BeTrue()) Expect(p.frames[1].(*wire.StreamFrame).DataLenPresent).To(BeTrue())
Expect(p.frames[2].(*frames.StreamFrame).DataLenPresent).To(BeFalse()) Expect(p.frames[2].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
Expect(p.raw).To(ContainSubstring(string(f1.Data))) Expect(p.raw).To(ContainSubstring(string(f1.Data)))
Expect(p.raw).To(ContainSubstring(string(f2.Data))) Expect(p.raw).To(ContainSubstring(string(f2.Data)))
Expect(p.raw).To(ContainSubstring(string(f3.Data))) Expect(p.raw).To(ContainSubstring(string(f3.Data)))
}) })
It("splits one stream frame larger than maximum size", func() { It("splits one stream frame larger than maximum size", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 7, StreamID: 7,
Offset: 1, Offset: 1,
} }
@ -401,13 +401,13 @@ var _ = Describe("Packet packer", func() {
payloadFrames, err := packer.composeNextPacket(maxFrameSize, true) payloadFrames, err := packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(payloadFrames).To(HaveLen(1)) Expect(payloadFrames).To(HaveLen(1))
Expect(payloadFrames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse()) Expect(payloadFrames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
Expect(payloadFrames[0].(*frames.StreamFrame).Data).To(HaveLen(int(maxStreamFrameDataLen))) Expect(payloadFrames[0].(*wire.StreamFrame).Data).To(HaveLen(int(maxStreamFrameDataLen)))
payloadFrames, err = packer.composeNextPacket(maxFrameSize, true) payloadFrames, err = packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(payloadFrames).To(HaveLen(1)) Expect(payloadFrames).To(HaveLen(1))
Expect(payloadFrames[0].(*frames.StreamFrame).Data).To(HaveLen(200)) Expect(payloadFrames[0].(*wire.StreamFrame).Data).To(HaveLen(200))
Expect(payloadFrames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse()) Expect(payloadFrames[0].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
payloadFrames, err = packer.composeNextPacket(maxFrameSize, true) payloadFrames, err = packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(payloadFrames).To(BeEmpty()) 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() { It("packs 2 stream frames that are too big for one packet correctly", func() {
maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - (1 + 1 + 2) maxStreamFrameDataLen := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLen - (1 + 1 + 2)
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+100), Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+100),
Offset: 1, Offset: 1,
} }
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+100), Data: bytes.Repeat([]byte{'f'}, int(maxStreamFrameDataLen)+100),
Offset: 1, Offset: 1,
@ -430,17 +430,17 @@ var _ = Describe("Packet packer", func() {
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.frames).To(HaveLen(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())
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize))) Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize)))
p, err = packer.PackPacket() p, err = packer.PackPacket()
Expect(p.frames).To(HaveLen(2)) Expect(p.frames).To(HaveLen(2))
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeTrue()) Expect(p.frames[0].(*wire.StreamFrame).DataLenPresent).To(BeTrue())
Expect(p.frames[1].(*frames.StreamFrame).DataLenPresent).To(BeFalse()) Expect(p.frames[1].(*wire.StreamFrame).DataLenPresent).To(BeFalse())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize))) Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize)))
p, err = packer.PackPacket() p, err = packer.PackPacket()
Expect(p.frames).To(HaveLen(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())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil()) Expect(p).ToNot(BeNil())
p, err = packer.PackPacket() 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() { 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, StreamID: 5,
Offset: 1, Offset: 1,
} }
@ -463,7 +463,7 @@ var _ = Describe("Packet packer", func() {
}) })
It("splits a stream frame larger than the maximum size", func() { It("splits a stream frame larger than the maximum size", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Offset: 1, Offset: 1,
} }
@ -481,7 +481,7 @@ var _ = Describe("Packet packer", func() {
It("refuses to send unencrypted stream data on a data stream", func() { It("refuses to send unencrypted stream data on a data stream", func() {
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 3, StreamID: 3,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -494,7 +494,7 @@ var _ = Describe("Packet packer", func() {
It("sends non forward-secure data as the client", func() { It("sends non forward-secure data as the client", func() {
packer.perspective = protocol.PerspectiveClient packer.perspective = protocol.PerspectiveClient
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -507,7 +507,7 @@ var _ = Describe("Packet packer", func() {
It("does not send non forward-secure data as the server", func() { It("does not send non forward-secure data as the server", func() {
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionSecure
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -524,7 +524,7 @@ var _ = Describe("Packet packer", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.encryptionLevel).To(Equal(protocol.EncryptionUnencrypted)) Expect(p.encryptionLevel).To(Equal(protocol.EncryptionUnencrypted))
Expect(p.frames).To(HaveLen(1)) 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() { It("sends encrypted stream data on the crypto stream", func() {
@ -534,38 +534,38 @@ var _ = Describe("Packet packer", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.encryptionLevel).To(Equal(protocol.EncryptionSecure)) Expect(p.encryptionLevel).To(Equal(protocol.EncryptionSecure))
Expect(p.frames).To(HaveLen(1)) 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() { It("does not pack stream frames if not allowed", func() {
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted
packer.QueueControlFrame(&frames.AckFrame{}) packer.QueueControlFrame(&wire.AckFrame{})
streamFramer.AddFrameForRetransmission(&frames.StreamFrame{StreamID: 3, Data: []byte("foobar")}) streamFramer.AddFrameForRetransmission(&wire.StreamFrame{StreamID: 3, Data: []byte("foobar")})
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p.frames).To(HaveLen(1)) 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() { Context("Blocked frames", func() {
It("queues a BLOCKED frame", func() { It("queues a BLOCKED frame", func() {
length := 100 length := 100
streamFramer.blockedFrameQueue = []*frames.BlockedFrame{{StreamID: 5}} streamFramer.blockedFrameQueue = []*wire.BlockedFrame{{StreamID: 5}}
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: bytes.Repeat([]byte{'f'}, length), Data: bytes.Repeat([]byte{'f'}, length),
} }
streamFramer.AddFrameForRetransmission(f) streamFramer.AddFrameForRetransmission(f)
_, err := packer.composeNextPacket(maxFrameSize, true) _, err := packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) 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() { It("removes the dataLen attribute from the last StreamFrame, even if it queued a BLOCKED frame", func() {
length := 100 length := 100
streamFramer.blockedFrameQueue = []*frames.BlockedFrame{{StreamID: 5}} streamFramer.blockedFrameQueue = []*wire.BlockedFrame{{StreamID: 5}}
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: bytes.Repeat([]byte{'f'}, length), Data: bytes.Repeat([]byte{'f'}, length),
} }
@ -573,31 +573,31 @@ var _ = Describe("Packet packer", func() {
p, err := packer.composeNextPacket(maxFrameSize, true) p, err := packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(p).To(HaveLen(1)) 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() { It("packs a connection-level BlockedFrame", func() {
streamFramer.blockedFrameQueue = []*frames.BlockedFrame{{StreamID: 0}} streamFramer.blockedFrameQueue = []*wire.BlockedFrame{{StreamID: 0}}
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
streamFramer.AddFrameForRetransmission(f) streamFramer.AddFrameForRetransmission(f)
_, err := packer.composeNextPacket(maxFrameSize, true) _, err := packer.composeNextPacket(maxFrameSize, true)
Expect(err).ToNot(HaveOccurred()) 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() { It("returns nil if we only have a single STOP_WAITING", func() {
packer.QueueControlFrame(&frames.StopWaitingFrame{}) packer.QueueControlFrame(&wire.StopWaitingFrame{})
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(p).To(BeNil()) Expect(p).To(BeNil())
}) })
It("packs a single ACK", func() { It("packs a single ACK", func() {
ack := &frames.AckFrame{LargestAcked: 42} ack := &wire.AckFrame{LargestAcked: 42}
packer.QueueControlFrame(ack) packer.QueueControlFrame(ack)
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).NotTo(HaveOccurred()) 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() { 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) packer.QueueControlFrame(ack)
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).NotTo(HaveOccurred()) 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() { 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) packer.QueueControlFrame(wuf)
p, err := packer.PackPacket() p, err := packer.PackPacket()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -623,8 +623,8 @@ var _ = Describe("Packet packer", func() {
}) })
Context("retransmitting of handshake packets", func() { Context("retransmitting of handshake packets", func() {
swf := &frames.StopWaitingFrame{LeastUnacked: 1} swf := &wire.StopWaitingFrame{LeastUnacked: 1}
sf := &frames.StreamFrame{ sf := &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -636,7 +636,7 @@ var _ = Describe("Packet packer", func() {
It("packs a retransmission for a packet sent with no encryption", func() { It("packs a retransmission for a packet sent with no encryption", func() {
packet := &ackhandler.Packet{ packet := &ackhandler.Packet{
EncryptionLevel: protocol.EncryptionUnencrypted, EncryptionLevel: protocol.EncryptionUnencrypted,
Frames: []frames.Frame{sf}, Frames: []wire.Frame{sf},
} }
p, err := packer.PackHandshakeRetransmission(packet) p, err := packer.PackHandshakeRetransmission(packet)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -650,7 +650,7 @@ var _ = Describe("Packet packer", func() {
packer.cryptoSetup.(*mockCryptoSetup).divNonce = nonce packer.cryptoSetup.(*mockCryptoSetup).divNonce = nonce
packet := &ackhandler.Packet{ packet := &ackhandler.Packet{
EncryptionLevel: protocol.EncryptionSecure, EncryptionLevel: protocol.EncryptionSecure,
Frames: []frames.Frame{sf}, Frames: []wire.Frame{sf},
} }
p, err := packer.PackHandshakeRetransmission(packet) p, err := packer.PackHandshakeRetransmission(packet)
Expect(err).ToNot(HaveOccurred()) 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() { It("includes the diversification nonce on packets sent with initial encryption", func() {
packet := &ackhandler.Packet{ packet := &ackhandler.Packet{
EncryptionLevel: protocol.EncryptionSecure, EncryptionLevel: protocol.EncryptionSecure,
Frames: []frames.Frame{sf}, Frames: []wire.Frame{sf},
} }
p, err := packer.PackHandshakeRetransmission(packet) p, err := packer.PackHandshakeRetransmission(packet)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -677,8 +677,8 @@ var _ = Describe("Packet packer", func() {
It("refuses to send a packet larger than MaxPacketSize", func() { It("refuses to send a packet larger than MaxPacketSize", func() {
packet := &ackhandler.Packet{ packet := &ackhandler.Packet{
EncryptionLevel: protocol.EncryptionSecure, EncryptionLevel: protocol.EncryptionSecure,
Frames: []frames.Frame{ Frames: []wire.Frame{
&frames.StreamFrame{ &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Data: bytes.Repeat([]byte{'f'}, int(protocol.MaxPacketSize-5)), Data: bytes.Repeat([]byte{'f'}, int(protocol.MaxPacketSize-5)),
}, },
@ -707,20 +707,20 @@ var _ = Describe("Packet packer", func() {
Context("packing ACK packets", func() { Context("packing ACK packets", func() {
It("packs ACK packets", func() { It("packs ACK packets", func() {
packer.QueueControlFrame(&frames.AckFrame{}) packer.QueueControlFrame(&wire.AckFrame{})
p, err := packer.PackAckPacket() p, err := packer.PackAckPacket()
Expect(err).NotTo(HaveOccurred()) 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() { It("packs ACK packets with SWFs", func() {
packer.QueueControlFrame(&frames.AckFrame{}) packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&frames.StopWaitingFrame{}) packer.QueueControlFrame(&wire.StopWaitingFrame{})
p, err := packer.PackAckPacket() p, err := packer.PackAckPacket()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(p.frames).To(Equal([]frames.Frame{ Expect(p.frames).To(Equal([]wire.Frame{
&frames.AckFrame{DelayTime: math.MaxInt64}, &wire.AckFrame{DelayTime: math.MaxInt64},
&frames.StopWaitingFrame{PacketNumber: 1, PacketNumberLen: 2}, &wire.StopWaitingFrame{PacketNumber: 1, PacketNumberLen: 2},
})) }))
}) })
}) })

View file

@ -5,14 +5,14 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
"github.com/lucas-clemente/quic-go/wire"
) )
type unpackedPacket struct { type unpackedPacket struct {
encryptionLevel protocol.EncryptionLevel encryptionLevel protocol.EncryptionLevel
frames []frames.Frame frames []wire.Frame
} }
type quicAEAD interface { type quicAEAD interface {
@ -38,7 +38,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
return nil, qerr.MissingPayload return nil, qerr.MissingPayload
} }
fs := make([]frames.Frame, 0, 2) fs := make([]wire.Frame, 0, 2)
// Read all frames in the packet // Read all frames in the packet
for r.Len() > 0 { for r.Len() > 0 {
@ -48,19 +48,19 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
} }
r.UnreadByte() r.UnreadByte()
var frame frames.Frame var frame wire.Frame
if typeByte&0x80 == 0x80 { if typeByte&0x80 == 0x80 {
frame, err = frames.ParseStreamFrame(r, u.version) frame, err = wire.ParseStreamFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidStreamData, err.Error()) err = qerr.Error(qerr.InvalidStreamData, err.Error())
} else { } else {
streamID := frame.(*frames.StreamFrame).StreamID streamID := frame.(*wire.StreamFrame).StreamID
if streamID != 1 && encryptionLevel <= protocol.EncryptionUnencrypted { if streamID != 1 && encryptionLevel <= protocol.EncryptionUnencrypted {
err = qerr.Error(qerr.UnencryptedStreamData, fmt.Sprintf("received unencrypted stream data on stream %d", streamID)) err = qerr.Error(qerr.UnencryptedStreamData, fmt.Sprintf("received unencrypted stream data on stream %d", streamID))
} }
} }
} else if typeByte&0xc0 == 0x40 { } else if typeByte&0xc0 == 0x40 {
frame, err = frames.ParseAckFrame(r, u.version) frame, err = wire.ParseAckFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidAckData, err.Error()) err = qerr.Error(qerr.InvalidAckData, err.Error())
} }
@ -69,37 +69,37 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
} else { } else {
switch typeByte { switch typeByte {
case 0x01: case 0x01:
frame, err = frames.ParseRstStreamFrame(r, u.version) frame, err = wire.ParseRstStreamFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidRstStreamData, err.Error()) err = qerr.Error(qerr.InvalidRstStreamData, err.Error())
} }
case 0x02: case 0x02:
frame, err = frames.ParseConnectionCloseFrame(r, u.version) frame, err = wire.ParseConnectionCloseFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidConnectionCloseData, err.Error()) err = qerr.Error(qerr.InvalidConnectionCloseData, err.Error())
} }
case 0x03: case 0x03:
frame, err = frames.ParseGoawayFrame(r, u.version) frame, err = wire.ParseGoawayFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidGoawayData, err.Error()) err = qerr.Error(qerr.InvalidGoawayData, err.Error())
} }
case 0x04: case 0x04:
frame, err = frames.ParseWindowUpdateFrame(r, u.version) frame, err = wire.ParseWindowUpdateFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidWindowUpdateData, err.Error()) err = qerr.Error(qerr.InvalidWindowUpdateData, err.Error())
} }
case 0x05: case 0x05:
frame, err = frames.ParseBlockedFrame(r, u.version) frame, err = wire.ParseBlockedFrame(r, u.version)
if err != nil { if err != nil {
err = qerr.Error(qerr.InvalidBlockedData, err.Error()) err = qerr.Error(qerr.InvalidBlockedData, err.Error())
} }
case 0x06: 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 { if err != nil {
err = qerr.Error(qerr.InvalidStopWaitingData, err.Error()) err = qerr.Error(qerr.InvalidStopWaitingData, err.Error())
} }
case 0x07: case 0x07:
frame, err = frames.ParsePingFrame(r, u.version) frame, err = wire.ParsePingFrame(r, u.version)
default: default:
err = qerr.Error(qerr.InvalidFrameData, fmt.Sprintf("unknown type byte 0x%x", typeByte)) err = qerr.Error(qerr.InvalidFrameData, fmt.Sprintf("unknown type byte 0x%x", typeByte))
} }

View file

@ -4,9 +4,9 @@ import (
"bytes" "bytes"
"github.com/lucas-clemente/quic-go/crypto" "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/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "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() { 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) err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes()) setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) 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() { It("saves the encryption level", func() {
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"} f := &wire.ConnectionCloseFrame{ReasonPhrase: "foo"}
err := f.Write(buf, 0) err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes()) setData(buf.Bytes())
@ -75,7 +75,7 @@ var _ = Describe("Packet unpacker", func() {
It("unpacks ACK frames", func() { It("unpacks ACK frames", func() {
unpacker.version = protocol.VersionWhatever unpacker.version = protocol.VersionWhatever
f := &frames.AckFrame{ f := &wire.AckFrame{
LargestAcked: 0x13, LargestAcked: 0x13,
LowestAcked: 1, LowestAcked: 1,
} }
@ -85,7 +85,7 @@ var _ = Describe("Packet unpacker", func() {
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(HaveLen(1)) Expect(packet.frames).To(HaveLen(1))
readFrame := packet.frames[0].(*frames.AckFrame) readFrame := packet.frames[0].(*wire.AckFrame)
Expect(readFrame).ToNot(BeNil()) Expect(readFrame).ToNot(BeNil())
Expect(readFrame.LargestAcked).To(Equal(protocol.PacketNumber(0x13))) 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() { It("handles PADDING between two other frames", func() {
f := &frames.PingFrame{} f := &wire.PingFrame{}
err := f.Write(buf, protocol.VersionWhatever) err := f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
_, err = buf.Write(bytes.Repeat([]byte{0}, 10)) // 10 bytes PADDING _, 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}) 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) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{ Expect(packet.frames).To(Equal([]wire.Frame{
&frames.RstStreamFrame{ &wire.RstStreamFrame{
StreamID: 0xDEADBEEF, StreamID: 0xDEADBEEF,
ByteOffset: 0xDECAFBAD11223344, ByteOffset: 0xDECAFBAD11223344,
ErrorCode: 0x13371234, ErrorCode: 0x13371234,
@ -131,13 +131,13 @@ var _ = Describe("Packet unpacker", func() {
}) })
It("unpacks CONNECTION_CLOSE frames", func() { It("unpacks CONNECTION_CLOSE frames", func() {
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"} f := &wire.ConnectionCloseFrame{ReasonPhrase: "foo"}
err := f.Write(buf, 0) err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes()) setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) 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() { It("accepts GOAWAY frames", func() {
@ -150,8 +150,8 @@ var _ = Describe("Packet unpacker", func() {
}) })
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{ Expect(packet.frames).To(Equal([]wire.Frame{
&frames.GoawayFrame{ &wire.GoawayFrame{
ErrorCode: 1, ErrorCode: 1,
LastGoodStream: 2, LastGoodStream: 2,
ReasonPhrase: "foo", 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}) setData([]byte{0x04, 0xEF, 0xBE, 0xAD, 0xDE, 0x37, 0x13, 0, 0, 0, 0, 0xFE, 0xCA})
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{ Expect(packet.frames).To(Equal([]wire.Frame{
&frames.WindowUpdateFrame{ &wire.WindowUpdateFrame{
StreamID: 0xDEADBEEF, StreamID: 0xDEADBEEF,
ByteOffset: 0xCAFE000000001337, ByteOffset: 0xCAFE000000001337,
}, },
@ -175,10 +175,8 @@ var _ = Describe("Packet unpacker", func() {
setData([]byte{0x05, 0xEF, 0xBE, 0xAD, 0xDE}) setData([]byte{0x05, 0xEF, 0xBE, 0xAD, 0xDE})
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{ Expect(packet.frames).To(Equal([]wire.Frame{
&frames.BlockedFrame{ &wire.BlockedFrame{StreamID: 0xDEADBEEF},
StreamID: 0xDEADBEEF,
},
})) }))
}) })
@ -186,10 +184,8 @@ var _ = Describe("Packet unpacker", func() {
setData([]byte{0x06, 0x03}) setData([]byte{0x06, 0x03})
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{ Expect(packet.frames).To(Equal([]wire.Frame{
&frames.StopWaitingFrame{ &wire.StopWaitingFrame{LeastUnacked: 7},
LeastUnacked: 7,
},
})) }))
}) })
@ -197,8 +193,8 @@ var _ = Describe("Packet unpacker", func() {
setData([]byte{0x07}) setData([]byte{0x07})
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{ Expect(packet.frames).To(Equal([]wire.Frame{
&frames.PingFrame{}, &wire.PingFrame{},
})) }))
}) })
@ -228,7 +224,7 @@ var _ = Describe("Packet unpacker", func() {
Context("unpacking STREAM frames", func() { Context("unpacking STREAM frames", func() {
It("unpacks unencrypted STREAM frames on stream 1", func() { It("unpacks unencrypted STREAM frames on stream 1", func() {
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -237,12 +233,12 @@ var _ = Describe("Packet unpacker", func() {
setData(buf.Bytes()) setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) 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() { It("unpacks encrypted STREAM frames on stream 1", func() {
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionSecure unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionSecure
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -251,12 +247,12 @@ var _ = Describe("Packet unpacker", func() {
setData(buf.Bytes()) setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data) packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred()) 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() { It("does not unpack unencrypted STREAM frames on higher streams", func() {
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 3, StreamID: 3,
Data: []byte("foobar"), Data: []byte("foobar"),
} }

View file

@ -12,11 +12,11 @@ import (
"github.com/lucas-clemente/quic-go/ackhandler" "github.com/lucas-clemente/quic-go/ackhandler"
"github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/congestion"
"github.com/lucas-clemente/quic-go/flowcontrol" "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/handshake"
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
"github.com/lucas-clemente/quic-go/wire"
) )
type unpacker interface { type unpacker interface {
@ -313,7 +313,7 @@ runLoop:
if s.config.KeepAlive && s.handshakeComplete && time.Since(s.lastNetworkActivityTime) >= s.idleTimeout()/2 { 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 // 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 s.keepAlivePingSent = true
} }
@ -434,29 +434,29 @@ func (s *session) handlePacketImpl(p *receivedPacket) error {
return s.handleFrames(packet.frames) 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 { for _, ff := range fs {
var err error var err error
frames.LogFrame(ff, false) wire.LogFrame(ff, false)
switch frame := ff.(type) { switch frame := ff.(type) {
case *frames.StreamFrame: case *wire.StreamFrame:
err = s.handleStreamFrame(frame) err = s.handleStreamFrame(frame)
case *frames.AckFrame: case *wire.AckFrame:
err = s.handleAckFrame(frame) err = s.handleAckFrame(frame)
case *frames.ConnectionCloseFrame: case *wire.ConnectionCloseFrame:
s.closeRemote(qerr.Error(frame.ErrorCode, frame.ReasonPhrase)) s.closeRemote(qerr.Error(frame.ErrorCode, frame.ReasonPhrase))
case *frames.GoawayFrame: case *wire.GoawayFrame:
err = errors.New("unimplemented: handling GOAWAY frames") err = errors.New("unimplemented: handling GOAWAY frames")
case *frames.StopWaitingFrame: case *wire.StopWaitingFrame:
// LeastUnacked is guaranteed to have LeastUnacked > 0 // LeastUnacked is guaranteed to have LeastUnacked > 0
// therefore this will never underflow // therefore this will never underflow
s.receivedPacketHandler.SetLowerLimit(frame.LeastUnacked - 1) s.receivedPacketHandler.SetLowerLimit(frame.LeastUnacked - 1)
case *frames.RstStreamFrame: case *wire.RstStreamFrame:
err = s.handleRstStreamFrame(frame) err = s.handleRstStreamFrame(frame)
case *frames.WindowUpdateFrame: case *wire.WindowUpdateFrame:
err = s.handleWindowUpdateFrame(frame) err = s.handleWindowUpdateFrame(frame)
case *frames.BlockedFrame: case *wire.BlockedFrame:
case *frames.PingFrame: case *wire.PingFrame:
default: default:
return errors.New("Session BUG: unexpected frame type") 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) str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
if err != nil { if err != nil {
return err return err
@ -501,7 +501,7 @@ func (s *session) handleStreamFrame(frame *frames.StreamFrame) error {
return str.AddStreamFrame(frame) return str.AddStreamFrame(frame)
} }
func (s *session) handleWindowUpdateFrame(frame *frames.WindowUpdateFrame) error { func (s *session) handleWindowUpdateFrame(frame *wire.WindowUpdateFrame) error {
if frame.StreamID != 0 { if frame.StreamID != 0 {
str, err := s.streamsMap.GetOrOpenStream(frame.StreamID) str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
if err != nil { if err != nil {
@ -515,7 +515,7 @@ func (s *session) handleWindowUpdateFrame(frame *frames.WindowUpdateFrame) error
return err 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) str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
if err != nil { if err != nil {
return err return err
@ -528,7 +528,7 @@ func (s *session) handleRstStreamFrame(frame *frames.RstStreamFrame) error {
return s.flowControlManager.ResetStream(frame.StreamID, frame.ByteOffset) 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) 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 // resend the frames that were in the packet
for _, frame := range retransmitPacket.GetFramesForRetransmission() { for _, frame := range retransmitPacket.GetFramesForRetransmission() {
switch f := frame.(type) { switch f := frame.(type) {
case *frames.StreamFrame: case *wire.StreamFrame:
s.streamFramer.AddFrameForRetransmission(f) 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 // 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) currentOffset, err := s.flowControlManager.GetReceiveWindow(f.StreamID)
if err == nil && f.ByteOffset >= currentOffset { if err == nil && f.ByteOffset >= currentOffset {
@ -671,7 +671,7 @@ func (s *session) sendPacket() error {
} }
// add a retransmittable frame // add a retransmittable frame
if s.sentPacketHandler.ShouldSendRetransmittablePacket() { if s.sentPacketHandler.ShouldSendRetransmittablePacket() {
s.packer.QueueControlFrame(&frames.PingFrame{}) s.packer.QueueControlFrame(&wire.PingFrame{})
} }
packet, err := s.packer.PackPacket() packet, err := s.packer.PackPacket()
if err != nil || packet == nil { if err != nil || packet == nil {
@ -707,7 +707,7 @@ func (s *session) sendPackedPacket(packet *packedPacket) error {
func (s *session) sendConnectionClose(quicErr *qerr.QuicError) error { func (s *session) sendConnectionClose(quicErr *qerr.QuicError) error {
s.packer.SetLeastUnacked(s.sentPacketHandler.GetLeastUnacked()) s.packer.SetLeastUnacked(s.sentPacketHandler.GetLeastUnacked())
packet, err := s.packer.PackConnectionClose(&frames.ConnectionCloseFrame{ packet, err := s.packer.PackConnectionClose(&wire.ConnectionCloseFrame{
ErrorCode: quicErr.ErrorCode, ErrorCode: quicErr.ErrorCode,
ReasonPhrase: quicErr.ErrorMessage, 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) 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 { 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) { func (s *session) queueResetStreamFrame(id protocol.StreamID, offset protocol.ByteCount) {
s.packer.QueueControlFrame(&frames.RstStreamFrame{ s.packer.QueueControlFrame(&wire.RstStreamFrame{
StreamID: id, StreamID: id,
ByteOffset: offset, ByteOffset: offset,
}) })
@ -830,11 +830,11 @@ func (s *session) tryDecryptingQueuedPackets() {
s.undecryptablePackets = s.undecryptablePackets[:0] s.undecryptablePackets = s.undecryptablePackets[:0]
} }
func (s *session) getWindowUpdateFrames() []*frames.WindowUpdateFrame { func (s *session) getWindowUpdateFrames() []*wire.WindowUpdateFrame {
updates := s.flowControlManager.GetWindowUpdates() updates := s.flowControlManager.GetWindowUpdates()
res := make([]*frames.WindowUpdateFrame, len(updates)) res := make([]*wire.WindowUpdateFrame, len(updates))
for i, u := range 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 return res
} }

View file

@ -16,13 +16,13 @@ import (
"github.com/lucas-clemente/quic-go/ackhandler" "github.com/lucas-clemente/quic-go/ackhandler"
"github.com/lucas-clemente/quic-go/crypto" "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/handshake"
"github.com/lucas-clemente/quic-go/internal/mocks" "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/mocks/mocks_fc"
"github.com/lucas-clemente/quic-go/internal/testdata" "github.com/lucas-clemente/quic-go/internal/testdata"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
"github.com/lucas-clemente/quic-go/wire"
) )
type mockConnection struct { type mockConnection struct {
@ -83,7 +83,7 @@ func (h *mockSentPacketHandler) SentPacket(packet *ackhandler.Packet) error {
return nil 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 return nil
} }
@ -97,9 +97,9 @@ func (h *mockSentPacketHandler) ShouldSendRetransmittablePacket() bool {
return b return b
} }
func (h *mockSentPacketHandler) GetStopWaitingFrame(force bool) *frames.StopWaitingFrame { func (h *mockSentPacketHandler) GetStopWaitingFrame(force bool) *wire.StopWaitingFrame {
h.requestedStopWaiting = true h.requestedStopWaiting = true
return &frames.StopWaitingFrame{LeastUnacked: 0x1337} return &wire.StopWaitingFrame{LeastUnacked: 0x1337}
} }
func (h *mockSentPacketHandler) DequeuePacketForRetransmission() *ackhandler.Packet { func (h *mockSentPacketHandler) DequeuePacketForRetransmission() *ackhandler.Packet {
@ -118,11 +118,11 @@ func newMockSentPacketHandler() ackhandler.SentPacketHandler {
var _ ackhandler.SentPacketHandler = &mockSentPacketHandler{} var _ ackhandler.SentPacketHandler = &mockSentPacketHandler{}
type mockReceivedPacketHandler struct { type mockReceivedPacketHandler struct {
nextAckFrame *frames.AckFrame nextAckFrame *wire.AckFrame
ackAlarm time.Time ackAlarm time.Time
} }
func (m *mockReceivedPacketHandler) GetAckFrame() *frames.AckFrame { func (m *mockReceivedPacketHandler) GetAckFrame() *wire.AckFrame {
f := m.nextAckFrame f := m.nextAckFrame
m.nextAckFrame = nil m.nextAckFrame = nil
return f return f
@ -263,7 +263,7 @@ var _ = Describe("Session", func() {
Context("when handling stream frames", func() { Context("when handling stream frames", func() {
It("makes new streams", func() { It("makes new streams", func() {
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xde, 0xca, 0xfb, 0xad}, Data: []byte{0xde, 0xca, 0xfb, 0xad},
}) })
@ -279,7 +279,7 @@ var _ = Describe("Session", func() {
It("does not reject existing streams with even StreamIDs", func() { It("does not reject existing streams with even StreamIDs", func() {
_, err := sess.GetOrOpenStream(5) _, err := sess.GetOrOpenStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = sess.handleStreamFrame(&frames.StreamFrame{ err = sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xde, 0xca, 0xfb, 0xad}, Data: []byte{0xde, 0xca, 0xfb, 0xad},
}) })
@ -287,12 +287,12 @@ var _ = Describe("Session", func() {
}) })
It("handles existing streams", func() { It("handles existing streams", func() {
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xde, 0xca}, Data: []byte{0xde, 0xca},
}) })
numOpenStreams := len(sess.streamsMap.openStreams) numOpenStreams := len(sess.streamsMap.openStreams)
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Offset: 2, Offset: 2,
Data: []byte{0xfb, 0xad}, Data: []byte{0xfb, 0xad},
@ -317,7 +317,7 @@ var _ = Describe("Session", func() {
}) })
It("does not delete streams with FIN bit", func() { It("does not delete streams with FIN bit", func() {
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xde, 0xca, 0xfb, 0xad}, Data: []byte{0xde, 0xca, 0xfb, 0xad},
FinBit: true, FinBit: true,
@ -336,7 +336,7 @@ var _ = Describe("Session", func() {
}) })
It("deletes streams with FIN bit & close", func() { It("deletes streams with FIN bit & close", func() {
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xde, 0xca, 0xfb, 0xad}, Data: []byte{0xde, 0xca, 0xfb, 0xad},
FinBit: true, FinBit: true,
@ -369,7 +369,7 @@ var _ = Describe("Session", func() {
It("cancels streams with error", func() { It("cancels streams with error", func() {
sess.garbageCollectStreams() sess.garbageCollectStreams()
testErr := errors.New("test") testErr := errors.New("test")
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0xde, 0xca, 0xfb, 0xad}, Data: []byte{0xde, 0xca, 0xfb, 0xad},
}) })
@ -413,7 +413,7 @@ var _ = Describe("Session", func() {
}) })
It("ignores STREAM frames for closed streams (client-side)", func() { It("ignores STREAM frames for closed streams (client-side)", func() {
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
FinBit: true, FinBit: true,
}) })
@ -426,7 +426,7 @@ var _ = Describe("Session", func() {
sess.garbageCollectStreams() sess.garbageCollectStreams()
str, _ = sess.streamsMap.GetOrOpenStream(5) str, _ = sess.streamsMap.GetOrOpenStream(5)
Expect(str).To(BeNil()) // make sure the stream is gone Expect(str).To(BeNil()) // make sure the stream is gone
err = sess.handleStreamFrame(&frames.StreamFrame{ err = sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
}) })
@ -437,7 +437,7 @@ var _ = Describe("Session", func() {
ostr, err := sess.OpenStream() ostr, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(ostr.StreamID()).To(Equal(protocol.StreamID(2))) Expect(ostr.StreamID()).To(Equal(protocol.StreamID(2)))
err = sess.handleStreamFrame(&frames.StreamFrame{ err = sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 2, StreamID: 2,
FinBit: true, FinBit: true,
}) })
@ -451,7 +451,7 @@ var _ = Describe("Session", func() {
sess.garbageCollectStreams() sess.garbageCollectStreams()
str, _ = sess.streamsMap.GetOrOpenStream(2) str, _ = sess.streamsMap.GetOrOpenStream(2)
Expect(str).To(BeNil()) // make sure the stream is gone Expect(str).To(BeNil()) // make sure the stream is gone
err = sess.handleStreamFrame(&frames.StreamFrame{ err = sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 2, StreamID: 2,
FinBit: true, FinBit: true,
}) })
@ -463,7 +463,7 @@ var _ = Describe("Session", func() {
It("closes the streams for writing", func() { It("closes the streams for writing", func() {
s, err := sess.GetOrOpenStream(5) s, err := sess.GetOrOpenStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{ err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
ErrorCode: 42, ErrorCode: 42,
}) })
@ -476,11 +476,11 @@ var _ = Describe("Session", func() {
It("doesn't close the stream for reading", func() { It("doesn't close the stream for reading", func() {
s, err := sess.GetOrOpenStream(5) s, err := sess.GetOrOpenStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
}) })
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{ err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
ErrorCode: 42, ErrorCode: 42,
ByteOffset: 6, ByteOffset: 6,
@ -496,12 +496,12 @@ var _ = Describe("Session", func() {
str, err := sess.GetOrOpenStream(5) str, err := sess.GetOrOpenStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str.(*stream).writeOffset = 0x1337 str.(*stream).writeOffset = 0x1337
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{ err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
}) })
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(sess.packer.controlFrames).To(HaveLen(1)) 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, StreamID: 5,
ByteOffset: 0x1337, ByteOffset: 0x1337,
})) }))
@ -513,7 +513,7 @@ var _ = Describe("Session", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
str.(*stream).sentFin() str.(*stream).sentFin()
str.Close() str.Close()
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{ err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
}) })
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -526,7 +526,7 @@ var _ = Describe("Session", func() {
fcm := mocks_fc.NewMockFlowControlManager(mockCtrl) fcm := mocks_fc.NewMockFlowControlManager(mockCtrl)
sess.flowControlManager = fcm sess.flowControlManager = fcm
fcm.EXPECT().ResetStream(protocol.StreamID(5), protocol.ByteCount(0x1337)) fcm.EXPECT().ResetStream(protocol.StreamID(5), protocol.ByteCount(0x1337))
err := sess.handleRstStreamFrame(&frames.RstStreamFrame{ err := sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 0x1337, ByteOffset: 0x1337,
}) })
@ -539,7 +539,7 @@ var _ = Describe("Session", func() {
fcm := mocks_fc.NewMockFlowControlManager(mockCtrl) fcm := mocks_fc.NewMockFlowControlManager(mockCtrl)
sess.flowControlManager = fcm sess.flowControlManager = fcm
fcm.EXPECT().ResetStream(protocol.StreamID(5), protocol.ByteCount(0x1337)).Return(testErr) fcm.EXPECT().ResetStream(protocol.StreamID(5), protocol.ByteCount(0x1337)).Return(testErr)
err := sess.handleRstStreamFrame(&frames.RstStreamFrame{ err := sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 0x1337, ByteOffset: 0x1337,
}) })
@ -547,7 +547,7 @@ var _ = Describe("Session", func() {
}) })
It("ignores the error when the stream is not known", 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, StreamID: 5,
ErrorCode: 42, ErrorCode: 42,
}}) }})
@ -561,7 +561,7 @@ var _ = Describe("Session", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str.Reset(testErr) str.Reset(testErr)
Expect(sess.packer.controlFrames).To(HaveLen(1)) 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, StreamID: 5,
ByteOffset: 0x1337, ByteOffset: 0x1337,
})) }))
@ -574,7 +574,7 @@ var _ = Describe("Session", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str.Reset(testErr) str.Reset(testErr)
Expect(sess.packer.controlFrames).To(HaveLen(1)) Expect(sess.packer.controlFrames).To(HaveLen(1))
err = sess.handleRstStreamFrame(&frames.RstStreamFrame{ err = sess.handleRstStreamFrame(&wire.RstStreamFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 0x42, ByteOffset: 0x42,
}) })
@ -587,7 +587,7 @@ var _ = Describe("Session", func() {
It("updates the Flow Control Window of a stream", func() { It("updates the Flow Control Window of a stream", func() {
_, err := sess.GetOrOpenStream(5) _, err := sess.GetOrOpenStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{ err = sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 100, ByteOffset: 100,
}) })
@ -596,7 +596,7 @@ var _ = Describe("Session", func() {
}) })
It("updates the Flow Control Window of the connection", func() { It("updates the Flow Control Window of the connection", func() {
err := sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{ err := sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
StreamID: 0, StreamID: 0,
ByteOffset: 0x800000, 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() { 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, StreamID: 5,
ByteOffset: 1337, ByteOffset: 1337,
}) })
@ -615,11 +615,11 @@ var _ = Describe("Session", func() {
}) })
It("errors when receiving a WindowUpdateFrame for a closed stream", 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) err := sess.streamsMap.RemoveStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
sess.garbageCollectStreams() sess.garbageCollectStreams()
err = sess.handleWindowUpdateFrame(&frames.WindowUpdateFrame{ err = sess.handleWindowUpdateFrame(&wire.WindowUpdateFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 1337, ByteOffset: 1337,
}) })
@ -627,11 +627,11 @@ var _ = Describe("Session", func() {
}) })
It("ignores errors when receiving a WindowUpdateFrame for a closed stream", 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) err := sess.streamsMap.RemoveStream(5)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
sess.garbageCollectStreams() sess.garbageCollectStreams()
err = sess.handleFrames([]frames.Frame{&frames.WindowUpdateFrame{ err = sess.handleFrames([]wire.Frame{&wire.WindowUpdateFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 1337, ByteOffset: 1337,
}}) }})
@ -640,29 +640,29 @@ var _ = Describe("Session", func() {
}) })
It("handles PING frames", func() { It("handles PING frames", func() {
err := sess.handleFrames([]frames.Frame{&frames.PingFrame{}}) err := sess.handleFrames([]wire.Frame{&wire.PingFrame{}})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
It("handles BLOCKED frames", func() { It("handles BLOCKED frames", func() {
err := sess.handleFrames([]frames.Frame{&frames.BlockedFrame{}}) err := sess.handleFrames([]wire.Frame{&wire.BlockedFrame{}})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
It("errors on GOAWAY frames", func() { 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")) Expect(err).To(MatchError("unimplemented: handling GOAWAY frames"))
}) })
It("handles STOP_WAITING frames", func() { 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()) Expect(err).NotTo(HaveOccurred())
}) })
It("handles CONNECTION_CLOSE frames", func(done Done) { It("handles CONNECTION_CLOSE frames", func(done Done) {
go sess.run() go sess.run()
str, _ := sess.GetOrOpenStream(5) 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()) Expect(err).NotTo(HaveOccurred())
Eventually(sess.Context().Done()).Should(BeClosed()) Eventually(sess.Context().Done()).Should(BeClosed())
_, err = str.Read([]byte{0}) _, err = str.Read([]byte{0})
@ -738,7 +738,7 @@ var _ = Describe("Session", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}() }()
Consistently(func() Stream { return str }).Should(BeNil()) Consistently(func() Stream { return str }).Should(BeNil())
sess.handleStreamFrame(&frames.StreamFrame{ sess.handleStreamFrame(&wire.StreamFrame{
StreamID: 3, StreamID: 3,
}) })
Eventually(func() Stream { return str }).ShouldNot(BeNil()) Eventually(func() Stream { return str }).ShouldNot(BeNil())
@ -969,7 +969,7 @@ var _ = Describe("Session", func() {
err := sess.sendPacket() err := sess.sendPacket()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(mconn.written).To(HaveLen(1)) 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() { It("sends two WindowUpdate frames", func() {
@ -999,7 +999,7 @@ var _ = Describe("Session", func() {
sess.packer.packetNumberGenerator.next = 0x1337 + 9 sess.packer.packetNumberGenerator.next = 0x1337 + 9
sess.packer.cryptoSetup = &mockCryptoSetup{encLevelSeal: protocol.EncryptionForwardSecure} sess.packer.cryptoSetup = &mockCryptoSetup{encLevelSeal: protocol.EncryptionForwardSecure}
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -1030,9 +1030,9 @@ var _ = Describe("Session", func() {
Context("for handshake packets", func() { Context("for handshake packets", func() {
It("retransmits an unencrypted packet", 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{{ sph.retransmissionQueue = []*ackhandler.Packet{{
Frames: []frames.Frame{sf}, Frames: []wire.Frame{sf},
EncryptionLevel: protocol.EncryptionUnencrypted, EncryptionLevel: protocol.EncryptionUnencrypted,
}} }}
err := sess.sendPacket() err := sess.sendPacket()
@ -1043,14 +1043,14 @@ var _ = Describe("Session", func() {
Expect(sentPackets[0].EncryptionLevel).To(Equal(protocol.EncryptionUnencrypted)) Expect(sentPackets[0].EncryptionLevel).To(Equal(protocol.EncryptionUnencrypted))
Expect(sentPackets[0].Frames).To(HaveLen(2)) Expect(sentPackets[0].Frames).To(HaveLen(2))
Expect(sentPackets[0].Frames[1]).To(Equal(sf)) 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))) Expect(swf.LeastUnacked).To(Equal(protocol.PacketNumber(0x1337)))
}) })
It("retransmit a packet encrypted with the initial encryption", func() { 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{{ sph.retransmissionQueue = []*ackhandler.Packet{{
Frames: []frames.Frame{sf}, Frames: []wire.Frame{sf},
EncryptionLevel: protocol.EncryptionSecure, EncryptionLevel: protocol.EncryptionSecure,
}} }}
err := sess.sendPacket() err := sess.sendPacket()
@ -1065,9 +1065,9 @@ var _ = Describe("Session", func() {
It("doesn't retransmit handshake packets when the handshake is complete", func() { It("doesn't retransmit handshake packets when the handshake is complete", func() {
sess.handshakeComplete = true sess.handshakeComplete = true
sf := &frames.StreamFrame{StreamID: 1, Data: []byte("foobar")} sf := &wire.StreamFrame{StreamID: 1, Data: []byte("foobar")}
sph.retransmissionQueue = []*ackhandler.Packet{{ sph.retransmissionQueue = []*ackhandler.Packet{{
Frames: []frames.Frame{sf}, Frames: []wire.Frame{sf},
EncryptionLevel: protocol.EncryptionSecure, EncryptionLevel: protocol.EncryptionSecure,
}} }}
err := sess.sendPacket() err := sess.sendPacket()
@ -1078,13 +1078,13 @@ var _ = Describe("Session", func() {
Context("for packets after the handshake", func() { Context("for packets after the handshake", func() {
It("sends a StreamFrame from a packet queued for retransmission", func() { It("sends a StreamFrame from a packet queued for retransmission", func() {
f := frames.StreamFrame{ f := wire.StreamFrame{
StreamID: 0x5, StreamID: 0x5,
Data: []byte("foobar1234567"), Data: []byte("foobar1234567"),
} }
p := ackhandler.Packet{ p := ackhandler.Packet{
PacketNumber: 0x1337, PacketNumber: 0x1337,
Frames: []frames.Frame{&f}, Frames: []wire.Frame{&f},
EncryptionLevel: protocol.EncryptionForwardSecure, EncryptionLevel: protocol.EncryptionForwardSecure,
} }
sph.retransmissionQueue = []*ackhandler.Packet{&p} sph.retransmissionQueue = []*ackhandler.Packet{&p}
@ -1097,22 +1097,22 @@ var _ = Describe("Session", func() {
}) })
It("sends a StreamFrame from a packet queued for retransmission", func() { It("sends a StreamFrame from a packet queued for retransmission", func() {
f1 := frames.StreamFrame{ f1 := wire.StreamFrame{
StreamID: 0x5, StreamID: 0x5,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
f2 := frames.StreamFrame{ f2 := wire.StreamFrame{
StreamID: 0x7, StreamID: 0x7,
Data: []byte("loremipsum"), Data: []byte("loremipsum"),
} }
p1 := ackhandler.Packet{ p1 := ackhandler.Packet{
PacketNumber: 0x1337, PacketNumber: 0x1337,
Frames: []frames.Frame{&f1}, Frames: []wire.Frame{&f1},
EncryptionLevel: protocol.EncryptionForwardSecure, EncryptionLevel: protocol.EncryptionForwardSecure,
} }
p2 := ackhandler.Packet{ p2 := ackhandler.Packet{
PacketNumber: 0x1338, PacketNumber: 0x1338,
Frames: []frames.Frame{&f2}, Frames: []wire.Frame{&f2},
EncryptionLevel: protocol.EncryptionForwardSecure, EncryptionLevel: protocol.EncryptionForwardSecure,
} }
sph.retransmissionQueue = []*ackhandler.Packet{&p1, &p2} 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() { It("always attaches a StopWaiting to a packet that contains a retransmission", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 0x5, StreamID: 0x5,
Data: bytes.Repeat([]byte{'f'}, int(1.5*float32(protocol.MaxPacketSize))), 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)) Expect(mconn.written).To(HaveLen(2))
sentPackets := sph.sentPackets sentPackets := sph.sentPackets
Expect(sentPackets).To(HaveLen(2)) Expect(sentPackets).To(HaveLen(2))
_, ok := sentPackets[0].Frames[0].(*frames.StopWaitingFrame) _, ok := sentPackets[0].Frames[0].(*wire.StopWaitingFrame)
Expect(ok).To(BeTrue()) Expect(ok).To(BeTrue())
_, ok = sentPackets[1].Frames[0].(*frames.StopWaitingFrame) _, ok = sentPackets[1].Frames[0].(*wire.StopWaitingFrame)
Expect(ok).To(BeTrue()) Expect(ok).To(BeTrue())
}) })
@ -1150,12 +1150,12 @@ var _ = Describe("Session", func() {
sess.flowControlManager = fcm sess.flowControlManager = fcm
fcm.EXPECT().GetWindowUpdates() fcm.EXPECT().GetWindowUpdates()
fcm.EXPECT().GetReceiveWindow(protocol.StreamID(5)).Return(protocol.ByteCount(0x1000), nil) fcm.EXPECT().GetReceiveWindow(protocol.StreamID(5)).Return(protocol.ByteCount(0x1000), nil)
wuf := &frames.WindowUpdateFrame{ wuf := &wire.WindowUpdateFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 0x1000, ByteOffset: 0x1000,
} }
sph.retransmissionQueue = []*ackhandler.Packet{{ sph.retransmissionQueue = []*ackhandler.Packet{{
Frames: []frames.Frame{wuf}, Frames: []wire.Frame{wuf},
EncryptionLevel: protocol.EncryptionForwardSecure, EncryptionLevel: protocol.EncryptionForwardSecure,
}} }}
err = sess.sendPacket() err = sess.sendPacket()
@ -1172,7 +1172,7 @@ var _ = Describe("Session", func() {
fcm.EXPECT().GetWindowUpdates() fcm.EXPECT().GetWindowUpdates()
fcm.EXPECT().GetReceiveWindow(protocol.StreamID(5)).Return(protocol.ByteCount(0x2000), nil) fcm.EXPECT().GetReceiveWindow(protocol.StreamID(5)).Return(protocol.ByteCount(0x2000), nil)
sph.retransmissionQueue = []*ackhandler.Packet{{ sph.retransmissionQueue = []*ackhandler.Packet{{
Frames: []frames.Frame{&frames.WindowUpdateFrame{ Frames: []wire.Frame{&wire.WindowUpdateFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 0x1000, ByteOffset: 0x1000,
}}, }},
@ -1194,7 +1194,7 @@ var _ = Describe("Session", func() {
_, err = sess.flowControlManager.SendWindowSize(5) _, err = sess.flowControlManager.SendWindowSize(5)
Expect(err).To(MatchError("Error accessing the flowController map.")) Expect(err).To(MatchError("Error accessing the flowController map."))
sph.retransmissionQueue = []*ackhandler.Packet{{ sph.retransmissionQueue = []*ackhandler.Packet{{
Frames: []frames.Frame{&frames.WindowUpdateFrame{ Frames: []wire.Frame{&wire.WindowUpdateFrame{
StreamID: 5, StreamID: 5,
ByteOffset: 0x1337, ByteOffset: 0x1337,
}}, }},
@ -1219,7 +1219,7 @@ var _ = Describe("Session", func() {
err := sess.sentPacketHandler.SentPacket(&ackhandler.Packet{ err := sess.sentPacketHandler.SentPacket(&ackhandler.Packet{
PacketNumber: n, PacketNumber: n,
Length: 1, Length: 1,
Frames: []frames.Frame{&frames.StreamFrame{ Frames: []wire.Frame{&wire.StreamFrame{
Data: []byte("foobar"), Data: []byte("foobar"),
}}, }},
EncryptionLevel: protocol.EncryptionForwardSecure, EncryptionLevel: protocol.EncryptionForwardSecure,
@ -1251,7 +1251,7 @@ var _ = Describe("Session", func() {
It("sets the timer to the ack timer", func() { It("sets the timer to the ack timer", func() {
rph := &mockReceivedPacketHandler{ackAlarm: time.Now().Add(10 * time.Millisecond)} rph := &mockReceivedPacketHandler{ackAlarm: time.Now().Add(10 * time.Millisecond)}
rph.nextAckFrame = &frames.AckFrame{LargestAcked: 0x1337} rph.nextAckFrame = &wire.AckFrame{LargestAcked: 0x1337}
sess.receivedPacketHandler = rph sess.receivedPacketHandler = rph
go sess.run() go sess.run()
defer sess.Close(nil) defer sess.Close(nil)
@ -1628,11 +1628,11 @@ var _ = Describe("Session", func() {
PacketNumber: 1, PacketNumber: 1,
Length: 1, Length: 1,
}) })
err := sess.handleFrames([]frames.Frame{&frames.AckFrame{ err := sess.handleFrames([]wire.Frame{&wire.AckFrame{
LargestAcked: 1, LargestAcked: 1,
}}) }})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = sess.handleFrames([]frames.Frame{&frames.AckFrame{ err = sess.handleFrames([]wire.Frame{&wire.AckFrame{
LargestAcked: 1, LargestAcked: 1,
}}) }})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View file

@ -9,9 +9,9 @@ import (
"time" "time"
"github.com/lucas-clemente/quic-go/flowcontrol" "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/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "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 // 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 // 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() maxOffset := frame.Offset + frame.DataLen()
err := s.flowControlManager.UpdateHighestReceived(s.streamID, maxOffset) err := s.flowControlManager.UpdateHighestReceived(s.streamID, maxOffset)
if err != nil { 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 // CloseRemote makes the stream receive a "virtual" FIN stream frame at a given offset
func (s *stream) CloseRemote(offset protocol.ByteCount) { 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 // Cancel is called by session to indicate that an error occurred

View file

@ -3,13 +3,13 @@ package quic
import ( import (
"errors" "errors"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
) )
type streamFrameSorter struct { type streamFrameSorter struct {
queuedFrames map[protocol.ByteCount]*frames.StreamFrame queuedFrames map[protocol.ByteCount]*wire.StreamFrame
readPosition protocol.ByteCount readPosition protocol.ByteCount
gaps *utils.ByteIntervalList gaps *utils.ByteIntervalList
} }
@ -23,13 +23,13 @@ var (
func newStreamFrameSorter() *streamFrameSorter { func newStreamFrameSorter() *streamFrameSorter {
s := streamFrameSorter{ s := streamFrameSorter{
gaps: utils.NewByteIntervalList(), 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}) s.gaps.PushFront(utils.ByteInterval{Start: 0, End: protocol.MaxByteCount})
return &s return &s
} }
func (s *streamFrameSorter) Push(frame *frames.StreamFrame) error { func (s *streamFrameSorter) Push(frame *wire.StreamFrame) error {
if frame.DataLen() == 0 { if frame.DataLen() == 0 {
if frame.FinBit { if frame.FinBit {
s.queuedFrames[frame.Offset] = frame s.queuedFrames[frame.Offset] = frame
@ -143,7 +143,7 @@ func (s *streamFrameSorter) Push(frame *frames.StreamFrame) error {
return nil return nil
} }
func (s *streamFrameSorter) Pop() *frames.StreamFrame { func (s *streamFrameSorter) Pop() *wire.StreamFrame {
frame := s.Head() frame := s.Head()
if frame != nil { if frame != nil {
s.readPosition += frame.DataLen() s.readPosition += frame.DataLen()
@ -152,7 +152,7 @@ func (s *streamFrameSorter) Pop() *frames.StreamFrame {
return frame return frame
} }
func (s *streamFrameSorter) Head() *frames.StreamFrame { func (s *streamFrameSorter) Head() *wire.StreamFrame {
frame, ok := s.queuedFrames[s.readPosition] frame, ok := s.queuedFrames[s.readPosition]
if ok { if ok {
return frame return frame

View file

@ -3,9 +3,9 @@ package quic
import ( import (
"bytes" "bytes"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -32,7 +32,7 @@ var _ = Describe("StreamFrame sorter", func() {
Context("Push", func() { Context("Push", func() {
It("inserts and pops a single frame", func() { It("inserts and pops a single frame", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -44,11 +44,11 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("inserts and pops two consecutive frame", func() { It("inserts and pops two consecutive frame", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 6, Offset: 6,
Data: []byte("foobar2"), Data: []byte("foobar2"),
} }
@ -62,14 +62,14 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("rejects empty frames", func() { It("rejects empty frames", func() {
f := &frames.StreamFrame{} f := &wire.StreamFrame{}
err := s.Push(f) err := s.Push(f)
Expect(err).To(MatchError(errEmptyStreamData)) Expect(err).To(MatchError(errEmptyStreamData))
}) })
Context("FinBit handling", func() { Context("FinBit handling", func() {
It("saves a FinBit frame at offset 0", func() { It("saves a FinBit frame at offset 0", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 0, Offset: 0,
FinBit: true, 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() { It("sets the FinBit if a stream is closed after receiving some data", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 6, Offset: 6,
FinBit: true, FinBit: true,
} }
@ -98,7 +98,7 @@ var _ = Describe("StreamFrame sorter", func() {
Context("Gap handling", func() { Context("Gap handling", func() {
It("finds the first gap", func() { It("finds the first gap", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("foobar"), 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() { It("correctly sets the first gap for a frame with offset 0", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -123,13 +123,13 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("finds the two gaps", func() { It("finds the two gaps", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 20, Offset: 20,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -143,13 +143,13 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("finds the two gaps in reverse order", func() { It("finds the two gaps in reverse order", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 20, Offset: 20,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -163,13 +163,13 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("shrinks a gap when it is partially filled", func() { It("shrinks a gap when it is partially filled", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("test"), Data: []byte("test"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 4, Offset: 4,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -182,13 +182,13 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("deletes a gap at the beginning, when it is filled", func() { It("deletes a gap at the beginning, when it is filled", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 6, Offset: 6,
Data: []byte("test"), Data: []byte("test"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -200,19 +200,19 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("deletes a gap in the middle, when it is filled", func() { It("deletes a gap in the middle, when it is filled", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("test"), Data: []byte("test"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("test2"), Data: []byte("test2"),
} }
err = s.Push(f2) err = s.Push(f2)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f3 := &frames.StreamFrame{ f3 := &wire.StreamFrame{
Offset: 4, Offset: 4,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -225,13 +225,13 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("splits a gap into two", func() { It("splits a gap into two", func() {
f1 := &frames.StreamFrame{ f1 := &wire.StreamFrame{
Offset: 100, Offset: 100,
Data: []byte("test"), Data: []byte("test"),
} }
err := s.Push(f1) err := s.Push(f1)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
f2 := &frames.StreamFrame{ f2 := &wire.StreamFrame{
Offset: 50, Offset: 50,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -248,11 +248,11 @@ var _ = Describe("StreamFrame sorter", func() {
Context("Overlapping Stream Data detection", func() { Context("Overlapping Stream Data detection", func() {
// create gaps: 0-5, 10-15, 20-25, 30-inf // create gaps: 0-5, 10-15, 20-25, 30-inf
BeforeEach(func() { 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()) 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()) 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()) Expect(err).ToNot(HaveOccurred())
checkGaps([]utils.ByteInterval{ checkGaps([]utils.ByteInterval{
{Start: 0, End: 5}, {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() { It("cuts a frame with offset 0 that overlaps at the end", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -281,7 +281,7 @@ var _ = Describe("StreamFrame sorter", func() {
It("cuts a frame that overlaps at the end", func() { It("cuts a frame that overlaps at the end", func() {
// 4 to 7 // 4 to 7
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 4, Offset: 4,
Data: []byte("foo"), 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() { It("cuts a frame that completely fills a gap, but overlaps at the end", func() {
// 10 to 16 // 10 to 16
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -318,7 +318,7 @@ var _ = Describe("StreamFrame sorter", func() {
It("cuts a frame that overlaps at the beginning", func() { It("cuts a frame that overlaps at the beginning", func() {
// 8 to 14 // 8 to 14
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 8, Offset: 8,
Data: []byte("foobar"), 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() { It("processes a frame that overlaps at the beginning and at the end, starting in a gap", func() {
// 2 to 12 // 2 to 12
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte("1234567890"), 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() { It("processes a frame that overlaps at the beginning and at the end, starting in a gap, ending in data", func() {
// 2 to 17 // 2 to 17
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte("123456789012345"), 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() { It("processes a frame that overlaps at the beginning and at the end, starting in a gap, ending in data", func() {
// 5 to 22 // 5 to 22
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 5, Offset: 5,
Data: []byte("12345678901234567"), Data: []byte("12345678901234567"),
} }
@ -394,7 +394,7 @@ var _ = Describe("StreamFrame sorter", func() {
It("processes a frame that closes multiple gaps", func() { It("processes a frame that closes multiple gaps", func() {
// 2 to 27 // 2 to 27
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 2, Offset: 2,
Data: bytes.Repeat([]byte{'e'}, 25), Data: bytes.Repeat([]byte{'e'}, 25),
} }
@ -414,7 +414,7 @@ var _ = Describe("StreamFrame sorter", func() {
It("processes a frame that closes multiple gaps", func() { It("processes a frame that closes multiple gaps", func() {
// 5 to 27 // 5 to 27
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 5, Offset: 5,
Data: bytes.Repeat([]byte{'d'}, 22), 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() { It("processes a frame that covers multiple gaps and ends at the end of a gap", func() {
// 1 to 15 // 1 to 15
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 1, Offset: 1,
Data: bytes.Repeat([]byte{'f'}, 14), 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() { It("processes a frame that closes all gaps (except for the last one)", func() {
// 0 to 32 // 0 to 32
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 0, Offset: 0,
Data: bytes.Repeat([]byte{'f'}, 32), 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() { It("cuts a frame that overlaps at the beginning and at the end, starting in data already received", func() {
// 8 to 17 // 8 to 17
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 8, Offset: 8,
Data: []byte("123456789"), Data: []byte("123456789"),
} }
@ -488,7 +488,7 @@ var _ = Describe("StreamFrame sorter", func() {
It("cuts a frame that completely covers two gaps", func() { It("cuts a frame that completely covers two gaps", func() {
// 10 to 20 // 10 to 20
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Offset: 10, Offset: 10,
Data: []byte("1234567890"), Data: []byte("1234567890"),
} }
@ -513,9 +513,9 @@ var _ = Describe("StreamFrame sorter", func() {
BeforeEach(func() { BeforeEach(func() {
// create gaps: 5-10, 15-inf // 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()) 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()) Expect(err).ToNot(HaveOccurred())
checkGaps(expectedGaps) checkGaps(expectedGaps)
}) })
@ -526,21 +526,21 @@ var _ = Describe("StreamFrame sorter", func() {
}) })
It("does not modify data when receiving a duplicate", 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(err).To(MatchError(errDuplicateStreamData))
Expect(s.queuedFrames[0].Data).ToNot(Equal([]byte("fffff"))) 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() { It("detects a duplicate frame that is smaller than the original, starting at the beginning", func() {
// 10 to 12 // 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(err).To(MatchError(errDuplicateStreamData))
Expect(s.queuedFrames[10].Data).To(HaveLen(5)) Expect(s.queuedFrames[10].Data).To(HaveLen(5))
}) })
It("detects a duplicate frame that is smaller than the original, somewhere in the middle", func() { It("detects a duplicate frame that is smaller than the original, somewhere in the middle", func() {
// 1 to 4 // 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(err).To(MatchError(errDuplicateStreamData))
Expect(s.queuedFrames[0].Data).To(HaveLen(5)) Expect(s.queuedFrames[0].Data).To(HaveLen(5))
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(1))) 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() { It("detects a duplicate frame that is smaller than the original, somewhere in the middle in the last block", func() {
// 11 to 14 // 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(err).To(MatchError(errDuplicateStreamData))
Expect(s.queuedFrames[10].Data).To(HaveLen(5)) Expect(s.queuedFrames[10].Data).To(HaveLen(5))
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(11))) 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() { It("detects a duplicate frame that is smaller than the original, with aligned end in the last block", func() {
// 11 to 14 // 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(err).To(MatchError(errDuplicateStreamData))
Expect(s.queuedFrames[10].Data).To(HaveLen(5)) Expect(s.queuedFrames[10].Data).To(HaveLen(5))
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(11))) 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() { It("detects a duplicate frame that is smaller than the original, with aligned end", func() {
// 3 to 5 // 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(err).To(MatchError(errDuplicateStreamData))
Expect(s.queuedFrames[0].Data).To(HaveLen(5)) Expect(s.queuedFrames[0].Data).To(HaveLen(5))
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(3))) Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(3)))
@ -574,7 +574,7 @@ var _ = Describe("StreamFrame sorter", func() {
Context("DoS protection", func() { Context("DoS protection", func() {
It("errors when too many gaps are created", func() { It("errors when too many gaps are created", func() {
for i := 0; i < protocol.MaxStreamFrameSorterGaps; i++ { for i := 0; i < protocol.MaxStreamFrameSorterGaps; i++ {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Data: []byte("foobar"), Data: []byte("foobar"),
Offset: protocol.ByteCount(i * 7), Offset: protocol.ByteCount(i * 7),
} }
@ -582,7 +582,7 @@ var _ = Describe("StreamFrame sorter", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
} }
Expect(s.gaps.Len()).To(Equal(protocol.MaxStreamFrameSorterGaps)) Expect(s.gaps.Len()).To(Equal(protocol.MaxStreamFrameSorterGaps))
f := &frames.StreamFrame{ f := &wire.StreamFrame{
Data: []byte("foobar"), Data: []byte("foobar"),
Offset: protocol.ByteCount(protocol.MaxStreamFrameSorterGaps*7) + 100, Offset: protocol.ByteCount(protocol.MaxStreamFrameSorterGaps*7) + 100,
} }

View file

@ -2,9 +2,9 @@ package quic
import ( import (
"github.com/lucas-clemente/quic-go/flowcontrol" "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/internal/utils"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
) )
type streamFramer struct { type streamFramer struct {
@ -12,8 +12,8 @@ type streamFramer struct {
flowControlManager flowcontrol.FlowControlManager flowControlManager flowcontrol.FlowControlManager
retransmissionQueue []*frames.StreamFrame retransmissionQueue []*wire.StreamFrame
blockedFrameQueue []*frames.BlockedFrame blockedFrameQueue []*wire.BlockedFrame
} }
func newStreamFramer(streamsMap *streamsMap, flowControlManager flowcontrol.FlowControlManager) *streamFramer { 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) 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) fs, currentLen := f.maybePopFramesForRetransmission(maxLen)
return append(fs, f.maybePopNormalFrames(maxLen-currentLen)...) return append(fs, f.maybePopNormalFrames(maxLen-currentLen)...)
} }
func (f *streamFramer) PopBlockedFrame() *frames.BlockedFrame { func (f *streamFramer) PopBlockedFrame() *wire.BlockedFrame {
if len(f.blockedFrameQueue) == 0 { if len(f.blockedFrameQueue) == 0 {
return nil 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(lclemente): This is somewhat duplicate with the normal path for generating frames.
// TODO(#657): Flow control // 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() { if !f.HasCryptoStreamFrame() {
return nil return nil
} }
cs, _ := f.streamsMap.GetOrOpenStream(1) cs, _ := f.streamsMap.GetOrOpenStream(1)
frame := &frames.StreamFrame{ frame := &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Offset: cs.writeOffset, Offset: cs.writeOffset,
} }
@ -67,7 +67,7 @@ func (f *streamFramer) PopCryptoStreamFrame(maxLen protocol.ByteCount) *frames.S
return frame 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 { for len(f.retransmissionQueue) > 0 {
frame := f.retransmissionQueue[0] frame := f.retransmissionQueue[0]
frame.DataLenPresent = true frame.DataLenPresent = true
@ -93,8 +93,8 @@ func (f *streamFramer) maybePopFramesForRetransmission(maxLen protocol.ByteCount
return return
} }
func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []*frames.StreamFrame) { func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []*wire.StreamFrame) {
frame := &frames.StreamFrame{DataLenPresent: true} frame := &wire.StreamFrame{DataLenPresent: true}
var currentLen protocol.ByteCount var currentLen protocol.ByteCount
fn := func(s *stream) (bool, error) { 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 // Finally, check if we are now FC blocked and should queue a BLOCKED frame
if f.flowControlManager.RemainingConnectionWindowSize() == 0 { if f.flowControlManager.RemainingConnectionWindowSize() == 0 {
// We are now connection-level FC blocked // 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 { } else if !frame.FinBit && sendWindowSize-frame.DataLen() == 0 {
// We are now stream-level FC blocked // 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) res = append(res, frame)
@ -159,7 +159,7 @@ func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []
return false, nil return false, nil
} }
frame = &frames.StreamFrame{DataLenPresent: true} frame = &wire.StreamFrame{DataLenPresent: true}
return true, nil 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. // 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() { if n >= frame.DataLen() {
return nil return nil
} }
@ -179,7 +179,7 @@ func maybeSplitOffFrame(frame *frames.StreamFrame, n protocol.ByteCount) *frames
frame.Offset += n frame.Offset += n
}() }()
return &frames.StreamFrame{ return &wire.StreamFrame{
FinBit: false, FinBit: false,
StreamID: frame.StreamID, StreamID: frame.StreamID,
Offset: frame.Offset, Offset: frame.Offset,

View file

@ -3,9 +3,9 @@ package quic
import ( import (
"bytes" "bytes"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc" "github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -17,7 +17,7 @@ var _ = Describe("Stream Framer", func() {
) )
var ( var (
retransmittedFrame1, retransmittedFrame2 *frames.StreamFrame retransmittedFrame1, retransmittedFrame2 *wire.StreamFrame
framer *streamFramer framer *streamFramer
streamsMap *streamsMap streamsMap *streamsMap
stream1, stream2 *stream stream1, stream2 *stream
@ -25,11 +25,11 @@ var _ = Describe("Stream Framer", func() {
) )
BeforeEach(func() { BeforeEach(func() {
retransmittedFrame1 = &frames.StreamFrame{ retransmittedFrame1 = &wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0x13, 0x37}, Data: []byte{0x13, 0x37},
} }
retransmittedFrame2 = &frames.StreamFrame{ retransmittedFrame2 = &wire.StreamFrame{
StreamID: 6, StreamID: 6,
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD}, Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
} }
@ -165,7 +165,7 @@ var _ = Describe("Stream Framer", func() {
Context("splitting of frames", func() { Context("splitting of frames", func() {
It("splits off nothing", func() { It("splits off nothing", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Data: []byte("bar"), Data: []byte("bar"),
Offset: 3, Offset: 3,
@ -176,7 +176,7 @@ var _ = Describe("Stream Framer", func() {
}) })
It("splits off initial frame", func() { It("splits off initial frame", func() {
f := &frames.StreamFrame{ f := &wire.StreamFrame{
StreamID: 1, StreamID: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
DataLenPresent: true, DataLenPresent: true,
@ -210,7 +210,7 @@ var _ = Describe("Stream Framer", func() {
It("never returns an empty stream frame", 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) // 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, StreamID: 5,
Offset: 1, Offset: 1,
FinBit: false, FinBit: false,

View file

@ -9,9 +9,9 @@ import (
"os" "os"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc" "github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/wire"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gbytes"
@ -78,7 +78,7 @@ var _ = Describe("Stream", func() {
It("reads a single StreamFrame", func() { It("reads a single StreamFrame", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
} }
@ -95,7 +95,7 @@ var _ = Describe("Stream", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, 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(2))
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
frame1 := frames.StreamFrame{ frame1 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD}, Data: []byte{0xDE, 0xAD},
} }
frame2 := frames.StreamFrame{ frame2 := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte{0xBE, 0xEF}, 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(2))
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
frame1 := frames.StreamFrame{ frame1 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD}, Data: []byte{0xDE, 0xAD},
} }
frame2 := frames.StreamFrame{ frame2 := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte{0xBE, 0xEF}, Data: []byte{0xBE, 0xEF},
} }
@ -163,7 +163,7 @@ var _ = Describe("Stream", func() {
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
frame := frames.StreamFrame{Data: []byte{0xDE, 0xAD}} frame := wire.StreamFrame{Data: []byte{0xDE, 0xAD}}
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
err := str.AddStreamFrame(&frame) err := str.AddStreamFrame(&frame)
Expect(err).ToNot(HaveOccurred()) 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(2))
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
frame1 := frames.StreamFrame{ frame1 := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte{0xBE, 0xEF}, Data: []byte{0xBE, 0xEF},
} }
frame2 := frames.StreamFrame{ frame2 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD}, 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(2))
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
frame1 := frames.StreamFrame{ frame1 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD}, Data: []byte{0xDE, 0xAD},
} }
frame2 := frames.StreamFrame{ frame2 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0x13, 0x37}, Data: []byte{0x13, 0x37},
} }
frame3 := frames.StreamFrame{ frame3 := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte{0xBE, 0xEF}, Data: []byte{0xBE, 0xEF},
} }
@ -232,11 +232,11 @@ var _ = Describe("Stream", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
frame1 := frames.StreamFrame{ frame1 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte("foob"), Data: []byte("foob"),
} }
frame2 := frames.StreamFrame{ frame2 := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte("obar"), Data: []byte("obar"),
} }
@ -254,7 +254,7 @@ var _ = Describe("Stream", func() {
It("calls onData", func() { It("calls onData", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, 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() { It("returns an error when Read is called after the deadline", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes() mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes()
f := &frames.StreamFrame{Data: []byte("foobar")} f := &wire.StreamFrame{Data: []byte("foobar")}
err := str.AddStreamFrame(f) err := str.AddStreamFrame(f)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str.SetReadDeadline(time.Now().Add(-time.Second)) 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() { It("sets a read deadline, when SetDeadline is called", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes() mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)).AnyTimes()
f := &frames.StreamFrame{Data: []byte("foobar")} f := &wire.StreamFrame{Data: []byte("foobar")}
err := str.AddStreamFrame(f) err := str.AddStreamFrame(f)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str.SetDeadline(time.Now().Add(-time.Second)) str.SetDeadline(time.Now().Add(-time.Second))
@ -348,7 +348,7 @@ var _ = Describe("Stream", func() {
It("returns EOFs", func() { It("returns EOFs", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
FinBit: true, FinBit: true,
@ -368,12 +368,12 @@ var _ = Describe("Stream", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)).Times(2)
frame1 := frames.StreamFrame{ frame1 := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte{0xBE, 0xEF}, Data: []byte{0xBE, 0xEF},
FinBit: true, FinBit: true,
} }
frame2 := frames.StreamFrame{ frame2 := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD}, Data: []byte{0xDE, 0xAD},
} }
@ -394,7 +394,7 @@ var _ = Describe("Stream", func() {
It("returns EOFs with partial read", func() { It("returns EOFs with partial read", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(2))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(2))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD}, Data: []byte{0xDE, 0xAD},
FinBit: true, FinBit: true,
@ -411,7 +411,7 @@ var _ = Describe("Stream", func() {
It("handles immediate FINs", func() { It("handles immediate FINs", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(0)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(0))
mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(0)) mockFcm.EXPECT().AddBytesRead(streamID, protocol.ByteCount(0))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{}, Data: []byte{},
FinBit: true, FinBit: true,
@ -484,7 +484,7 @@ var _ = Describe("Stream", func() {
Context("reset by the peer", func() { Context("reset by the peer", func() {
It("continues reading after receiving a remote error", func() { It("continues reading after receiving a remote error", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, 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() { It("reads a delayed StreamFrame that arrives after receiving a remote error", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
str.RegisterRemoteError(testErr) str.RegisterRemoteError(testErr)
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, 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() { It("returns the error if reading past the offset of the frame received", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, 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() { It("returns an EOF when reading past the offset, if the stream received a finbit", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
FinBit: true, FinBit: true,
@ -544,7 +544,7 @@ var _ = Describe("Stream", func() {
It("continues reading in small chunks after receiving a remote error", func() { It("continues reading in small chunks after receiving a remote error", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
FinBit: true, 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() { It("doesn't inform the flow controller about bytes read after receiving the remote error", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(4))
// No AddBytesRead() // No AddBytesRead()
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 0, Offset: 0,
StreamID: 5, StreamID: 5,
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
@ -685,7 +685,7 @@ var _ = Describe("Stream", func() {
It("doesn't allow further reads", func() { It("doesn't allow further reads", func() {
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6)) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(6))
str.AddStreamFrame(&frames.StreamFrame{ str.AddStreamFrame(&wire.StreamFrame{
Data: []byte("foobar"), Data: []byte("foobar"),
}) })
str.Reset(testErr) str.Reset(testErr)
@ -946,7 +946,7 @@ var _ = Describe("Stream", func() {
It("errors when a StreamFrames causes a flow control violation", func() { It("errors when a StreamFrames causes a flow control violation", func() {
testErr := errors.New("flow control violation") testErr := errors.New("flow control violation")
mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(8)).Return(testErr) mockFcm.EXPECT().UpdateHighestReceived(streamID, protocol.ByteCount(8)).Return(testErr)
frame := frames.StreamFrame{ frame := wire.StreamFrame{
Offset: 2, Offset: 2,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
@ -958,7 +958,7 @@ var _ = Describe("Stream", func() {
testErr := errors.New("testErr") testErr := errors.New("testErr")
finishReading := func() { finishReading := func() {
err := str.AddStreamFrame(&frames.StreamFrame{FinBit: true}) err := str.AddStreamFrame(&wire.StreamFrame{FinBit: true})
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
b := make([]byte, 100) b := make([]byte, 100)
_, err = strWithTimeout.Read(b) _, err = strWithTimeout.Read(b)

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import "github.com/lucas-clemente/quic-go/protocol" import "github.com/lucas-clemente/quic-go/protocol"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

28
wire/log.go Normal file
View 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)
}
}

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"
@ -37,12 +37,12 @@ var _ = Describe("Frame logging", func() {
It("logs sent frames", func() { It("logs sent frames", func() {
LogFrame(&RstStreamFrame{}, true) 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() { It("logs received frames", func() {
LogFrame(&RstStreamFrame{}, false) 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() { It("logs stream frames", func() {
@ -52,7 +52,7 @@ var _ = Describe("Frame logging", func() {
Data: bytes.Repeat([]byte{'f'}, 0x100), Data: bytes.Repeat([]byte{'f'}, 0x100),
} }
LogFrame(frame, false) 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() { It("logs ACK frames", func() {
@ -62,7 +62,7 @@ var _ = Describe("Frame logging", func() {
DelayTime: 1 * time.Millisecond, DelayTime: 1 * time.Millisecond,
} }
LogFrame(frame, false) 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() { It("logs incoming StopWaiting frames", func() {
@ -70,7 +70,7 @@ var _ = Describe("Frame logging", func() {
LeastUnacked: 0x1337, LeastUnacked: 0x1337,
} }
LogFrame(frame, false) 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() { It("logs outgoing StopWaiting frames", func() {
@ -79,6 +79,6 @@ var _ = Describe("Frame logging", func() {
PacketNumberLen: protocol.PacketNumberLen4, PacketNumberLen: protocol.PacketNumberLen4,
} }
LogFrame(frame, true) 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"))
}) })
}) })

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package frames package wire
import ( import (
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
@ -11,7 +11,7 @@ import (
func TestCrypto(t *testing.T) { func TestCrypto(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Frames Suite") RunSpecs(t, "Wire Suite")
} }
const ( const (