@@ -86,6 +86,11 @@ impl Timers {
8686 }
8787
8888 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+
8994 let session_established = self [ TimeSessionEstablished ] ;
9095
9196 if session_established >= self [ TimeLastDataPacketSent ] {
@@ -97,6 +102,11 @@ impl Timers {
97102 }
98103
99104 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+
100110 let session_established = self [ TimeSessionEstablished ] ;
101111
102112 if session_established >= self [ TimeLastDataPacketReceived ] {
@@ -317,35 +327,33 @@ impl Tunn {
317327 handshake_initiation_required = true ;
318328 }
319329 } 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+ }
334343
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 ;
349357 }
350358
351359 // If we have sent a packet to a given peer but have not received a
0 commit comments