removing dev branch, many changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// LogThru
|
||||
// Pass errors through and log them simultaneously via map_err()
|
||||
// Also contains common log facilities (net, rpc, rtab, pstore, crypto, etc )
|
||||
// Also contains common log facilities (net, rpc, rtab, stor, pstore, crypto, etc )
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -123,6 +123,42 @@ macro_rules! log_rtab {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! log_stor {
|
||||
(error $text:expr) => { error!(
|
||||
target: "stor",
|
||||
"{}",
|
||||
$text,
|
||||
)};
|
||||
(error $fmt:literal, $($arg:expr),+) => {
|
||||
error!(target:"stor", $fmt, $($arg),+);
|
||||
};
|
||||
(warn $text:expr) => { warn!(
|
||||
target: "stor",
|
||||
"{}",
|
||||
$text,
|
||||
)};
|
||||
(warn $fmt:literal, $($arg:expr),+) => {
|
||||
warn!(target:"stor", $fmt, $($arg),+);
|
||||
};
|
||||
(debug $text:expr) => { debug!(
|
||||
target: "stor",
|
||||
"{}",
|
||||
$text,
|
||||
)};
|
||||
(debug $fmt:literal, $($arg:expr),+) => {
|
||||
debug!(target:"stor", $fmt, $($arg),+);
|
||||
};
|
||||
($text:expr) => {trace!(
|
||||
target: "stor",
|
||||
"{}",
|
||||
$text,
|
||||
)};
|
||||
($fmt:literal, $($arg:expr),+) => {
|
||||
trace!(target:"stor", $fmt, $($arg),+);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! log_pstore {
|
||||
(error $text:expr) => { error!(
|
||||
@@ -216,6 +252,18 @@ macro_rules! logthru_rtab {
|
||||
}
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! logthru_stor {
|
||||
($($level:ident)?) => {
|
||||
logthru!($($level)? "stor")
|
||||
};
|
||||
($($level:ident)? $text:literal) => {
|
||||
logthru!($($level)? "stor", $text)
|
||||
};
|
||||
($($level:ident)? $fmt:literal, $($arg:expr),+) => {
|
||||
logthru!($($level)? "stor", $fmt, $($arg),+)
|
||||
}
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! logthru_pstore {
|
||||
($($level:ident)?) => {
|
||||
logthru!($($level)? "pstore")
|
||||
|
@@ -16,13 +16,12 @@ impl RngCore for VeilidRng {
|
||||
}
|
||||
|
||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
if let Err(e) = self.try_fill_bytes(dest) {
|
||||
panic!("Error: {}", e);
|
||||
}
|
||||
random_bytes(dest);
|
||||
}
|
||||
|
||||
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
|
||||
random_bytes(dest).map_err(rand::Error::new)
|
||||
random_bytes(dest);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +29,7 @@ cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
use js_sys::Math;
|
||||
|
||||
pub fn random_bytes(dest: &mut [u8]) -> EyreResult<()> {
|
||||
pub fn random_bytes(dest: &mut [u8]) {
|
||||
let len = dest.len();
|
||||
let u32len = len / 4;
|
||||
let remlen = len % 4;
|
||||
@@ -49,8 +48,6 @@ cfg_if! {
|
||||
dest[u32len * 4 + n] = ((r >> (n * 8)) & 0xFF) as u8;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_random_u32() -> u32 {
|
||||
@@ -65,9 +62,9 @@ cfg_if! {
|
||||
|
||||
} else {
|
||||
|
||||
pub fn random_bytes(dest: &mut [u8]) -> EyreResult<()> {
|
||||
pub fn random_bytes(dest: &mut [u8]) {
|
||||
let mut rng = rand::thread_rng();
|
||||
rng.try_fill_bytes(dest).wrap_err("failed to fill bytes")
|
||||
rng.fill_bytes(dest);
|
||||
}
|
||||
|
||||
pub fn get_random_u32() -> u32 {
|
||||
|
@@ -32,6 +32,37 @@ macro_rules! bail_io_error_other {
|
||||
};
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature="rt-tokio")] {
|
||||
#[macro_export]
|
||||
macro_rules! asyncmutex_try_lock {
|
||||
($x:expr) => {
|
||||
$x.try_lock().ok()
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! asyncmutex_lock_arc {
|
||||
($x:expr) => {
|
||||
$x.clone().lock_owned().await
|
||||
};
|
||||
}
|
||||
} else {
|
||||
#[macro_export]
|
||||
macro_rules! asyncmutex_try_lock {
|
||||
($x:expr) => {
|
||||
$x.try_lock()
|
||||
};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! asyncmutex_lock_arc {
|
||||
($x:expr) => {
|
||||
$x.lock_arc().await
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub fn system_boxed<'a, Out>(
|
||||
@@ -99,6 +130,10 @@ pub fn ms_to_us(ms: u32) -> u64 {
|
||||
(ms as u64) * 1000u64
|
||||
}
|
||||
|
||||
pub fn us_to_ms(us: u64) -> EyreResult<u32> {
|
||||
u32::try_from(us / 1000u64).wrap_err("could not convert microseconds")
|
||||
}
|
||||
|
||||
// Calculate retry attempt with logarhythmic falloff
|
||||
pub fn retry_falloff_log(
|
||||
last_us: u64,
|
||||
|
Reference in New Issue
Block a user