diff --git a/Cargo.lock b/Cargo.lock index 607e15070a..f5eb4ca627 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -743,6 +743,7 @@ dependencies = [ "tracing", "tracing-subscriber", "url", + "wasmtimer", "wiremock", ] @@ -1475,12 +1476,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "attohttpc" version = "0.24.1" @@ -2468,7 +2463,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -3521,15 +3516,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared 0.1.1", -] - [[package]] name = "foreign-types" version = "0.5.0" @@ -3537,7 +3523,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared 0.3.1", + "foreign-types-shared", ] [[package]] @@ -3551,12 +3537,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -4433,25 +4413,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "h2" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http 1.1.0", - "indexmap 2.7.0", - "slab", - "tokio", - "tokio-util 0.7.12", - "tracing", -] - [[package]] name = "half" version = "2.4.1" @@ -4813,7 +4774,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.26", + "h2", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -4836,7 +4797,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.7", "http 1.1.0", "http-body 1.0.1", "httparse", @@ -4891,22 +4851,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper 1.5.1", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.10" @@ -6458,23 +6402,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "netlink-packet-core" version = "0.7.0" @@ -6889,50 +6816,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "openssl" -version = "0.10.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types 0.3.2", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "opentelemetry" version = "0.20.0" @@ -8240,7 +8123,7 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2 0.3.26", + "h2", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.31", @@ -8278,22 +8161,18 @@ checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64 0.22.1", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2 0.4.7", "http 1.1.0", "http-body 1.0.1", "http-body-util", "hyper 1.5.1", "hyper-rustls 0.27.3", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -8305,9 +8184,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper 1.0.2", - "system-configuration 0.6.1", "tokio", - "tokio-native-tls", "tokio-rustls 0.26.0", "tower-service", "url", @@ -8707,15 +8584,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "schnellru" version = "0.2.3" @@ -8807,29 +8675,6 @@ dependencies = [ "cc", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.6.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "self_encryption" version = "0.30.0" @@ -9793,16 +9638,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.22.0" @@ -9932,7 +9767,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "h2 0.3.26", + "h2", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.31", @@ -9964,7 +9799,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "h2 0.3.26", + "h2", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.31", @@ -10452,12 +10287,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "vergen" version = "8.3.2" diff --git a/ant-bootstrap/Cargo.toml b/ant-bootstrap/Cargo.toml index e707df4fef..51667787cf 100644 --- a/ant-bootstrap/Cargo.toml +++ b/ant-bootstrap/Cargo.toml @@ -21,16 +21,21 @@ dirs-next = "~2.0.0" fs2 = "0.4.3" futures = "0.3.30" libp2p = { version = "0.54.1", features = ["serde"] } -reqwest = { version = "0.12.2", features = ["json"] } +reqwest = { version = "0.12.2", default-features = false, features = [ + "rustls-tls-manual-roots", +] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tempfile = "3.8.1" thiserror = "1.0" -tokio = { version = "1.0", features = ["full", "sync"] } +tokio = { version = "1.0", features = ["time"] } tracing = "0.1" url = "2.4.0" [dev-dependencies] wiremock = "0.5" tokio = { version = "1.0", features = ["full", "test-util"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } \ No newline at end of file +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +wasmtimer = "0.2.0" \ No newline at end of file diff --git a/ant-bootstrap/src/cache_store.rs b/ant-bootstrap/src/cache_store.rs index 8c8d7fe4c9..171780def5 100644 --- a/ant-bootstrap/src/cache_store.rs +++ b/ant-bootstrap/src/cache_store.rs @@ -197,15 +197,15 @@ impl BootstrapCacheStore { Ok(()) } - pub async fn initialize_from_local_cache(&mut self) -> Result<()> { - self.data = Self::load_cache_data(&self.config).await?; + pub fn initialize_from_local_cache(&mut self) -> Result<()> { + self.data = Self::load_cache_data(&self.config)?; self.old_shared_state = self.data.clone(); Ok(()) } /// Load cache data from disk /// Make sure to have clean addrs inside the cache as we don't call craft_valid_multiaddr - pub async fn load_cache_data(cfg: &BootstrapCacheConfig) -> Result { + pub fn load_cache_data(cfg: &BootstrapCacheConfig) -> Result { // Try to open the file with read permissions let mut file = OpenOptions::new() .read(true) @@ -213,7 +213,7 @@ impl BootstrapCacheStore { .inspect_err(|err| warn!("Failed to open cache file: {err}",))?; // Acquire shared lock for reading - Self::acquire_shared_lock(&file).await.inspect_err(|err| { + Self::acquire_shared_lock(&file).inspect_err(|err| { warn!("Failed to acquire shared lock: {err}"); })?; @@ -365,7 +365,7 @@ impl BootstrapCacheStore { return Ok(()); } - if let Ok(data_from_file) = Self::load_cache_data(&self.config).await { + if let Ok(data_from_file) = Self::load_cache_data(&self.config) { self.data.sync(&self.old_shared_state, &data_from_file); // Now the synced version is the old_shared_state } else { @@ -383,24 +383,26 @@ impl BootstrapCacheStore { }) } - async fn acquire_shared_lock(file: &File) -> Result<()> { - let file = file.try_clone()?; - - tokio::task::spawn_blocking(move || file.try_lock_shared().map_err(Error::from)) - .await - .map_err(|e| { - Error::from(std::io::Error::new( - std::io::ErrorKind::Other, - format!("Failed to spawn blocking task: {}", e), - )) - })? + /// Acquire a shared lock on the cache file. + /// This is a no-op on WASM. + fn acquire_shared_lock(file: &File) -> Result<()> { + #[cfg(not(target_arch = "wasm32"))] + { + let file = file.try_clone()?; + file.try_lock_shared()?; + } + + Ok(()) } + /// Acquire an exclusive lock on the cache file. + /// This is a no-op on WASM. async fn acquire_exclusive_lock(file: &File) -> Result<()> { let mut backoff = Duration::from_millis(10); let max_attempts = 5; let mut attempts = 0; + #[cfg(not(target_arch = "wasm32"))] loop { match file.try_lock_exclusive() { Ok(_) => return Ok(()), @@ -409,7 +411,10 @@ impl BootstrapCacheStore { } Err(e) if e.kind() == io::ErrorKind::WouldBlock => { attempts += 1; + #[cfg(not(target_arch = "wasm32"))] tokio::time::sleep(backoff).await; + #[cfg(target_arch = "wasm32")] + wasmtimer::std::sleep(backoff).await; backoff *= 2; } Err(_) => return Err(Error::LockError), diff --git a/ant-bootstrap/src/contacts.rs b/ant-bootstrap/src/contacts.rs index 53c3c3c62f..90da558a83 100644 --- a/ant-bootstrap/src/contacts.rs +++ b/ant-bootstrap/src/contacts.rs @@ -217,7 +217,11 @@ impl ContactsFetcher { trace!( "Failed to get bootstrap addrs from URL, retrying {retries}/{MAX_RETRIES_ON_FETCH_FAILURE}" ); + + #[cfg(not(target_arch = "wasm32"))] tokio::time::sleep(Duration::from_secs(1)).await; + #[cfg(target_arch = "wasm32")] + wasmtimer::std::sleep(Duration::from_secs(1)).await; }; Ok(bootstrap_addresses) diff --git a/ant-bootstrap/src/error.rs b/ant-bootstrap/src/error.rs index e7771a64b4..a8cb8e1cc8 100644 --- a/ant-bootstrap/src/error.rs +++ b/ant-bootstrap/src/error.rs @@ -26,8 +26,6 @@ pub enum Error { Json(#[from] serde_json::Error), #[error("HTTP error: {0}")] Http(#[from] reqwest::Error), - #[error("Timeout error: {0}")] - Timeout(#[from] tokio::time::error::Elapsed), #[error("Persist error: {0}")] Persist(#[from] tempfile::PersistError), #[error("Lock error")] diff --git a/ant-bootstrap/src/initial_peers.rs b/ant-bootstrap/src/initial_peers.rs index a15f60cc05..4bfa372276 100644 --- a/ant-bootstrap/src/initial_peers.rs +++ b/ant-bootstrap/src/initial_peers.rs @@ -164,7 +164,7 @@ impl PeersArgs { }; if let Some(cfg) = cfg { info!("Loading bootstrap addresses from cache"); - if let Ok(data) = BootstrapCacheStore::load_cache_data(&cfg).await { + if let Ok(data) = BootstrapCacheStore::load_cache_data(&cfg) { if let Some(cache) = cache.as_mut() { info!("Initializing cache with bootstrap addresses from cache"); cache.data = data.clone(); diff --git a/ant-bootstrap/tests/cache_tests.rs b/ant-bootstrap/tests/cache_tests.rs index aac95579a0..360280aab5 100644 --- a/ant-bootstrap/tests/cache_tests.rs +++ b/ant-bootstrap/tests/cache_tests.rs @@ -63,7 +63,7 @@ async fn test_cache_persistence() -> Result<(), Box> { // Create a new cache store with the same path let mut cache_store2 = BootstrapCacheStore::empty(config)?; - cache_store2.initialize_from_local_cache().await.unwrap(); + cache_store2.initialize_from_local_cache().unwrap(); let addrs = cache_store2.get_reliable_addrs().collect::>(); assert!(!addrs.is_empty(), "Cache should persist across instances");