@@ -97,6 +97,11 @@ impl Timers {
97
97
}
98
98
99
99
pub ( crate ) fn rekey_after_time_on_send ( & self ) -> Option < Instant > {
100
+ if !self . is_initiator {
101
+ // If we aren't the initiator of the current session, this timer does not matter.
102
+ return None ;
103
+ }
104
+
100
105
let session_established = self [ TimeSessionEstablished ] ;
101
106
102
107
if session_established >= self [ TimeLastDataPacketSent ] {
@@ -108,6 +113,11 @@ impl Timers {
108
113
}
109
114
110
115
pub ( crate ) fn reject_after_time_on_receive ( & self ) -> Option < Instant > {
116
+ if !self . is_initiator {
117
+ // If we aren't the initiator of the current session, this timer does not matter.
118
+ return None ;
119
+ }
120
+
111
121
let session_established = self [ TimeSessionEstablished ] ;
112
122
113
123
if session_established >= self [ TimeLastDataPacketReceived ] {
@@ -325,35 +335,33 @@ impl Tunn {
325
335
handshake_initiation_required = true ;
326
336
}
327
337
} else {
328
- if self . timers . is_initiator ( ) {
329
- // After sending a packet, if the sender was the original initiator
330
- // of the handshake and if the current session key is REKEY_AFTER_TIME
331
- // ms old, we initiate a new handshake. If the sender was the original
332
- // responder of the handshake, it does not re-initiate a new handshake
333
- // after REKEY_AFTER_TIME ms like the original initiator does.
334
- if self
335
- . timers
336
- . rekey_after_time_on_send ( )
337
- . is_some_and ( |deadline| now >= deadline)
338
- {
339
- tracing:: debug!( "HANDSHAKE(REKEY_AFTER_TIME (on send))" ) ;
340
- handshake_initiation_required = true ;
341
- }
338
+ // After sending a packet, if the sender was the original initiator
339
+ // of the handshake and if the current session key is REKEY_AFTER_TIME
340
+ // ms old, we initiate a new handshake. If the sender was the original
341
+ // responder of the handshake, it does not re-initiate a new handshake
342
+ // after REKEY_AFTER_TIME ms like the original initiator does.
343
+ if self
344
+ . timers
345
+ . rekey_after_time_on_send ( )
346
+ . is_some_and ( |deadline| now >= deadline)
347
+ {
348
+ tracing:: debug!( "HANDSHAKE(REKEY_AFTER_TIME (on send))" ) ;
349
+ handshake_initiation_required = true ;
350
+ }
342
351
343
- // After receiving a packet, if the receiver was the original initiator
344
- // of the handshake and if the current session key is REJECT_AFTER_TIME
345
- // - KEEPALIVE_TIMEOUT - REKEY_TIMEOUT ms old, we initiate a new
346
- // handshake.
347
- if self
348
- . timers
349
- . reject_after_time_on_receive ( )
350
- . is_some_and ( |deadline| now >= deadline)
351
- {
352
- tracing:: debug!(
353
- "HANDSHAKE(REJECT_AFTER_TIME - KEEPALIVE_TIMEOUT - REKEY_TIMEOUT (on receive))"
354
- ) ;
355
- handshake_initiation_required = true ;
356
- }
352
+ // After receiving a packet, if the receiver was the original initiator
353
+ // of the handshake and if the current session key is REJECT_AFTER_TIME
354
+ // - KEEPALIVE_TIMEOUT - REKEY_TIMEOUT ms old, we initiate a new
355
+ // handshake.
356
+ if self
357
+ . timers
358
+ . reject_after_time_on_receive ( )
359
+ . is_some_and ( |deadline| now >= deadline)
360
+ {
361
+ tracing:: debug!(
362
+ "HANDSHAKE(REJECT_AFTER_TIME - KEEPALIVE_TIMEOUT - REKEY_TIMEOUT (on receive))"
363
+ ) ;
364
+ handshake_initiation_required = true ;
357
365
}
358
366
359
367
// If we have sent a packet to a given peer but have not received a
0 commit comments