@@ -48,7 +48,9 @@ pub struct Timers {
48
48
/// Did we receive data without sending anything back?
49
49
want_keepalive : bool ,
50
50
/// Did we send data without hearing back?
51
- want_handshake : bool ,
51
+ ///
52
+ /// If `Some`, holds the _first_ instant when we sent a packet.
53
+ want_handshake_since : Option < Instant > ,
52
54
persistent_keepalive : usize ,
53
55
/// Should this timer call reset rr function (if not a shared rr instance)
54
56
pub ( super ) should_reset_rr : bool ,
@@ -69,7 +71,7 @@ impl Timers {
69
71
is_initiator : false ,
70
72
timers : [ now; TimerName :: Top as usize ] ,
71
73
want_keepalive : Default :: default ( ) ,
72
- want_handshake : Default :: default ( ) ,
74
+ want_handshake_since : Default :: default ( ) ,
73
75
persistent_keepalive : usize:: from ( persistent_keepalive. unwrap_or ( 0 ) ) ,
74
76
should_reset_rr : reset_rr,
75
77
send_handshake_at : None ,
@@ -118,9 +120,7 @@ impl Timers {
118
120
}
119
121
120
122
pub ( crate ) fn rekey_after_time_without_response ( & self ) -> Option < Instant > {
121
- if !self . want_handshake {
122
- return None ;
123
- }
123
+ let first_packet_without_reply = self . want_handshake_since ?;
124
124
125
125
let last_data_packet_sent = self [ TimeLastDataPacketSent ] ;
126
126
let last_packet_received = self [ TimeLastPacketReceived ] ;
@@ -130,7 +130,7 @@ impl Timers {
130
130
return None ;
131
131
}
132
132
133
- Some ( last_packet_received + KEEPALIVE_TIMEOUT + REKEY_TIMEOUT )
133
+ Some ( first_packet_without_reply + KEEPALIVE_TIMEOUT + REKEY_TIMEOUT )
134
134
}
135
135
136
136
pub ( crate ) fn keepalive_after_time_without_send ( & self ) -> Option < Instant > {
@@ -169,7 +169,7 @@ impl Timers {
169
169
for t in & mut self . timers [ ..] {
170
170
* t = now;
171
171
}
172
- self . want_handshake = false ;
172
+ self . want_handshake_since = None ;
173
173
self . want_keepalive = false ;
174
174
}
175
175
}
@@ -192,12 +192,20 @@ impl Tunn {
192
192
match timer_name {
193
193
TimeLastPacketReceived => {
194
194
self . timers . want_keepalive = true ;
195
- self . timers . want_handshake = false ;
195
+ self . timers . want_handshake_since = None ;
196
196
}
197
197
TimeLastPacketSent => {
198
- self . timers . want_handshake = true ;
199
198
self . timers . want_keepalive = false ;
200
199
}
200
+ TimeLastDataPacketSent => {
201
+ match self . timers . want_handshake_since {
202
+ Some ( _) => { } // Already waiting for a reply, don't update the timestamp.
203
+ None => {
204
+ // This is the first packet to not be replied to, start tracking the time.
205
+ self . timers . want_handshake_since = Some ( now)
206
+ }
207
+ }
208
+ }
201
209
_ => { }
202
210
}
203
211
0 commit comments