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