checkpoint
This commit is contained in:
@@ -28,27 +28,6 @@ mod tools;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod wasm;
|
||||
|
||||
pub use cfg_if::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use eyre::{bail, ensure, eyre, Report as EyreReport, Result as EyreResult, WrapErr};
|
||||
pub use futures_util::future::{select, Either};
|
||||
pub use futures_util::select;
|
||||
pub use futures_util::stream::FuturesUnordered;
|
||||
pub use futures_util::{AsyncRead, AsyncWrite};
|
||||
pub use log_thru::*;
|
||||
pub use owo_colors::OwoColorize;
|
||||
pub use parking_lot::*;
|
||||
pub use split_url::*;
|
||||
pub use static_assertions::*;
|
||||
pub use stop_token::*;
|
||||
pub use thiserror::Error as ThisError;
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "tracing")] {
|
||||
pub use tracing::*;
|
||||
} else {
|
||||
pub use log::*;
|
||||
}
|
||||
}
|
||||
pub type PinBox<T> = Pin<Box<T>>;
|
||||
pub type PinBoxFuture<T> = PinBox<dyn Future<Output = T> + 'static>;
|
||||
pub type PinBoxFutureLifetime<'a, T> = PinBox<dyn Future<Output = T> + 'a>;
|
||||
@@ -120,6 +99,7 @@ pub use eventual_value_clone::*;
|
||||
pub use interval::*;
|
||||
pub use ip_addr_port::*;
|
||||
pub use ip_extra::*;
|
||||
pub use log_thru::*;
|
||||
pub use must_join_handle::*;
|
||||
pub use must_join_single_future::*;
|
||||
pub use mutable_future::*;
|
||||
@@ -128,17 +108,32 @@ pub use random::*;
|
||||
pub use single_shot_eventual::*;
|
||||
pub use sleep::*;
|
||||
pub use spawn::*;
|
||||
pub use split_url::*;
|
||||
pub use tick_task::*;
|
||||
pub use timeout::*;
|
||||
pub use timeout_or::*;
|
||||
pub use timestamp::*;
|
||||
pub use tools::*;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use wasm::*;
|
||||
|
||||
// Tests must be public for wasm-pack tests
|
||||
pub mod tests;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "tracing")] {
|
||||
use tracing::*;
|
||||
} else {
|
||||
use log::*;
|
||||
}
|
||||
}
|
||||
use cfg_if::*;
|
||||
use futures_util::{AsyncRead, AsyncWrite};
|
||||
use parking_lot::*;
|
||||
use stop_token::*;
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
// For iOS tests
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main_rs() {}
|
||||
|
@@ -337,19 +337,13 @@ macro_rules! network_result_value_or_log {
|
||||
($r: expr => $f:tt) => {
|
||||
match $r {
|
||||
NetworkResult::Timeout => {
|
||||
log_network_result!(
|
||||
"{} at {}@{}:{}",
|
||||
"Timeout".cyan(),
|
||||
file!(),
|
||||
line!(),
|
||||
column!()
|
||||
);
|
||||
log_network_result!("{} at {}@{}:{}", "Timeout", file!(), line!(), column!());
|
||||
$f
|
||||
}
|
||||
NetworkResult::ServiceUnavailable => {
|
||||
log_network_result!(
|
||||
"{} at {}@{}:{}",
|
||||
"ServiceUnavailable".cyan(),
|
||||
"ServiceUnavailable",
|
||||
file!(),
|
||||
line!(),
|
||||
column!()
|
||||
@@ -359,7 +353,7 @@ macro_rules! network_result_value_or_log {
|
||||
NetworkResult::NoConnection(e) => {
|
||||
log_network_result!(
|
||||
"{}({}) at {}@{}:{}",
|
||||
"No connection".cyan(),
|
||||
"No connection",
|
||||
e.to_string(),
|
||||
file!(),
|
||||
line!(),
|
||||
@@ -370,7 +364,7 @@ macro_rules! network_result_value_or_log {
|
||||
NetworkResult::AlreadyExists(e) => {
|
||||
log_network_result!(
|
||||
"{}({}) at {}@{}:{}",
|
||||
"Already exists".cyan(),
|
||||
"Already exists",
|
||||
e.to_string(),
|
||||
file!(),
|
||||
line!(),
|
||||
@@ -381,7 +375,7 @@ macro_rules! network_result_value_or_log {
|
||||
NetworkResult::InvalidMessage(s) => {
|
||||
log_network_result!(
|
||||
"{}({}) at {}@{}:{}",
|
||||
"Invalid message".cyan(),
|
||||
"Invalid message",
|
||||
s,
|
||||
file!(),
|
||||
line!(),
|
||||
|
@@ -97,11 +97,13 @@ cfg_if! {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub fn split_port(name: &str) -> EyreResult<(String, Option<u16>)> {
|
||||
pub fn split_port(name: &str) -> Result<(String, Option<u16>), String> {
|
||||
if let Some(split) = name.rfind(':') {
|
||||
let hoststr = &name[0..split];
|
||||
let portstr = &name[split + 1..];
|
||||
let port: u16 = portstr.parse::<u16>().wrap_err("invalid port")?;
|
||||
let port: u16 = portstr
|
||||
.parse::<u16>()
|
||||
.map_err(|e| format!("invalid port: {}", e))?;
|
||||
|
||||
Ok((hoststr.to_string(), Some(port)))
|
||||
} else {
|
||||
@@ -130,8 +132,8 @@ 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")
|
||||
pub fn us_to_ms(us: u64) -> Result<u32, String> {
|
||||
u32::try_from(us / 1000u64).map_err(|e| format!("could not convert microseconds: {}", e))
|
||||
}
|
||||
|
||||
// Calculate retry attempt with logarhythmic falloff
|
||||
@@ -224,7 +226,7 @@ pub fn compatible_unspecified_socket_addr(socket_addr: &SocketAddr) -> SocketAdd
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listen_address_to_socket_addrs(listen_address: &str) -> EyreResult<Vec<SocketAddr>> {
|
||||
pub fn listen_address_to_socket_addrs(listen_address: &str) -> Result<Vec<SocketAddr>, String> {
|
||||
// If no address is specified, but the port is, use ipv4 and ipv6 unspecified
|
||||
// If the address is specified, only use the specified port and fail otherwise
|
||||
let ip_addrs = vec![
|
||||
@@ -235,7 +237,7 @@ pub fn listen_address_to_socket_addrs(listen_address: &str) -> EyreResult<Vec<So
|
||||
Ok(if let Some(portstr) = listen_address.strip_prefix(':') {
|
||||
let port = portstr
|
||||
.parse::<u16>()
|
||||
.wrap_err("Invalid port format in udp listen address")?;
|
||||
.map_err(|e| format!("Invalid port format in udp listen address: {}", e))?;
|
||||
ip_addrs.iter().map(|a| SocketAddr::new(*a, port)).collect()
|
||||
} else if let Ok(port) = listen_address.parse::<u16>() {
|
||||
ip_addrs.iter().map(|a| SocketAddr::new(*a, port)).collect()
|
||||
@@ -243,11 +245,11 @@ pub fn listen_address_to_socket_addrs(listen_address: &str) -> EyreResult<Vec<So
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
use core::str::FromStr;
|
||||
vec![SocketAddr::from_str(listen_address).map_err(|e| io_error_other!(e)).wrap_err("Unable to parse address")?]
|
||||
vec![SocketAddr::from_str(listen_address).map_err(|e| format!("Unable to parse address: {}",e))?]
|
||||
} else {
|
||||
listen_address
|
||||
.to_socket_addrs()
|
||||
.wrap_err("Unable to resolve address")?
|
||||
.map_err(|e| format!("Unable to resolve address: {}", e))?
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -277,7 +279,7 @@ cfg_if::cfg_if! {
|
||||
use std::os::unix::prelude::PermissionsExt;
|
||||
use nix::unistd::{Uid, Gid};
|
||||
|
||||
pub fn ensure_file_private_owner<P:AsRef<Path>>(path: P) -> EyreResult<()>
|
||||
pub fn ensure_file_private_owner<P:AsRef<Path>>(path: P) -> Result<(), String>
|
||||
{
|
||||
let path = path.as_ref();
|
||||
if !path.exists() {
|
||||
@@ -286,13 +288,13 @@ cfg_if::cfg_if! {
|
||||
|
||||
let uid = Uid::effective();
|
||||
let gid = Gid::effective();
|
||||
let meta = std::fs::metadata(path).wrap_err("unable to get metadata for path")?;
|
||||
let meta = std::fs::metadata(path).map_err(|e| format!("unable to get metadata for path: {}", e))?;
|
||||
|
||||
if meta.mode() != 0o600 {
|
||||
std::fs::set_permissions(path,std::fs::Permissions::from_mode(0o600)).wrap_err("unable to set correct permissions on path")?;
|
||||
std::fs::set_permissions(path,std::fs::Permissions::from_mode(0o600)).map_err(|e| format!("unable to set correct permissions on path: {}", e))?;
|
||||
}
|
||||
if meta.uid() != uid.as_raw() || meta.gid() != gid.as_raw() {
|
||||
bail!("path has incorrect owner/group");
|
||||
return Err("path has incorrect owner/group".to_owned());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -300,7 +302,7 @@ cfg_if::cfg_if! {
|
||||
//use std::os::windows::fs::MetadataExt;
|
||||
//use windows_permissions::*;
|
||||
|
||||
pub fn ensure_file_private_owner<P:AsRef<Path>>(path: P) -> EyreResult<()>
|
||||
pub fn ensure_file_private_owner<P:AsRef<Path>>(path: P) -> Result<(), String>
|
||||
{
|
||||
let path = path.as_ref();
|
||||
if !path.exists() {
|
||||
|
Reference in New Issue
Block a user