retransmission queue: simplify queueing of PING frames

This commit is contained in:
Marten Seemann 2023-06-04 15:28:16 +03:00
parent da55dfaabd
commit 5225a104d4
4 changed files with 74 additions and 50 deletions

View file

@ -23,7 +23,7 @@ var _ = Describe("Retransmission queue", func() {
It("queues and retrieves a control frame", func() {
f := &wire.MaxDataFrame{MaximumData: 0x42}
q.AddInitial(f)
q.addInitial(f)
Expect(q.HasInitialData()).To(BeTrue())
Expect(q.GetInitialFrame(f.Length(protocol.Version1)-1, protocol.Version1)).To(BeNil())
Expect(q.GetInitialFrame(f.Length(protocol.Version1), protocol.Version1)).To(Equal(f))
@ -32,7 +32,7 @@ var _ = Describe("Retransmission queue", func() {
It("queues and retrieves a CRYPTO frame", func() {
f := &wire.CryptoFrame{Data: []byte("foobar")}
q.AddInitial(f)
q.addInitial(f)
Expect(q.HasInitialData()).To(BeTrue())
Expect(q.GetInitialFrame(f.Length(protocol.Version1), protocol.Version1)).To(Equal(f))
Expect(q.HasInitialData()).To(BeFalse())
@ -43,7 +43,7 @@ var _ = Describe("Retransmission queue", func() {
Offset: 100,
Data: []byte("foobar"),
}
q.AddInitial(f)
q.addInitial(f)
Expect(q.HasInitialData()).To(BeTrue())
f1 := q.GetInitialFrame(f.Length(protocol.Version1)-3, protocol.Version1)
Expect(f1).ToNot(BeNil())
@ -61,8 +61,8 @@ var _ = Describe("Retransmission queue", func() {
It("returns other frames when a CRYPTO frame wouldn't fit", func() {
f := &wire.CryptoFrame{Data: []byte("foobar")}
q.AddInitial(f)
q.AddInitial(&wire.PingFrame{})
q.addInitial(f)
q.addInitial(&wire.PingFrame{})
f1 := q.GetInitialFrame(2, protocol.Version1) // too small for a CRYPTO frame
Expect(f1).ToNot(BeNil())
Expect(f1).To(BeAssignableToTypeOf(&wire.PingFrame{}))
@ -74,8 +74,8 @@ var _ = Describe("Retransmission queue", func() {
It("retrieves both a CRYPTO frame and a control frame", func() {
cf := &wire.MaxDataFrame{MaximumData: 0x42}
f := &wire.CryptoFrame{Data: []byte("foobar")}
q.AddInitial(f)
q.AddInitial(cf)
q.addInitial(f)
q.addInitial(cf)
Expect(q.HasInitialData()).To(BeTrue())
Expect(q.GetInitialFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(f))
Expect(q.GetInitialFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(cf))
@ -83,8 +83,8 @@ var _ = Describe("Retransmission queue", func() {
})
It("drops all Initial frames", func() {
q.AddInitial(&wire.CryptoFrame{Data: []byte("foobar")})
q.AddInitial(&wire.MaxDataFrame{MaximumData: 0x42})
q.addInitial(&wire.CryptoFrame{Data: []byte("foobar")})
q.addInitial(&wire.MaxDataFrame{MaximumData: 0x42})
q.DropPackets(protocol.EncryptionInitial)
Expect(q.HasInitialData()).To(BeFalse())
Expect(q.GetInitialFrame(protocol.MaxByteCount, protocol.Version1)).To(BeNil())
@ -96,6 +96,12 @@ var _ = Describe("Retransmission queue", func() {
Expect(q.HasInitialData()).To(BeTrue())
Expect(q.GetInitialFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(f))
})
It("adds a PING", func() {
q.AddPing(protocol.EncryptionInitial)
Expect(q.HasInitialData()).To(BeTrue())
Expect(q.GetInitialFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(&wire.PingFrame{}))
})
})
Context("Handshake data", func() {
@ -106,7 +112,7 @@ var _ = Describe("Retransmission queue", func() {
It("queues and retrieves a control frame", func() {
f := &wire.MaxDataFrame{MaximumData: 0x42}
q.AddHandshake(f)
q.addHandshake(f)
Expect(q.HasHandshakeData()).To(BeTrue())
Expect(q.GetHandshakeFrame(f.Length(protocol.Version1)-1, protocol.Version1)).To(BeNil())
Expect(q.GetHandshakeFrame(f.Length(protocol.Version1), protocol.Version1)).To(Equal(f))
@ -115,7 +121,7 @@ var _ = Describe("Retransmission queue", func() {
It("queues and retrieves a CRYPTO frame", func() {
f := &wire.CryptoFrame{Data: []byte("foobar")}
q.AddHandshake(f)
q.addHandshake(f)
Expect(q.HasHandshakeData()).To(BeTrue())
Expect(q.GetHandshakeFrame(f.Length(protocol.Version1), protocol.Version1)).To(Equal(f))
Expect(q.HasHandshakeData()).To(BeFalse())
@ -126,7 +132,7 @@ var _ = Describe("Retransmission queue", func() {
Offset: 100,
Data: []byte("foobar"),
}
q.AddHandshake(f)
q.addHandshake(f)
Expect(q.HasHandshakeData()).To(BeTrue())
f1 := q.GetHandshakeFrame(f.Length(protocol.Version1)-3, protocol.Version1)
Expect(f1).ToNot(BeNil())
@ -144,8 +150,8 @@ var _ = Describe("Retransmission queue", func() {
It("returns other frames when a CRYPTO frame wouldn't fit", func() {
f := &wire.CryptoFrame{Data: []byte("foobar")}
q.AddHandshake(f)
q.AddHandshake(&wire.PingFrame{})
q.addHandshake(f)
q.addHandshake(&wire.PingFrame{})
f1 := q.GetHandshakeFrame(2, protocol.Version1) // too small for a CRYPTO frame
Expect(f1).ToNot(BeNil())
Expect(f1).To(BeAssignableToTypeOf(&wire.PingFrame{}))
@ -157,8 +163,8 @@ var _ = Describe("Retransmission queue", func() {
It("retrieves both a CRYPTO frame and a control frame", func() {
cf := &wire.MaxDataFrame{MaximumData: 0x42}
f := &wire.CryptoFrame{Data: []byte("foobar")}
q.AddHandshake(f)
q.AddHandshake(cf)
q.addHandshake(f)
q.addHandshake(cf)
Expect(q.HasHandshakeData()).To(BeTrue())
Expect(q.GetHandshakeFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(f))
Expect(q.GetHandshakeFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(cf))
@ -166,8 +172,8 @@ var _ = Describe("Retransmission queue", func() {
})
It("drops all Handshake frames", func() {
q.AddHandshake(&wire.CryptoFrame{Data: []byte("foobar")})
q.AddHandshake(&wire.MaxDataFrame{MaximumData: 0x42})
q.addHandshake(&wire.CryptoFrame{Data: []byte("foobar")})
q.addHandshake(&wire.MaxDataFrame{MaximumData: 0x42})
q.DropPackets(protocol.EncryptionHandshake)
Expect(q.HasHandshakeData()).To(BeFalse())
Expect(q.GetHandshakeFrame(protocol.MaxByteCount, protocol.Version1)).To(BeNil())
@ -179,6 +185,12 @@ var _ = Describe("Retransmission queue", func() {
Expect(q.HasHandshakeData()).To(BeTrue())
Expect(q.GetHandshakeFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(f))
})
It("adds a PING", func() {
q.AddPing(protocol.EncryptionHandshake)
Expect(q.HasHandshakeData()).To(BeTrue())
Expect(q.GetHandshakeFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(&wire.PingFrame{}))
})
})
Context("Application data", func() {
@ -189,7 +201,7 @@ var _ = Describe("Retransmission queue", func() {
It("queues and retrieves a control frame", func() {
f := &wire.MaxDataFrame{MaximumData: 0x42}
Expect(q.HasAppData()).To(BeFalse())
q.AddAppData(f)
q.addAppData(f)
Expect(q.HasAppData()).To(BeTrue())
Expect(q.GetAppDataFrame(f.Length(protocol.Version1)-1, protocol.Version1)).To(BeNil())
Expect(q.GetAppDataFrame(f.Length(protocol.Version1), protocol.Version1)).To(Equal(f))
@ -202,5 +214,11 @@ var _ = Describe("Retransmission queue", func() {
Expect(q.HasAppData()).To(BeTrue())
Expect(q.GetAppDataFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(f))
})
It("adds a PING", func() {
q.AddPing(protocol.Encryption1RTT)
Expect(q.HasAppData()).To(BeTrue())
Expect(q.GetAppDataFrame(protocol.MaxByteCount, protocol.Version1)).To(Equal(&wire.PingFrame{}))
})
})
})