@@ -60,10 +60,8 @@ pub struct Timers {
60
60
///
61
61
/// If `Some`, tracks the timestamp when we want to send a keepalive.
62
62
want_passive_keepalive_at : Option < Instant > ,
63
- /// Did we send data without hearing back?
64
- ///
65
- /// If `Some`, tracks the timestamp when we want to initiate the new handshake.
66
- want_handshake_at : Option < Instant > ,
63
+ /// The earliest data packet we sent without receiving a reply.
64
+ first_data_sent_without_reply : Option < Instant > ,
67
65
persistent_keepalive : usize ,
68
66
/// Should this timer call reset rr function (if not a shared rr instance)
69
67
pub ( super ) should_reset_rr : bool ,
@@ -84,7 +82,7 @@ impl Timers {
84
82
is_initiator : false ,
85
83
timers : [ now; TimerName :: Top as usize ] ,
86
84
want_passive_keepalive_at : Default :: default ( ) ,
87
- want_handshake_at : Default :: default ( ) ,
85
+ first_data_sent_without_reply : Default :: default ( ) ,
88
86
persistent_keepalive : usize:: from ( persistent_keepalive. unwrap_or ( 0 ) ) ,
89
87
should_reset_rr : reset_rr,
90
88
send_handshake_at : None ,
@@ -122,6 +120,12 @@ impl Timers {
122
120
Some ( session_established + REJECT_AFTER_TIME - KEEPALIVE_TIMEOUT - REKEY_TIMEOUT )
123
121
}
124
122
123
+ pub ( crate ) fn rekey_after_time_without_response ( & self ) -> Option < Instant > {
124
+ let first_packet_without_reply = self . first_data_sent_without_reply ?;
125
+
126
+ Some ( first_packet_without_reply + KEEPALIVE_TIMEOUT + REKEY_TIMEOUT )
127
+ }
128
+
125
129
fn is_initiator ( & self ) -> bool {
126
130
self . is_initiator
127
131
}
@@ -136,7 +140,7 @@ impl Timers {
136
140
for t in & mut self . timers [ ..] {
137
141
* t = now;
138
142
}
139
- self . want_handshake_at = None ;
143
+ self . first_data_sent_without_reply = None ;
140
144
self . want_passive_keepalive_at = None ;
141
145
}
142
146
}
@@ -158,7 +162,7 @@ impl Tunn {
158
162
pub ( super ) fn timer_tick ( & mut self , timer_name : TimerName , now : Instant ) {
159
163
match timer_name {
160
164
TimeLastPacketReceived => {
161
- self . timers . want_handshake_at = None ;
165
+ self . timers . first_data_sent_without_reply = None ;
162
166
}
163
167
TimeLastPacketSent => {
164
168
self . timers . want_passive_keepalive_at = None ;
@@ -167,16 +171,14 @@ impl Tunn {
167
171
self . timers . want_passive_keepalive_at = Some ( now + KEEPALIVE_TIMEOUT ) ;
168
172
}
169
173
TimeLastDataPacketSent => {
170
- match self . timers . want_handshake_at {
174
+ match self . timers . first_data_sent_without_reply {
171
175
Some ( _) => {
172
176
// This isn't the first timer tick (i.e. not the first packet)
173
177
// we haven't received a response to.
174
178
}
175
179
None => {
176
180
// We sent a packet and haven't heard back yet.
177
- // Start a timer for when we want to make a new handshake.
178
- self . timers . want_handshake_at =
179
- Some ( now + KEEPALIVE_TIMEOUT + REKEY_TIMEOUT )
181
+ self . timers . first_data_sent_without_reply = Some ( now)
180
182
}
181
183
}
182
184
}
@@ -352,8 +354,8 @@ impl Tunn {
352
354
// we initiate a new handshake.
353
355
if self
354
356
. timers
355
- . want_handshake_at
356
- . is_some_and ( |handshake_at | now >= handshake_at )
357
+ . rekey_after_time_without_response ( )
358
+ . is_some_and ( |deadline | now >= deadline )
357
359
{
358
360
tracing:: debug!( "HANDSHAKE(KEEPALIVE + REKEY_TIMEOUT)" ) ;
359
361
handshake_initiation_required = true ;
0 commit comments