mirror of
https://github.com/telemt/telemt.git
synced 2026-07-23 22:16:13 +03:00
Update dependencies and refactor random number generation
- Bump versions of several dependencies in Cargo.toml for improved functionality and security, including: - socket2 to 0.6 - nix to 0.31 - toml to 1.0 - x509-parser to 0.18 - dashmap to 6.1 - rand to 0.10 - reqwest to 0.13 - notify to 8.2 - ipnetwork to 0.21 - webpki-roots to 1.0 - criterion to 0.8 - Introduce `OnceLock` for secure random number generation in multiple modules to ensure thread safety and reduce overhead. - Refactor random number generation calls to use the new `RngExt` trait methods for consistency and clarity. - Add new PNG files for architectural documentation.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use rand::Rng;
|
||||
use rand::RngExt;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::pin::Pin;
|
||||
@@ -600,7 +600,7 @@ impl UpstreamManager {
|
||||
return self.connect_retry_backoff;
|
||||
}
|
||||
let jitter_cap_ms = (base_ms / 2).max(1);
|
||||
let jitter_ms = rand::rng().gen_range(0..=jitter_cap_ms);
|
||||
let jitter_ms = rand::rng().random_range(0..=jitter_cap_ms);
|
||||
Duration::from_millis(base_ms.saturating_add(jitter_ms))
|
||||
}
|
||||
|
||||
@@ -667,7 +667,7 @@ impl UpstreamManager {
|
||||
"No healthy upstreams available! Using random."
|
||||
);
|
||||
}
|
||||
return Some(filtered_upstreams[rand::rng().gen_range(0..filtered_upstreams.len())]);
|
||||
return Some(filtered_upstreams[rand::rng().random_range(0..filtered_upstreams.len())]);
|
||||
}
|
||||
|
||||
if healthy.len() == 1 {
|
||||
@@ -690,10 +690,10 @@ impl UpstreamManager {
|
||||
let total: f64 = weights.iter().map(|(_, w)| w).sum();
|
||||
|
||||
if total <= 0.0 {
|
||||
return Some(healthy[rand::rng().gen_range(0..healthy.len())]);
|
||||
return Some(healthy[rand::rng().random_range(0..healthy.len())]);
|
||||
}
|
||||
|
||||
let mut choice: f64 = rand::rng().gen_range(0.0..total);
|
||||
let mut choice: f64 = rand::rng().random_range(0.0..total);
|
||||
|
||||
for &(idx, weight) in &weights {
|
||||
if choice < weight {
|
||||
|
||||
Reference in New Issue
Block a user