33
44use super :: errors:: WireGuardError ;
55use crate :: noise:: { Tunn , TunnResult } ;
6- use crate :: sleepyinstant:: ClockImpl ;
76use crate :: sleepyinstant:: Instant ;
7+ use crate :: sleepyinstant:: { ClockDuration , ClockUnit } ;
88use core:: mem;
99use core:: ops:: { Index , IndexMut } ;
10- use embedded_time:: duration:: { Generic , Seconds } ;
11- use embedded_time:: Clock ;
10+ use embedded_time:: duration:: Seconds ;
1211
1312// Some constants, represent time in seconds
1413// https://www.wireguard.com/papers/wireguard.pdf#page=14
@@ -50,8 +49,8 @@ pub struct Timers {
5049 is_initiator : bool ,
5150 /// Start time of the tunnel
5251 time_started : Instant ,
53- timers : [ Generic < < ClockImpl as Clock > :: T > ; TimerName :: Top as usize ] ,
54- pub ( super ) session_timers : [ Generic < < ClockImpl as Clock > :: T > ; super :: N_SESSIONS ] ,
52+ timers : [ ClockDuration ; TimerName :: Top as usize ] ,
53+ pub ( super ) session_timers : [ ClockDuration ; super :: N_SESSIONS ] ,
5554 /// Did we receive data without sending anything back?
5655 want_keepalive : bool ,
5756 /// Did we send data without hearing back?
@@ -92,14 +91,14 @@ impl Timers {
9291}
9392
9493impl Index < TimerName > for Timers {
95- type Output = Generic < < ClockImpl as Clock > :: T > ;
96- fn index ( & self , index : TimerName ) -> & Generic < < ClockImpl as Clock > :: T > {
94+ type Output = ClockDuration ;
95+ fn index ( & self , index : TimerName ) -> & ClockDuration {
9796 & self . timers [ index as usize ]
9897 }
9998}
10099
101100impl IndexMut < TimerName > for Timers {
102- fn index_mut ( & mut self , index : TimerName ) -> & mut Generic < < ClockImpl as Clock > :: T > {
101+ fn index_mut ( & mut self , index : TimerName ) -> & mut ClockDuration {
103102 & mut self . timers [ index as usize ]
104103 }
105104}
@@ -145,7 +144,7 @@ impl Tunn {
145144 self . timers . clear ( ) ;
146145 }
147146
148- fn update_session_timers ( & mut self , time_now : Generic < < ClockImpl as Clock > :: T > ) {
147+ fn update_session_timers ( & mut self , time_now : ClockDuration ) {
149148 let timers = & mut self . timers ;
150149
151150 for ( i, t) in timers. session_timers . iter_mut ( ) . enumerate ( ) {
@@ -286,7 +285,7 @@ impl Tunn {
286285 // Persistent KEEPALIVE
287286 if persistent_keepalive > 0
288287 && ( now - self . timers [ TimePersistentKeepalive ]
289- >= Seconds :: < < ClockImpl as Clock > :: T > ( persistent_keepalive as _ ) )
288+ >= Seconds :: < ClockUnit > ( persistent_keepalive as _ ) )
290289 {
291290 tracing:: debug!( "KEEPALIVE(PERSISTENT_KEEPALIVE)" ) ;
292291 self . timer_tick ( TimePersistentKeepalive ) ;
@@ -307,7 +306,7 @@ impl Tunn {
307306 TunnResult :: Done
308307 }
309308
310- pub fn time_since_last_handshake ( & self ) -> Option < Generic < < ClockImpl as Clock > :: T > > {
309+ pub fn time_since_last_handshake ( & self ) -> Option < ClockDuration > {
311310 let current_session = self . current ;
312311 if self . sessions [ current_session % super :: N_SESSIONS ] . is_some ( ) {
313312 let duration_since_tun_start = Instant :: now ( ) . duration_since ( self . timers . time_started ) ;
0 commit comments