mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 21:27:35 +03:00
pass the time a packet was received to the short header opener
This saves us one time.Now() syscall per received 1-RTT packet.
This commit is contained in:
parent
ee00cbe088
commit
bb48c9b31a
9 changed files with 92 additions and 80 deletions
internal/handshake
|
@ -91,14 +91,14 @@ func newUpdatableAEAD(rttStats *congestion.RTTStats, logger utils.Logger) *updat
|
|||
}
|
||||
}
|
||||
|
||||
func (a *updatableAEAD) rollKeys() {
|
||||
func (a *updatableAEAD) rollKeys(now time.Time) {
|
||||
a.keyPhase++
|
||||
a.firstRcvdWithCurrentKey = protocol.InvalidPacketNumber
|
||||
a.firstSentWithCurrentKey = protocol.InvalidPacketNumber
|
||||
a.numRcvdWithCurrentKey = 0
|
||||
a.numSentWithCurrentKey = 0
|
||||
a.prevRcvAEAD = a.rcvAEAD
|
||||
a.prevRcvAEADExpiry = time.Now().Add(3 * a.rttStats.PTO())
|
||||
a.prevRcvAEADExpiry = now.Add(3 * a.rttStats.PTO())
|
||||
a.rcvAEAD = a.nextRcvAEAD
|
||||
a.sendAEAD = a.nextSendAEAD
|
||||
|
||||
|
@ -142,8 +142,8 @@ func (a *updatableAEAD) SetWriteKey(suite cipherSuite, trafficSecret []byte) {
|
|||
a.nextSendAEAD = createAEAD(suite, a.nextSendTrafficSecret)
|
||||
}
|
||||
|
||||
func (a *updatableAEAD) Open(dst, src []byte, pn protocol.PacketNumber, kp protocol.KeyPhaseBit, ad []byte) ([]byte, error) {
|
||||
if a.prevRcvAEAD != nil && time.Now().After(a.prevRcvAEADExpiry) {
|
||||
func (a *updatableAEAD) Open(dst, src []byte, rcvTime time.Time, pn protocol.PacketNumber, kp protocol.KeyPhaseBit, ad []byte) ([]byte, error) {
|
||||
if a.prevRcvAEAD != nil && rcvTime.After(a.prevRcvAEADExpiry) {
|
||||
a.prevRcvAEAD = nil
|
||||
a.prevRcvAEADExpiry = time.Time{}
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ func (a *updatableAEAD) Open(dst, src []byte, pn protocol.PacketNumber, kp proto
|
|||
if a.firstSentWithCurrentKey == protocol.InvalidPacketNumber {
|
||||
return nil, qerr.Error(qerr.ProtocolViolation, "keys updated too quickly")
|
||||
}
|
||||
a.rollKeys()
|
||||
a.rollKeys(rcvTime)
|
||||
a.logger.Debugf("Peer updated keys to %s", a.keyPhase)
|
||||
a.firstRcvdWithCurrentKey = pn
|
||||
return dec, err
|
||||
|
@ -232,7 +232,7 @@ func (a *updatableAEAD) shouldInitiateKeyUpdate() bool {
|
|||
|
||||
func (a *updatableAEAD) KeyPhase() protocol.KeyPhaseBit {
|
||||
if a.shouldInitiateKeyUpdate() {
|
||||
a.rollKeys()
|
||||
a.rollKeys(time.Now())
|
||||
}
|
||||
return a.keyPhase.Bit()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue