diff --git a/Cargo.lock b/Cargo.lock index 12ec9ac8..1d8b683e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -467,22 +467,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -614,7 +598,6 @@ dependencies = [ "parking_lot 0.12.1", "pretty_env_logger", "rand", - "reqwest", "serde", "serde_bytes", "serde_cbor", @@ -679,15 +662,6 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" -[[package]] -name = "encoding_rs" -version = "0.8.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" -dependencies = [ - "cfg-if", -] - [[package]] name = "enum-ordinalize" version = "4.3.0" @@ -1188,12 +1162,6 @@ dependencies = [ "stdweb", ] -[[package]] -name = "ipnet" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - [[package]] name = "is-terminal" version = "0.4.12" @@ -1672,42 +1640,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "reqwest" -version = "0.11.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" -dependencies = [ - "base64 0.21.7", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http 0.2.11", - "http-body", - "hyper", - "ipnet", - "js-sys", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "system-configuration", - "tokio", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "rusqlite" version = "0.26.3" @@ -2045,27 +1977,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tempfile" version = "3.10.1" @@ -2553,18 +2464,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.91" @@ -2594,16 +2493,6 @@ version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" -[[package]] -name = "web-sys" -version = "0.3.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "winapi" version = "0.3.9" @@ -2775,13 +2664,3 @@ checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178" dependencies = [ "memchr", ] - -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] diff --git a/core/dtn7/Cargo.toml b/core/dtn7/Cargo.toml index 10c1681d..9fc39f1a 100644 --- a/core/dtn7/Cargo.toml +++ b/core/dtn7/Cargo.toml @@ -73,7 +73,6 @@ num-derive = "0.4.2" num-traits = "0.2.15" thiserror = "1.0.31" dtn7-codegen = { path = "../codegen", version = "0.1.2" } -reqwest = { version = "0.11.13", default-features = false} sha1 = "0.10.5" glob-match = "0.2.1" diff --git a/core/dtn7/src/cla/httppull.rs b/core/dtn7/src/cla/httppull.rs index ce3ba20c..631239f1 100644 --- a/core/dtn7/src/cla/httppull.rs +++ b/core/dtn7/src/cla/httppull.rs @@ -21,101 +21,99 @@ pub struct HttpPullConvergenceLayer { tx: mpsc::Sender, } +/// pulls missing bundles from node +/// addr can be either an IP or a DNS name async fn http_pull_from_node( eid: EndpointID, - addr: IpAddr, + addr: String, port: u16, local_digest: String, ) -> TransferResult { let now = std::time::Instant::now(); let mut transfers = 0; - let client = reqwest::Client::new(); - debug!("pulling bundles from {} / {}", eid, addr); - - // get digest of remote node - let response = client - .get(&format!("http://{}:{}/status/bundles/digest", addr, port)) - .send() - .await; - let digest = match response { - Ok(digest) => digest.text().await.unwrap(), - Err(e) => { - error!("could not get digest from remote: {}", e); - return TransferResult::Failure; - } - }; - if digest == local_digest { - debug!("no new bundles on remote"); - return TransferResult::Successful; - } else { - debug!( - "remote ({}) has new bundles (remote: {} vs local: {})", - eid, digest, local_digest - ); - } - // get list of bundles from remote node - let response = client - .get(&format!("http://{}:{}/status/bundles", addr, port)) - .send() - .await; - let bid_list = match response { - Ok(bid_list) => bid_list.text().await.unwrap(), - Err(e) => { - error!("could not get bundle ID list from remote: {}", e); - return TransferResult::Failure; - } - }; - let bids: Vec = serde_json::from_str(&bid_list).unwrap(); - - // calculate missing bundles - let mut missing = Vec::new(); - - for bid in bids { - if !store_has_item(&bid) { - missing.push(bid); - } - } - - // fetch missing bundles from remote node - for bid in missing { - transfers += 1; - let response = client - .get(&format!("http://{}:{}/download?{}", addr, port, bid)) - .send() - .await; - let bundle_buf = match response { - Ok(bundle) => bundle.bytes().await.unwrap(), + tokio::task::spawn_blocking(move || { + // get digest of remote node + let response = + attohttpc::get(format!("http://{}:{}/status/bundles/digest", addr, port)).send(); + let digest = match response { + Ok(digest) => digest.text().unwrap(), Err(e) => { - error!("could not get bundle from remote: {}", e); + error!("could not get digest from remote: {}", e); + //bail!("could not get digest from remote: {}", e); return TransferResult::Failure; } }; - let bundle = match bp7::Bundle::try_from(bundle_buf.as_ref()) { - Ok(bundle) => bundle, + if digest == local_digest { + debug!("no new bundles on remote"); + return TransferResult::Successful; + } else { + debug!( + "remote ({}) has new bundles (remote: {} vs local: {})", + eid, digest, local_digest + ); + } + // get list of bundles from remote node + let response = attohttpc::get(format!("http://{}:{}/status/bundles", addr, port)).send(); + let bid_list = match response { + Ok(bid_list) => bid_list.text().unwrap(), Err(e) => { - warn!("could not parse bundle from remote: {}", e); - continue; + error!("could not get bundle ID list from remote: {}", e); + return TransferResult::Failure; } }; - info!("Downloaded bundle: {} from {}", bundle.id(), addr); - { - tokio::spawn(async move { - if let Err(err) = crate::core::processing::receive(bundle).await { - error!("Failed to process bundle: {}", err); + let bids: Vec = serde_json::from_str(&bid_list).unwrap(); + + // calculate missing bundles + let mut missing = Vec::new(); + + for bid in bids { + if !store_has_item(&bid) { + missing.push(bid); + } + } + + // fetch missing bundles from remote node + for bid in missing { + transfers += 1; + let response = + attohttpc::get(format!("http://{}:{}/download?{}", addr, port, bid)).send(); + + let bundle_buf = match response { + Ok(bundle) => bundle.bytes().unwrap(), + Err(e) => { + error!("could not get bundle from remote: {}", e); + return TransferResult::Failure; + } + }; + let bundle = match bp7::Bundle::try_from(bundle_buf.as_ref()) { + Ok(bundle) => bundle, + Err(e) => { + warn!("could not parse bundle from remote: {}", e); + continue; } - }); + }; + info!("Downloaded bundle: {} from {}", bundle.id(), addr); + { + tokio::spawn(async move { + if let Err(err) = crate::core::processing::receive(bundle).await { + error!("Failed to process bundle: {}", err); + } + }); + } } - } - debug!( - "finished pulling {} bundles from {} / {} in {:?}", - transfers, - eid, - addr, - now.elapsed() - ); - TransferResult::Successful + debug!( + "finished pulling {} bundles from {} / {} in {:?}", + transfers, + eid, + addr, + now.elapsed() + ); + TransferResult::Successful + }) + .await + .unwrap() } async fn http_pull_bundles() { debug!("pulling bundles from peers"); @@ -138,10 +136,10 @@ async fn http_pull_bundles() { } if CONFIG.lock().parallel_bundle_processing { tokio::spawn(async move { - http_pull_from_node(peer.eid, ipaddr, port, local_digest).await; + http_pull_from_node(peer.eid, ipaddr.to_string(), port, local_digest).await; }); } else { - http_pull_from_node(peer.eid, ipaddr, port, local_digest).await; + http_pull_from_node(peer.eid, ipaddr.to_string(), port, local_digest).await; } } }