@@ -467,7 +467,7 @@ func (p *packetPacker) PackPacket() (*packedPacket, error) {
467
467
}, nil
468
468
}
469
469
470
- func (p * packetPacker ) maybeGetCryptoPacket (maxSize , currentSize protocol.ByteCount , encLevel protocol.EncryptionLevel ) (* wire.ExtendedHeader , * payload ) {
470
+ func (p * packetPacker ) maybeGetCryptoPacket (maxPacketSize , currentSize protocol.ByteCount , encLevel protocol.EncryptionLevel ) (* wire.ExtendedHeader , * payload ) {
471
471
var s cryptoStream
472
472
var hasRetransmission bool
473
473
//nolint:exhaustive // Initial and Handshake are the only two encryption levels here.
@@ -494,30 +494,30 @@ func (p *packetPacker) maybeGetCryptoPacket(maxSize, currentSize protocol.ByteCo
494
494
if ack != nil {
495
495
payload .ack = ack
496
496
payload .length = ack .Length (p .version )
497
- maxSize -= payload .length
497
+ maxPacketSize -= payload .length
498
498
}
499
499
hdr := p .getLongHeader (encLevel )
500
- maxSize -= hdr .GetLength (p .version )
500
+ maxPacketSize -= hdr .GetLength (p .version )
501
501
if hasRetransmission {
502
502
for {
503
503
var f wire.Frame
504
504
//nolint:exhaustive // 0-RTT packets can't contain any retransmission.s
505
505
switch encLevel {
506
506
case protocol .EncryptionInitial :
507
- f = p .retransmissionQueue .GetInitialFrame (maxSize )
507
+ f = p .retransmissionQueue .GetInitialFrame (maxPacketSize )
508
508
case protocol .EncryptionHandshake :
509
- f = p .retransmissionQueue .GetHandshakeFrame (maxSize )
509
+ f = p .retransmissionQueue .GetHandshakeFrame (maxPacketSize )
510
510
}
511
511
if f == nil {
512
512
break
513
513
}
514
514
payload .frames = append (payload .frames , ackhandler.Frame {Frame : f })
515
515
frameLen := f .Length (p .version )
516
516
payload .length += frameLen
517
- maxSize -= frameLen
517
+ maxPacketSize -= frameLen
518
518
}
519
519
} else if s .HasData () {
520
- cf := s .PopCryptoFrame (maxSize )
520
+ cf := s .PopCryptoFrame (maxPacketSize )
521
521
payload .frames = []ackhandler.Frame {{Frame : cf }}
522
522
payload .length += cf .Length (p .version )
523
523
}
@@ -547,18 +547,19 @@ func (p *packetPacker) maybeGetAppDataPacket(maxPacketSize, currentSize protocol
547
547
}
548
548
549
549
maxPayloadSize := maxPacketSize - hdr .GetLength (p .version ) - protocol .ByteCount (sealer .Overhead ())
550
- payload := p .maybeGetAppDataPacketWithEncLevel (maxPayloadSize , currentSize , encLevel )
550
+ payload := p .maybeGetAppDataPacketWithEncLevel (maxPayloadSize , encLevel == protocol . Encryption1RTT && currentSize == 0 )
551
551
return sealer , hdr , payload
552
552
}
553
553
554
- func (p * packetPacker ) maybeGetAppDataPacketWithEncLevel (maxPayloadSize , currentSize protocol.ByteCount , encLevel protocol. EncryptionLevel ) * payload {
555
- payload := p .composeNextPacket (maxPayloadSize , encLevel == protocol . Encryption1RTT && currentSize == 0 )
554
+ func (p * packetPacker ) maybeGetAppDataPacketWithEncLevel (maxPayloadSize protocol.ByteCount , ackAllowed bool ) * payload {
555
+ payload := p .composeNextPacket (maxPayloadSize , ackAllowed )
556
556
557
557
// check if we have anything to send
558
- if len (payload .frames ) == 0 && payload .ack == nil {
559
- return nil
560
- }
561
- if len (payload .frames ) == 0 { // the packet only contains an ACK
558
+ if len (payload .frames ) == 0 {
559
+ if payload .ack == nil {
560
+ return nil
561
+ }
562
+ // the packet only contains an ACK
562
563
if p .numNonAckElicitingAcks >= protocol .MaxNonAckElicitingAcks {
563
564
ping := & wire.PingFrame {}
564
565
payload .frames = append (payload .frames , ackhandler.Frame {Frame : ping })
@@ -642,14 +643,12 @@ func (p *packetPacker) MaybePackProbePacket(encLevel protocol.EncryptionLevel) (
642
643
return nil , err
643
644
}
644
645
sealer = oneRTTSealer
645
- payload = p .maybeGetAppDataPacketWithEncLevel (p .maxPacketSize - protocol .ByteCount (sealer .Overhead ()), 0 , protocol .Encryption1RTT )
646
- if payload != nil {
647
- hdr = p .getShortHeader (oneRTTSealer .KeyPhase ())
648
- }
646
+ hdr = p .getShortHeader (oneRTTSealer .KeyPhase ())
647
+ payload = p .maybeGetAppDataPacketWithEncLevel (p .maxPacketSize - protocol .ByteCount (sealer .Overhead ())- hdr .GetLength (p .version ), true )
649
648
default :
650
649
panic ("unknown encryption level" )
651
650
}
652
- if hdr == nil {
651
+ if payload == nil {
653
652
return nil , nil
654
653
}
655
654
size := p .packetLength (hdr , payload ) + protocol .ByteCount (sealer .Overhead ())
0 commit comments