forked from quic-go/quic-go
Move retransmittable frame logic to the ackhandler package
This commit is contained in:
38
ackhandler/retransmittable.go
Normal file
38
ackhandler/retransmittable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package ackhandler
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
)
|
||||
|
||||
// Returns a new slice with all non-retransmittable frames deleted.
|
||||
func stripNonRetransmittableFrames(fs []frames.Frame) []frames.Frame {
|
||||
res := make([]frames.Frame, 0, len(fs))
|
||||
for _, f := range fs {
|
||||
if IsFrameRetransmittable(f) {
|
||||
res = append(res, f)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IsFrameRetransmittable returns true if the frame should be retransmitted.
|
||||
func IsFrameRetransmittable(f frames.Frame) bool {
|
||||
switch f.(type) {
|
||||
case *frames.StopWaitingFrame:
|
||||
return false
|
||||
case *frames.AckFrame:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasRetransmittableFrames returns true if at least one frame is retransmittable.
|
||||
func HasRetransmittableFrames(fs []frames.Frame) bool {
|
||||
for _, f := range fs {
|
||||
if IsFrameRetransmittable(f) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
44
ackhandler/retransmittable_test.go
Normal file
44
ackhandler/retransmittable_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package ackhandler
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("retransmittable frames", func() {
|
||||
for fl, el := range map[frames.Frame]bool{
|
||||
&frames.AckFrame{}: false,
|
||||
&frames.StopWaitingFrame{}: false,
|
||||
&frames.BlockedFrame{}: true,
|
||||
&frames.ConnectionCloseFrame{}: true,
|
||||
&frames.GoawayFrame{}: true,
|
||||
&frames.PingFrame{}: true,
|
||||
&frames.RstStreamFrame{}: true,
|
||||
&frames.StreamFrame{}: true,
|
||||
&frames.WindowUpdateFrame{}: true,
|
||||
} {
|
||||
f := fl
|
||||
e := el
|
||||
fName := reflect.ValueOf(f).Elem().Type().Name()
|
||||
|
||||
It("works for "+fName, func() {
|
||||
Expect(IsFrameRetransmittable(f)).To(Equal(e))
|
||||
})
|
||||
|
||||
It("stripping non-retransmittable frames works for "+fName, func() {
|
||||
s := []frames.Frame{f}
|
||||
if e {
|
||||
Expect(stripNonRetransmittableFrames(s)).To(Equal([]frames.Frame{f}))
|
||||
} else {
|
||||
Expect(stripNonRetransmittableFrames(s)).To(BeEmpty())
|
||||
}
|
||||
})
|
||||
|
||||
It("HasRetransmittableFrames works for "+fName, func() {
|
||||
Expect(HasRetransmittableFrames([]frames.Frame{f})).To(Equal(e))
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user