taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit 85f6f177780ebc84dcb96dda59c3f9c20ed5ede4
parent a4f4b202c1e861b136146b52e75d4e5582665c21
Author: Antoine A <>
Date:   Wed,  9 Jul 2025 14:06:30 +0200

common: add jitter

Diffstat:
MCargo.lock | 25+++++++++++++++++++------
Mcommon/taler-common/src/lib.rs | 37++++++++++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -237,9 +237,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.27" +version = "1.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" +checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" dependencies = [ "shlex", ] @@ -984,9 +984,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb" +checksum = "7f66d5bd4c6f02bf0542fad85d626775bab9258cf795a4256dcaf3161114d1df" dependencies = [ "base64", "bytes", @@ -1130,6 +1130,17 @@ dependencies = [ ] [[package]] +name = "io-uring" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" +dependencies = [ + "bitflags", + "cfg-if", + "libc", +] + +[[package]] name = "ipnet" version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2395,16 +2406,18 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.45.1" +version = "1.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" +checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" dependencies = [ "backtrace", "bytes", + "io-uring", "libc", "mio", "pin-project-lite", "signal-hook-registry", + "slab", "socket2", "tokio-macros", "windows-sys 0.52.0", diff --git a/common/taler-common/src/lib.rs b/common/taler-common/src/lib.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -use std::{future::Future, io::IsTerminal, path::PathBuf}; +use std::{future::Future, io::IsTerminal, path::PathBuf, time::Duration}; use config::{Config, parser::ConfigSource}; use log::TalerTime; @@ -82,3 +82,38 @@ pub fn taler_main<F: Future<Output = Result<(), anyhow::Error>>>( std::process::exit(1); } } + +/// Infinite exponential backoff with decorrelated jitter +pub struct ExpoBackoffDecorr { + base: u32, + max: u32, + factor: f32, + sleep: u32, +} + +impl ExpoBackoffDecorr { + pub fn new(base: u32, max: u32, factor: f32) -> Self { + Self { + base, + max, + factor, + sleep: base, + } + } + + pub fn next(&mut self) -> Duration { + self.sleep = + fastrand::u32(self.base..(self.sleep as f32 * self.factor) as u32).min(self.max); + return Duration::from_millis(self.sleep as u64); + } + + pub fn reset(&mut self) { + self.sleep = self.base + } +} + +impl Default for ExpoBackoffDecorr { + fn default() -> Self { + Self::new(200, 15 * 1000, 2.0) + } +}