From abd4f572c01807dcfdfe76b6054b51328f4087c5 Mon Sep 17 00:00:00 2001 From: Kasey Date: Thu, 20 Oct 2022 18:33:14 -0400 Subject: [PATCH 1/6] fix: windows symlink support --- iroh-api/Cargo.toml | 1 + iroh-api/src/api_ext.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/iroh-api/Cargo.toml b/iroh-api/Cargo.toml index c522f95ac9..5ef6516c82 100644 --- a/iroh-api/Cargo.toml +++ b/iroh-api/Cargo.toml @@ -32,3 +32,4 @@ thiserror = "1.0" [dev-dependencies] tempfile = "3.3.0" +tempdir = "0.3.7" diff --git a/iroh-api/src/api_ext.rs b/iroh-api/src/api_ext.rs index c45a7e33a1..3ec078027c 100644 --- a/iroh-api/src/api_ext.rs +++ b/iroh-api/src/api_ext.rs @@ -90,6 +90,13 @@ async fn save_get_stream( if let Some(parent) = path.parent() { tokio::fs::create_dir_all(parent.to_path(root_path)).await?; } + #[cfg(windows)] + tokio::task::spawn_blocking(move || { + make_windows_symlink(target, full_path).map_err(|e| anyhow::anyhow!(e)) + }) + .await??; + + #[cfg(unix)] tokio::fs::symlink(target, full_path).await?; } } @@ -97,6 +104,15 @@ async fn save_get_stream( Ok(()) } +#[cfg(windows)] +fn make_windows_symlink(target: PathBuf, path: PathBuf) -> Result<()> { + if target.is_dir() { + std::os::windows::fs::symlink_dir(target, path).map_err(|e| anyhow::anyhow!(e)) + } else { + std::os::windows::fs::symlink_file(target, path).map_err(|e| anyhow::anyhow!(e)) + } +} + /// Given an cid and an optional output path, determine root path fn get_root_path(ipfs_path: &IpfsPath, output_path: Option<&Path>) -> PathBuf { match output_path { From 0d888e5f7e10d21ef36c08a503242b9aa5fe79e0 Mon Sep 17 00:00:00 2001 From: Kasey Date: Fri, 21 Oct 2022 10:18:28 -0400 Subject: [PATCH 2/6] fix: uds grpc error in iroh-one --- iroh-one/src/config.rs | 15 +++++++++++++-- iroh-resolver/src/unixfs_builder.rs | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/iroh-one/src/config.rs b/iroh-one/src/config.rs index ade1ce617d..86e60f0a12 100644 --- a/iroh-one/src/config.rs +++ b/iroh-one/src/config.rs @@ -5,7 +5,6 @@ use config::{ConfigError, Map, Source, Value}; use iroh_metrics::config::Config as MetricsConfig; use iroh_p2p::Libp2pConfig; use iroh_rpc_client::Config as RpcClientConfig; -use iroh_rpc_types::Addr; use iroh_store::config::config_data_path; use iroh_util::insert_into_config_map; use serde::{Deserialize, Serialize}; @@ -67,10 +66,22 @@ impl Config { /// The gateway itself is exposing a UDS rpc endpoint to be also usable /// as a single entry point for other system services if feature enabled. pub fn default_rpc_config() -> RpcClientConfig { +<<<<<<< HEAD let path: PathBuf = TempDir::new().unwrap().path().join("iroh/ipfsd.http"); +======= + #[cfg(feature = "uds-gateway")] + let path: PathBuf = tempdir::TempDir::new("iroh") + .unwrap() + .path() + .join("ipfsd.http"); +>>>>>>> 8144e4e (fix: uds grpc error in iroh-one) RpcClientConfig { - gateway_addr: Some(Addr::GrpcUds(path)), + #[cfg(feature = "uds-gateway")] + gateway_addr: Some(iroh_rpc_types::Addr::GrpcUds(path)), + // TODO(ramfox): not sure what the correct option is when not running a uds gateway + #[cfg(not(feature = "uds-gateway"))] + gateway_addr: None, p2p_addr: None, store_addr: None, } diff --git a/iroh-resolver/src/unixfs_builder.rs b/iroh-resolver/src/unixfs_builder.rs index 051c7090ae..8aa193783b 100644 --- a/iroh-resolver/src/unixfs_builder.rs +++ b/iroh-resolver/src/unixfs_builder.rs @@ -950,6 +950,7 @@ mod tests { Ok(()) } + #[cfg(not(windows))] #[tokio::test] async fn symlink_from_disk_test() -> Result<()> { let temp_dir = tempfile::tempdir()?; From 76377420e1ecd5f3f6122554226c25ce511d562f Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 24 Oct 2022 14:48:47 +0300 Subject: [PATCH 3/6] fix: Fix clippy on windows cargo clippy --target=x86_64-pc-windows-gnu --- .cargo/config | 5 ++++- iroh-gateway/src/main.rs | 1 + iroh-one/src/config.rs | 5 ----- iroh-one/src/main.rs | 1 + iroh-p2p/src/main.rs | 4 +++- iroh-store/src/main.rs | 4 +++- iroh-util/src/lib.rs | 2 ++ 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.cargo/config b/.cargo/config index f0ccbc9a88..b3e386a1cb 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,2 +1,5 @@ [alias] -xtask = "run --package xtask --" \ No newline at end of file +xtask = "run --package xtask --" + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" diff --git a/iroh-gateway/src/main.rs b/iroh-gateway/src/main.rs index d00b89dbb9..9f04057464 100644 --- a/iroh-gateway/src/main.rs +++ b/iroh-gateway/src/main.rs @@ -13,6 +13,7 @@ use iroh_rpc_client::Client as RpcClient; use iroh_util::lock::ProgramLock; use iroh_util::{iroh_config_path, make_config}; use tokio::sync::RwLock; +#[cfg(unix)] use tracing::{debug, error}; #[tokio::main(flavor = "multi_thread")] diff --git a/iroh-one/src/config.rs b/iroh-one/src/config.rs index 86e60f0a12..e7b4727331 100644 --- a/iroh-one/src/config.rs +++ b/iroh-one/src/config.rs @@ -9,7 +9,6 @@ use iroh_store::config::config_data_path; use iroh_util::insert_into_config_map; use serde::{Deserialize, Serialize}; use std::path::PathBuf; -use tempfile::TempDir; /// CONFIG_FILE_NAME is the name of the optional config file located in the iroh home directory pub const CONFIG_FILE_NAME: &str = "one.config.toml"; @@ -66,15 +65,11 @@ impl Config { /// The gateway itself is exposing a UDS rpc endpoint to be also usable /// as a single entry point for other system services if feature enabled. pub fn default_rpc_config() -> RpcClientConfig { -<<<<<<< HEAD - let path: PathBuf = TempDir::new().unwrap().path().join("iroh/ipfsd.http"); -======= #[cfg(feature = "uds-gateway")] let path: PathBuf = tempdir::TempDir::new("iroh") .unwrap() .path() .join("ipfsd.http"); ->>>>>>> 8144e4e (fix: uds grpc error in iroh-one) RpcClientConfig { #[cfg(feature = "uds-gateway")] diff --git a/iroh-one/src/main.rs b/iroh-one/src/main.rs index 007780f49c..bbc8bd3d7e 100644 --- a/iroh-one/src/main.rs +++ b/iroh-one/src/main.rs @@ -17,6 +17,7 @@ use iroh_util::{iroh_config_path, make_config}; #[cfg(feature = "uds-gateway")] use tempdir::TempDir; use tokio::sync::RwLock; +#[cfg(unix)] use tracing::{debug, error}; #[tokio::main(flavor = "multi_thread")] diff --git a/iroh-p2p/src/main.rs b/iroh-p2p/src/main.rs index fa76105deb..19b4a0bdc6 100644 --- a/iroh-p2p/src/main.rs +++ b/iroh-p2p/src/main.rs @@ -5,7 +5,9 @@ use iroh_p2p::{cli::Args, metrics, DiskStorage, Keychain, Node}; use iroh_util::lock::ProgramLock; use iroh_util::{iroh_config_path, make_config}; use tokio::task; -use tracing::{debug, error}; +#[cfg(unix)] +use tracing::debug; +use tracing::error; /// Starts daemon process fn main() -> Result<()> { diff --git a/iroh-store/src/main.rs b/iroh-store/src/main.rs index 0ff9a4295e..ad8ab175ba 100644 --- a/iroh-store/src/main.rs +++ b/iroh-store/src/main.rs @@ -7,7 +7,9 @@ use iroh_store::{ }; use iroh_util::lock::ProgramLock; use iroh_util::{block_until_sigint, iroh_config_path, make_config}; -use tracing::{debug, error, info}; +use tracing::info; +#[cfg(unix)] +use tracing::{debug, error}; #[tokio::main(flavor = "multi_thread")] async fn main() -> anyhow::Result<()> { diff --git a/iroh-util/src/lib.rs b/iroh-util/src/lib.rs index 457ab95d2a..172df7123b 100644 --- a/iroh-util/src/lib.rs +++ b/iroh-util/src/lib.rs @@ -22,7 +22,9 @@ pub mod lock; /// name of directory that wraps all iroh files in a given application directory const IROH_DIR: &str = "iroh"; +#[cfg(unix)] const DEFAULT_NOFILE_LIMIT: u64 = 65536; +#[cfg(unix)] const MIN_NOFILE_LIMIT: u64 = 2048; /// Blocks current thread until ctrl-c is received From 8d6e931f387ae978fd7ea88f7b678526c9b5b71c Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 24 Oct 2022 15:29:50 +0300 Subject: [PATCH 4/6] fix: fix lock for windows also clippy windows for iroh-localops --- iroh-localops/src/process.rs | 7 ++++--- iroh-util/src/lock.rs | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/iroh-localops/src/process.rs b/iroh-localops/src/process.rs index 1c6b363d5c..7a952494cf 100644 --- a/iroh-localops/src/process.rs +++ b/iroh-localops/src/process.rs @@ -4,6 +4,7 @@ use nix::sys::signal::{kill, Signal}; #[cfg(any(target_os = "macos", target_os = "linux"))] use nix::unistd::Pid; use std::path::PathBuf; +#[cfg(any(target_os = "macos", target_os = "linux"))] use std::process::{Command, Stdio}; // TODO(b5): instead of using u32's for Process Identifiers, use a proper Pid type @@ -33,7 +34,7 @@ pub fn daemonize(bin_path: PathBuf, log_path: PathBuf) -> Result<()> { } #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] -fn daemonize_process(bin_path: PathBuf, log_path: PathBuf) -> Result<()> { +fn daemonize_process(_bin_path: PathBuf, _log_path: PathBuf) -> Result<()> { Err(anyhow!( "daemonizing processes is not supported on your operating system" )) @@ -62,7 +63,7 @@ fn daemonize_process(bin_path: PathBuf, log_path: PathBuf) -> Result<()> { } #[cfg(target_os = "windows")] -fn daemonize_process(bin_path: PathBuf, log_path: PathBuf) -> Result<()> { +fn daemonize_process(_bin_path: PathBuf, _log_path: PathBuf) -> Result<()> { Err(anyhow!("daemonizing processes on windows is not supported")) } @@ -87,6 +88,6 @@ fn stop_process(pid: i32) -> Result<()> { } #[cfg(target_os = "windows")] -fn stop_process(pid: i32) -> Result<()> { +fn stop_process(_pid: i32) -> Result<()> { Err(anyhow!("stopping processes on windows is not supported")) } diff --git a/iroh-util/src/lock.rs b/iroh-util/src/lock.rs index bce8237a00..74c70708ba 100644 --- a/iroh-util/src/lock.rs +++ b/iroh-util/src/lock.rs @@ -6,6 +6,7 @@ use std::io::ErrorKind; use std::io::Write; use std::path::PathBuf; use std::process; +use sysinfo::PidExt; use sysinfo::{Pid, ProcessExt, ProcessStatus::*, System, SystemExt}; use thiserror::Error; use tracing::warn; @@ -192,9 +193,9 @@ fn read_lock(path: &PathBuf) -> Result { file.read_to_string(&mut pid) .map_err(|_| LockError::CorruptLock(path.clone()))?; let pid = pid - .parse::() + .parse::() .map_err(|_| LockError::CorruptLock(path.clone()))?; - Ok(Pid::from(pid)) + Ok(Pid::from_u32(pid)) } /// LockError is the set of known program lock errors From 52385fcb92c0908c5f570b8d1eff6cee98c458bf Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 24 Oct 2022 16:06:17 +0300 Subject: [PATCH 5/6] fix: Use u32 for pid everywhere because windows --- iroh-localops/src/process.rs | 10 +++++----- iroh/src/services.rs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/iroh-localops/src/process.rs b/iroh-localops/src/process.rs index 7a952494cf..96e5b66521 100644 --- a/iroh-localops/src/process.rs +++ b/iroh-localops/src/process.rs @@ -70,24 +70,24 @@ fn daemonize_process(_bin_path: PathBuf, _log_path: PathBuf) -> Result<()> { // TODO(b5) - this level of indirection isn't necessary, factor `stop_process` // directly into `stop` // https://github.com/n0-computer/iroh/pull/360#discussion_r1002000769 -pub fn stop(pid: i32) -> Result<()> { +pub fn stop(pid: u32) -> Result<()> { stop_process(pid) } #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] -fn stop_process(pid: i32) -> Result<()> { +fn stop_process(pid: u32) -> Result<()> { Err(anyhow!( "stopping processes is not supported on your operating system" )) } #[cfg(any(target_os = "macos", target_os = "linux"))] -fn stop_process(pid: i32) -> Result<()> { - let id = Pid::from_raw(pid); +fn stop_process(pid: u32) -> Result<()> { + let id = Pid::from_raw(pid as i32); kill(id, Signal::SIGINT).map_err(|e| anyhow!("killing process: {}", e)) } #[cfg(target_os = "windows")] -fn stop_process(_pid: i32) -> Result<()> { +fn stop_process(_pid: u32) -> Result<()> { Err(anyhow!("stopping processes on windows is not supported")) } diff --git a/iroh/src/services.rs b/iroh/src/services.rs index 7231f3d746..c386c659a0 100644 --- a/iroh/src/services.rs +++ b/iroh/src/services.rs @@ -6,6 +6,7 @@ use iroh_util::iroh_cache_path; use std::collections::HashSet; use std::io::{stdout, Write}; use std::time::SystemTime; +use sysinfo::PidExt; use tracing::info; use iroh_api::{Api, ServiceStatus, StatusRow, StatusTable}; @@ -131,7 +132,7 @@ pub async fn stop_services(api: &impl Api, services: HashSet<&str>) -> Result<() Ok(pid) => { info!("stopping {} pid: {}", daemon_name, pid); print!("stopping {}... ", &daemon_name); - match iroh_localops::process::stop(pid.into()) { + match iroh_localops::process::stop(pid.as_u32()) { Ok(_) => { let is_down = ensure_status( api, From fad5242e90eab905f2131893a9ceed47d40eff64 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 24 Oct 2022 16:50:32 +0300 Subject: [PATCH 6/6] refactor: use tracing prefix in conditional code ...so we don't have to make the imports conditional to please clippy --- iroh-gateway/src/main.rs | 6 ++---- iroh-one/src/main.rs | 6 ++---- iroh-p2p/src/main.rs | 4 +--- iroh-store/src/main.rs | 6 ++---- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/iroh-gateway/src/main.rs b/iroh-gateway/src/main.rs index 9f04057464..81f07e55f3 100644 --- a/iroh-gateway/src/main.rs +++ b/iroh-gateway/src/main.rs @@ -13,8 +13,6 @@ use iroh_rpc_client::Client as RpcClient; use iroh_util::lock::ProgramLock; use iroh_util::{iroh_config_path, make_config}; use tokio::sync::RwLock; -#[cfg(unix)] -use tracing::{debug, error}; #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<()> { @@ -65,8 +63,8 @@ async fn main() -> Result<()> { #[cfg(unix)] { match iroh_util::increase_fd_limit() { - Ok(soft) => debug!("NOFILE limit: soft = {}", soft), - Err(err) => error!("Error increasing NOFILE limit: {}", err), + Ok(soft) => tracing::debug!("NOFILE limit: soft = {}", soft), + Err(err) => tracing::error!("Error increasing NOFILE limit: {}", err), } } diff --git a/iroh-one/src/main.rs b/iroh-one/src/main.rs index bbc8bd3d7e..c2db335445 100644 --- a/iroh-one/src/main.rs +++ b/iroh-one/src/main.rs @@ -17,8 +17,6 @@ use iroh_util::{iroh_config_path, make_config}; #[cfg(feature = "uds-gateway")] use tempdir::TempDir; use tokio::sync::RwLock; -#[cfg(unix)] -use tracing::{debug, error}; #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<()> { @@ -44,8 +42,8 @@ async fn main() -> Result<()> { #[cfg(unix)] { match iroh_util::increase_fd_limit() { - Ok(soft) => debug!("NOFILE limit: soft = {}", soft), - Err(err) => error!("Error increasing NOFILE limit: {}", err), + Ok(soft) => tracing::debug!("NOFILE limit: soft = {}", soft), + Err(err) => tracing::error!("Error increasing NOFILE limit: {}", err), } } diff --git a/iroh-p2p/src/main.rs b/iroh-p2p/src/main.rs index 19b4a0bdc6..60506f3341 100644 --- a/iroh-p2p/src/main.rs +++ b/iroh-p2p/src/main.rs @@ -5,8 +5,6 @@ use iroh_p2p::{cli::Args, metrics, DiskStorage, Keychain, Node}; use iroh_util::lock::ProgramLock; use iroh_util::{iroh_config_path, make_config}; use tokio::task; -#[cfg(unix)] -use tracing::debug; use tracing::error; /// Starts daemon process @@ -52,7 +50,7 @@ fn main() -> Result<()> { #[cfg(unix)] { match iroh_util::increase_fd_limit() { - Ok(soft) => debug!("NOFILE limit: soft = {}", soft), + Ok(soft) => tracing::debug!("NOFILE limit: soft = {}", soft), Err(err) => error!("Error increasing NOFILE limit: {}", err), } } diff --git a/iroh-store/src/main.rs b/iroh-store/src/main.rs index ad8ab175ba..109a7b72e0 100644 --- a/iroh-store/src/main.rs +++ b/iroh-store/src/main.rs @@ -8,8 +8,6 @@ use iroh_store::{ use iroh_util::lock::ProgramLock; use iroh_util::{block_until_sigint, iroh_config_path, make_config}; use tracing::info; -#[cfg(unix)] -use tracing::{debug, error}; #[tokio::main(flavor = "multi_thread")] async fn main() -> anyhow::Result<()> { @@ -46,8 +44,8 @@ async fn main() -> anyhow::Result<()> { #[cfg(unix)] { match iroh_util::increase_fd_limit() { - Ok(soft) => debug!("NOFILE limit: soft = {}", soft), - Err(err) => error!("Error increasing NOFILE limit: {}", err), + Ok(soft) => tracing::debug!("NOFILE limit: soft = {}", soft), + Err(err) => tracing::error!("Error increasing NOFILE limit: {}", err), } }