2026-06-24 01:47:26 +08:00
|
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
2026-04-07 02:50:19 +08:00
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
|
|
2026-06-24 01:47:26 +08:00
|
|
|
static REQUEST_DISTRIBUTION_COUNTER: AtomicU64 = AtomicU64::new(0);
|
|
|
|
|
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) fn current_unix_secs() -> u64 {
|
|
|
|
|
SystemTime::now()
|
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
.as_secs()
|
|
|
|
|
}
|
2026-04-10 01:46:14 +08:00
|
|
|
|
|
|
|
|
pub(crate) fn current_unix_ms() -> u64 {
|
|
|
|
|
SystemTime::now()
|
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
.as_millis() as u64
|
|
|
|
|
}
|
2026-06-24 01:47:26 +08:00
|
|
|
|
|
|
|
|
pub(crate) fn request_distribution_seed() -> u64 {
|
|
|
|
|
let now_ms = current_unix_ms();
|
|
|
|
|
let counter = REQUEST_DISTRIBUTION_COUNTER.fetch_add(1, Ordering::Relaxed);
|
|
|
|
|
now_ms.rotate_left(21) ^ counter
|
|
|
|
|
}
|