mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 13:17:36 +03:00
use PacketNumberGenerator in PacketPacker
This commit is contained in:
parent
86d73970fc
commit
78fab5c264
3 changed files with 34 additions and 6 deletions
|
@ -22,7 +22,9 @@ type packetPacker struct {
|
|||
connectionID protocol.ConnectionID
|
||||
version protocol.VersionNumber
|
||||
cryptoSetup *handshake.CryptoSetup
|
||||
lastPacketNumber protocol.PacketNumber
|
||||
|
||||
lastPacketNumber protocol.PacketNumber // TODO: remove when dropping support for QUIC 33
|
||||
packetNumberGenerator *packetNumberGenerator
|
||||
|
||||
connectionParametersManager *handshake.ConnectionParametersManager
|
||||
|
||||
|
@ -31,13 +33,19 @@ type packetPacker struct {
|
|||
}
|
||||
|
||||
func newPacketPacker(connectionID protocol.ConnectionID, cryptoSetup *handshake.CryptoSetup, connectionParametersHandler *handshake.ConnectionParametersManager, streamFramer *streamFramer, version protocol.VersionNumber) *packetPacker {
|
||||
return &packetPacker{
|
||||
p := &packetPacker{
|
||||
cryptoSetup: cryptoSetup,
|
||||
connectionID: connectionID,
|
||||
connectionParametersManager: connectionParametersHandler,
|
||||
version: version,
|
||||
streamFramer: streamFramer,
|
||||
}
|
||||
|
||||
if version >= protocol.Version34 {
|
||||
p.packetNumberGenerator = newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength)
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *packetPacker) PackConnectionClose(frame *frames.ConnectionCloseFrame, leastUnacked protocol.PacketNumber) (*packedPacket, error) {
|
||||
|
@ -53,7 +61,12 @@ func (p *packetPacker) packPacket(stopWaitingFrame *frames.StopWaitingFrame, con
|
|||
p.controlFrames = append(p.controlFrames, controlFrames...)
|
||||
}
|
||||
|
||||
currentPacketNumber := p.lastPacketNumber + 1
|
||||
var currentPacketNumber protocol.PacketNumber
|
||||
if p.version <= protocol.Version33 {
|
||||
currentPacketNumber = p.lastPacketNumber + 1
|
||||
} else {
|
||||
currentPacketNumber = p.packetNumberGenerator.GetNextPacketNumber()
|
||||
}
|
||||
|
||||
// cryptoSetup needs to be locked here, so that the AEADs are not changed between
|
||||
// calling DiversificationNonce() and Seal().
|
||||
|
|
|
@ -28,6 +28,7 @@ var _ = Describe("Packet packer", func() {
|
|||
packer = &packetPacker{
|
||||
cryptoSetup: &handshake.CryptoSetup{},
|
||||
connectionParametersManager: handshake.NewConnectionParamatersManager(),
|
||||
packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength),
|
||||
streamFramer: streamFramer,
|
||||
}
|
||||
publicHeaderLen = 1 + 8 + 1 // 1 flag byte, 8 connection ID, 1 packet number
|
||||
|
@ -112,6 +113,16 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(p.raw).NotTo(BeEmpty())
|
||||
})
|
||||
|
||||
It("increases the packet number", func() {
|
||||
p1, err := packer.PackPacket(nil, []frames.Frame{&frames.ConnectionCloseFrame{}}, 0, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p1).ToNot(BeNil())
|
||||
p2, err := packer.PackPacket(nil, []frames.Frame{&frames.ConnectionCloseFrame{}}, 0, true)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p2).ToNot(BeNil())
|
||||
Expect(p2.number).To(BeNumerically(">", p1.number))
|
||||
})
|
||||
|
||||
It("packs a StopWaitingFrame first", func() {
|
||||
swf := &frames.StopWaitingFrame{LeastUnacked: 10}
|
||||
p, err := packer.PackPacket(swf, []frames.Frame{&frames.ConnectionCloseFrame{}}, 0, true)
|
||||
|
@ -122,6 +133,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("sets the LeastUnackedDelta length of a StopWaitingFrame", func() {
|
||||
packer.version = protocol.Version33 // TODO: find a different way to test this when dropping support for QUIC 33
|
||||
packetNumber := protocol.PacketNumber(0xDECAFB) // will result in a 4 byte packet number
|
||||
packer.lastPacketNumber = packetNumber - 1
|
||||
swf := &frames.StopWaitingFrame{LeastUnacked: packetNumber - 0x100}
|
||||
|
|
|
@ -44,6 +44,9 @@ const MaxSessionUnprocessedPackets = 128
|
|||
// RetransmissionThreshold + 1 is the number of times a packet has to be NACKed so that it gets retransmitted
|
||||
const RetransmissionThreshold uint8 = 3
|
||||
|
||||
// SkipPacketAveragePeriodLength is the average period length in which one packet number is skipped to prevent an Optimistic ACK attack
|
||||
const SkipPacketAveragePeriodLength PacketNumber = 500
|
||||
|
||||
// STKExpiryTimeSec is the valid time of a source address token in seconds
|
||||
const STKExpiryTimeSec = 24 * 60 * 60
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue