diff --git a/performance/src/zssp.rs b/performance/src/zssp.rs index c305205..7d99ffa 100644 --- a/performance/src/zssp.rs +++ b/performance/src/zssp.rs @@ -619,6 +619,25 @@ impl Context { } /// Perform periodic background service and cleanup tasks. /// + /// This returns the number of milliseconds until it should be called again. The caller should + /// try to satisfy this but small variations in timing of up to +/- a second or two are not + /// a problem. + /// + /// * `app` - Interface to application using ZSSP + /// * `send_to` - Function to get a sender and an MTU to send something over an active session + pub fn service, SendFn: FnMut(&mut [u8]) -> bool>( + &self, + mut app: App, + send_to: impl FnMut(&Arc>) -> Option<(SendFn, usize)>, + ) -> i64 { + let current_time = app.time(); + let next_service_time = self.service_inner(app, send_to, current_time); + let max_interval = Crypto::SETTINGS.fragment_assembly_timeout.min(Crypto::SETTINGS.rekey_timeout).min(Crypto::SETTINGS.initial_offer_timeout); + + (next_service_time - current_time).min(max_interval as i64) + } + /// Perform periodic background service and cleanup tasks. + /// /// This returns exact timestamp at which this function should be called again, or `i64::MAX` if /// there is currently no reason to call this again. However, future calls to `Context::open` /// and `Context::receive` can and will change this timestamp. Both of these functions return @@ -638,26 +657,6 @@ impl Context { let current_time = app.time(); self.service_inner(app, send_to, current_time) } - - /// Perform periodic background service and cleanup tasks. - /// - /// This returns the number of milliseconds until it should be called again. The caller should - /// try to satisfy this but small variations in timing of up to +/- a second or two are not - /// a problem. - /// - /// * `app` - Interface to application using ZSSP - /// * `send_to` - Function to get a sender and an MTU to send something over an active session - pub fn service, SendFn: FnMut(&mut [u8]) -> bool>( - &self, - mut app: App, - send_to: impl FnMut(&Arc>) -> Option<(SendFn, usize)>, - ) -> i64 { - let current_time = app.time(); - let next_service_time = self.service_inner(app, send_to, current_time); - let max_interval = Crypto::SETTINGS.fragment_assembly_timeout.min(Crypto::SETTINGS.rekey_timeout).min(Crypto::SETTINGS.initial_offer_timeout); - - (next_service_time - current_time).min(max_interval as i64) - } fn service_inner, SendFn: FnMut(&mut [u8]) -> bool>( &self, mut app: App, @@ -714,4 +713,9 @@ impl Context { t1.min(t2) } + /// Returns the exact timestamp at which either `Context::service` or + /// `Context::service_scheduled` should be called again. + pub fn next_service_time(&self) -> i64 { + self.0.next_service_time.load(Ordering::Relaxed) + } }