From 7fc9d5938188cb57fabf3dc32c1c9b88611cfc9b Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 8 Jan 2017 19:30:50 +0700 Subject: [PATCH] determine if a received packet is retransmittable --- packet_unpacker.go | 4 ---- unpacked_packet.go | 27 ++++++++++++++++++++++++ unpacked_packet_test.go | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 unpacked_packet.go create mode 100644 unpacked_packet_test.go diff --git a/packet_unpacker.go b/packet_unpacker.go index 3434751b..cec85ed7 100644 --- a/packet_unpacker.go +++ b/packet_unpacker.go @@ -11,10 +11,6 @@ import ( "github.com/lucas-clemente/quic-go/qerr" ) -type unpackedPacket struct { - frames []frames.Frame -} - type packetUnpacker struct { version protocol.VersionNumber aead crypto.AEAD diff --git a/unpacked_packet.go b/unpacked_packet.go new file mode 100644 index 00000000..80792047 --- /dev/null +++ b/unpacked_packet.go @@ -0,0 +1,27 @@ +package quic + +import "github.com/lucas-clemente/quic-go/frames" + +type unpackedPacket struct { + frames []frames.Frame +} + +func (u *unpackedPacket) IsRetransmittable() bool { + for _, f := range u.frames { + switch f.(type) { + case *frames.StreamFrame: + return true + case *frames.RstStreamFrame: + return true + case *frames.WindowUpdateFrame: + return true + case *frames.BlockedFrame: + return true + case *frames.PingFrame: + return true + case *frames.GoawayFrame: + return true + } + } + return false +} diff --git a/unpacked_packet_test.go b/unpacked_packet_test.go new file mode 100644 index 00000000..82112a26 --- /dev/null +++ b/unpacked_packet_test.go @@ -0,0 +1,46 @@ +package quic + +import ( + "github.com/lucas-clemente/quic-go/frames" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Unpacked packet", func() { + var packet *unpackedPacket + BeforeEach(func() { + packet = &unpackedPacket{} + }) + + It("says that an empty packet is not retransmittable", func() { + Expect(packet.IsRetransmittable()).To(BeFalse()) + }) + + It("detects the frame types", func() { + packet.frames = []frames.Frame{&frames.AckFrame{}} + Expect(packet.IsRetransmittable()).To(BeFalse()) + packet.frames = []frames.Frame{&frames.BlockedFrame{}} + Expect(packet.IsRetransmittable()).To(BeTrue()) + packet.frames = []frames.Frame{&frames.GoawayFrame{}} + Expect(packet.IsRetransmittable()).To(BeTrue()) + packet.frames = []frames.Frame{&frames.PingFrame{}} + Expect(packet.IsRetransmittable()).To(BeTrue()) + packet.frames = []frames.Frame{&frames.StreamFrame{}} + Expect(packet.IsRetransmittable()).To(BeTrue()) + packet.frames = []frames.Frame{&frames.RstStreamFrame{}} + Expect(packet.IsRetransmittable()).To(BeTrue()) + packet.frames = []frames.Frame{&frames.StopWaitingFrame{}} + Expect(packet.IsRetransmittable()).To(BeFalse()) + packet.frames = []frames.Frame{&frames.WindowUpdateFrame{}} + Expect(packet.IsRetransmittable()).To(BeTrue()) + }) + + It("says that a packet is retransmittable if it contains one retransmittable frame", func() { + packet.frames = []frames.Frame{ + &frames.AckFrame{}, + &frames.WindowUpdateFrame{}, + &frames.StopWaitingFrame{}, + } + Expect(packet.IsRetransmittable()).To(BeTrue()) + }) +})