mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-06 13:47:35 +03:00
fix limit of undecrytable packets queue length
fixes #517 Also fixes an off-by-one error, such that the queue now holds exactly protocol.MaxUndecrytablePackets packets when enough undecryptable packets are received.
This commit is contained in:
parent
2a9f214381
commit
8565fdf722
2 changed files with 24 additions and 7 deletions
12
session.go
12
session.go
|
@ -782,12 +782,16 @@ func (s *session) tryQueueingUndecryptablePacket(p *receivedPacket) {
|
||||||
if s.cryptoSetup.HandshakeComplete() {
|
if s.cryptoSetup.HandshakeComplete() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
utils.Infof("Queueing packet 0x%x for later decryption", p.publicHeader.PacketNumber)
|
if len(s.undecryptablePackets)+1 > protocol.MaxUndecryptablePackets {
|
||||||
if len(s.undecryptablePackets)+1 >= protocol.MaxUndecryptablePackets && s.receivedTooManyUndecrytablePacketsTime.IsZero() {
|
// if this is the first time the undecryptablePackets runs full, start the timer to send a Public Reset
|
||||||
s.receivedTooManyUndecrytablePacketsTime = time.Now()
|
if s.receivedTooManyUndecrytablePacketsTime.IsZero() {
|
||||||
s.maybeResetTimer()
|
s.receivedTooManyUndecrytablePacketsTime = time.Now()
|
||||||
|
s.maybeResetTimer()
|
||||||
|
}
|
||||||
|
utils.Infof("Dropping undecrytable packet 0x%x (undecryptable packet queue full)", p.publicHeader.PacketNumber)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
utils.Infof("Queueing packet 0x%x for later decryption", p.publicHeader.PacketNumber)
|
||||||
s.undecryptablePackets = append(s.undecryptablePackets, p)
|
s.undecryptablePackets = append(s.undecryptablePackets, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1193,7 +1193,7 @@ var _ = Describe("Session", func() {
|
||||||
Context("sending a Public Reset when receiving undecryptable packets during the handshake", func() {
|
Context("sending a Public Reset when receiving undecryptable packets during the handshake", func() {
|
||||||
It("doesn't immediately send a Public Reset after receiving too many undecryptable packets", func() {
|
It("doesn't immediately send a Public Reset after receiving too many undecryptable packets", func() {
|
||||||
go sess.run()
|
go sess.run()
|
||||||
for i := 0; i < protocol.MaxUndecryptablePackets; i++ {
|
for i := 0; i < protocol.MaxUndecryptablePackets+1; i++ {
|
||||||
hdr := &PublicHeader{
|
hdr := &PublicHeader{
|
||||||
PacketNumber: protocol.PacketNumber(i + 1),
|
PacketNumber: protocol.PacketNumber(i + 1),
|
||||||
}
|
}
|
||||||
|
@ -1205,7 +1205,7 @@ var _ = Describe("Session", func() {
|
||||||
|
|
||||||
It("sets a deadline to send a Public Reset after receiving too many undecryptable packets", func() {
|
It("sets a deadline to send a Public Reset after receiving too many undecryptable packets", func() {
|
||||||
go sess.run()
|
go sess.run()
|
||||||
for i := 0; i < protocol.MaxUndecryptablePackets; i++ {
|
for i := 0; i < protocol.MaxUndecryptablePackets+1; i++ {
|
||||||
hdr := &PublicHeader{
|
hdr := &PublicHeader{
|
||||||
PacketNumber: protocol.PacketNumber(i + 1),
|
PacketNumber: protocol.PacketNumber(i + 1),
|
||||||
}
|
}
|
||||||
|
@ -1214,6 +1214,19 @@ var _ = Describe("Session", func() {
|
||||||
Eventually(func() time.Time { return sess.receivedTooManyUndecrytablePacketsTime }).Should(BeTemporally("~", time.Now(), 10*time.Millisecond))
|
Eventually(func() time.Time { return sess.receivedTooManyUndecrytablePacketsTime }).Should(BeTemporally("~", time.Now(), 10*time.Millisecond))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("drops undecryptable packets when the undecrytable packet queue is full", func() {
|
||||||
|
go sess.run()
|
||||||
|
for i := 0; i < protocol.MaxUndecryptablePackets+10; i++ {
|
||||||
|
hdr := &PublicHeader{
|
||||||
|
PacketNumber: protocol.PacketNumber(i + 1),
|
||||||
|
}
|
||||||
|
sess.handlePacket(&receivedPacket{publicHeader: hdr, data: []byte("foobar")})
|
||||||
|
}
|
||||||
|
Eventually(func() []*receivedPacket { return sess.undecryptablePackets }).Should(HaveLen(protocol.MaxUndecryptablePackets))
|
||||||
|
// check that old packets are kept, and the new packets are dropped
|
||||||
|
Expect(sess.undecryptablePackets[0].publicHeader.PacketNumber).To(Equal(protocol.PacketNumber(1)))
|
||||||
|
})
|
||||||
|
|
||||||
It("sends a Public Reset after a timeout", func() {
|
It("sends a Public Reset after a timeout", func() {
|
||||||
sess.receivedTooManyUndecrytablePacketsTime = time.Now().Add(-protocol.PublicResetTimeout)
|
sess.receivedTooManyUndecrytablePacketsTime = time.Now().Add(-protocol.PublicResetTimeout)
|
||||||
go sess.run()
|
go sess.run()
|
||||||
|
@ -1226,7 +1239,7 @@ var _ = Describe("Session", func() {
|
||||||
|
|
||||||
It("ignores undecryptable packets after the handshake is complete", func() {
|
It("ignores undecryptable packets after the handshake is complete", func() {
|
||||||
*(*bool)(unsafe.Pointer(reflect.ValueOf(sess.cryptoSetup).Elem().FieldByName("receivedForwardSecurePacket").UnsafeAddr())) = true
|
*(*bool)(unsafe.Pointer(reflect.ValueOf(sess.cryptoSetup).Elem().FieldByName("receivedForwardSecurePacket").UnsafeAddr())) = true
|
||||||
for i := 0; i < protocol.MaxUndecryptablePackets; i++ {
|
for i := 0; i < protocol.MaxUndecryptablePackets+1; i++ {
|
||||||
hdr := &PublicHeader{
|
hdr := &PublicHeader{
|
||||||
PacketNumber: protocol.PacketNumber(i + 1),
|
PacketNumber: protocol.PacketNumber(i + 1),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue