diff --git a/Cargo.lock b/Cargo.lock index 4594a42..7e7bafe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,7 +220,7 @@ version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdb8867f378f33f78a811a8eb9bf108ad99430d7aad43315dd9319c827ef6247" dependencies = [ - "http 0.2.11", + "http 0.2.12", "log", "url", "wildmatch", @@ -253,7 +253,7 @@ dependencies = [ "bytes", "fastrand", "hex", - "http 0.2.11", + "http 0.2.12", "hyper 0.14.28", "ring 0.17.8", "time", @@ -290,7 +290,7 @@ dependencies = [ "aws-types", "bytes", "fastrand", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "percent-encoding", "pin-project-lite", @@ -318,7 +318,7 @@ dependencies = [ "aws-smithy-xml", "aws-types", "bytes", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "once_cell", "percent-encoding", @@ -343,7 +343,7 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "http 0.2.11", + "http 0.2.12", "once_cell", "regex-lite", "tracing", @@ -365,7 +365,7 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "http 0.2.11", + "http 0.2.12", "once_cell", "regex-lite", "tracing", @@ -388,7 +388,7 @@ dependencies = [ "aws-smithy-types", "aws-smithy-xml", "aws-types", - "http 0.2.11", + "http 0.2.12", "once_cell", "regex-lite", "tracing", @@ -410,8 +410,8 @@ dependencies = [ "form_urlencoded", "hex", "hmac", - "http 0.2.11", - "http 1.0.0", + "http 0.2.12", + "http 1.1.0", "once_cell", "p256 0.11.1", "percent-encoding", @@ -446,7 +446,7 @@ dependencies = [ "crc32c", "crc32fast", "hex", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "md-5", "pin-project-lite", @@ -478,7 +478,7 @@ dependencies = [ "bytes", "bytes-utils", "futures-core", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "once_cell", "percent-encoding", @@ -519,7 +519,7 @@ dependencies = [ "bytes", "fastrand", "h2 0.3.24", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", "hyper-rustls", @@ -540,8 +540,8 @@ dependencies = [ "aws-smithy-async", "aws-smithy-types", "bytes", - "http 0.2.11", - "http 1.0.0", + "http 0.2.12", + "http 1.1.0", "pin-project-lite", "tokio", "tracing", @@ -558,7 +558,7 @@ dependencies = [ "bytes", "bytes-utils", "futures-core", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "itoa", "num-integer", @@ -590,7 +590,7 @@ dependencies = [ "aws-smithy-async", "aws-smithy-runtime-api", "aws-smithy-types", - "http 0.2.11", + "http 0.2.12", "rustc_version", "tracing", ] @@ -605,7 +605,7 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "hyper 1.2.0", @@ -638,7 +638,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "mime", @@ -820,9 +820,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.88" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" @@ -843,9 +843,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -869,9 +869,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" dependencies = [ "clap_builder", "clap_derive", @@ -879,9 +879,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -1946,7 +1946,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 0.2.11", + "http 0.2.12", "indexmap 2.2.5", "slab", "tokio", @@ -1965,7 +1965,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 1.0.0", + "http 1.1.0", "indexmap 2.2.5", "slab", "tokio", @@ -2113,9 +2113,9 @@ checksum = "f558a64ac9af88b5ba400d99b579451af0d39c6d360980045b91aac966d705e2" [[package]] name = "http" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -2124,9 +2124,9 @@ dependencies = [ [[package]] name = "http" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -2140,7 +2140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http 0.2.11", + "http 0.2.12", "pin-project-lite", ] @@ -2151,7 +2151,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http 1.0.0", + "http 1.1.0", ] [[package]] @@ -2162,7 +2162,7 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "pin-project-lite", ] @@ -2209,7 +2209,7 @@ dependencies = [ "futures-core", "futures-util", "h2 0.3.24", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "httparse", "httpdate", @@ -2232,7 +2232,7 @@ dependencies = [ "futures-channel", "futures-util", "h2 0.4.2", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "httparse", "httpdate", @@ -2250,7 +2250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http 0.2.11", + "http 0.2.12", "hyper 0.14.28", "log", "rustls", @@ -2267,7 +2267,7 @@ checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "hyper 1.2.0", "pin-project-lite", @@ -2327,7 +2327,7 @@ dependencies = [ "attohttpc", "bytes", "futures", - "http 0.2.11", + "http 0.2.12", "hyper 0.14.28", "log", "rand", @@ -2419,7 +2419,7 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "iroh" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ "anyhow", "bao-tree", @@ -2478,18 +2478,29 @@ dependencies = [ [[package]] name = "iroh-base" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ + "aead", "anyhow", "bao-tree", + "crypto_box", "data-encoding", + "derive_more", + "ed25519-dalek", "hex", "multibase", + "once_cell", "postcard", + "rand", + "rand_core", "redb", "serde", "serde-error", + "ssh-key", "thiserror", + "ttl_cache", + "url", + "zeroize", ] [[package]] @@ -2508,7 +2519,7 @@ dependencies = [ [[package]] name = "iroh-bytes" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ "anyhow", "bao-tree", @@ -2547,7 +2558,7 @@ dependencies = [ [[package]] name = "iroh-gossip" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ "anyhow", "bytes", @@ -2588,7 +2599,7 @@ dependencies = [ [[package]] name = "iroh-metrics" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ "anyhow", "erased_set", @@ -2608,27 +2619,25 @@ dependencies = [ [[package]] name = "iroh-net" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ "aead", "anyhow", "backoff", "bytes", - "crypto_box", "curve25519-dalek", "data-encoding", "default-net", "der 0.7.8", "derive_more", "duct", - "ed25519-dalek", "flume", "futures", "governor", "hex", "hickory-resolver", "hostname", - "http 1.0.0", + "http 1.1.0", "http-body-util", "hyper 1.2.0", "hyper-util", @@ -2659,7 +2668,6 @@ dependencies = [ "serdect", "smallvec", "socket2", - "ssh-key", "strum", "stun-rs", "surge-ping", @@ -2670,20 +2678,18 @@ dependencies = [ "tokio-rustls-acme", "tokio-util", "tracing", - "ttl_cache", "url", "watchable", "webpki-roots", "windows 0.51.1", "wmi", "x509-parser", - "zeroize", ] [[package]] name = "iroh-sync" version = "0.12.0" -source = "git+https://github.com/izihawa/iroh?branch=bao-file#ce38dc0f92ef73d55c1139f9646019cfa6254288" +source = "git+https://github.com/izihawa/iroh?branch=bao-file#a1a9257af7530dc8c545a0cd1f39c9093c83c010" dependencies = [ "anyhow", "bytes", @@ -2734,9 +2740,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -3415,18 +3421,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", @@ -3484,39 +3490,39 @@ checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" [[package]] name = "pnet_base" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872e46346144ebf35219ccaa64b1dffacd9c6f188cd7d012bd6977a2a838f42e" +checksum = "fe4cf6fb3ab38b68d01ab2aea03ed3d1132b4868fa4e06285f29f16da01c5f4c" dependencies = [ "no-std-net", ] [[package]] name = "pnet_macros" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a780e80005c2e463ec25a6e9f928630049a10b43945fea83207207d4a7606f4" +checksum = "688b17499eee04a0408aca0aa5cba5fc86401d7216de8a63fdf7a4c227871804" dependencies = [ "proc-macro2", "quote", "regex", - "syn 1.0.109", + "syn 2.0.52", ] [[package]] name = "pnet_macros_support" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d932134f32efd7834eb8b16d42418dac87086347d1bc7d142370ef078582bc" +checksum = "eea925b72f4bd37f8eab0f221bbe4c78b63498350c983ffa9dd4bcde7e030f56" dependencies = [ "pnet_base", ] [[package]] name = "pnet_packet" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bde678bbd85cb1c2d99dc9fc596e57f03aa725f84f3168b0eaf33eeccb41706" +checksum = "a9a005825396b7fe7a38a8e288dbc342d5034dac80c15212436424fef8ea90ba" dependencies = [ "glob", "pnet_base", @@ -3964,7 +3970,7 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.5", + "regex-automata 0.4.6", "regex-syntax 0.8.2", ] @@ -3979,9 +3985,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -4018,7 +4024,7 @@ dependencies = [ "futures-core", "futures-util", "h2 0.3.24", - "http 0.2.11", + "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", "hyper-rustls", @@ -4795,9 +4801,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "surge-ping" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af341b2be485d647b5dc4cfb2da99efac35b5c95748a08fb7233480fedc5ead3" +checksum = "efbf95ce4c7c5b311d2ce3f088af2b93edef0f09727fa50fbe03c7a979afce77" dependencies = [ "hex", "parking_lot", @@ -5167,7 +5173,7 @@ checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ "bitflags 2.4.2", "bytes", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "pin-project-lite", @@ -5481,9 +5487,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -5491,9 +5497,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -5506,9 +5512,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.41" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ "cfg-if", "js-sys", @@ -5518,9 +5524,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5528,9 +5534,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -5541,9 +5547,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "watchable" @@ -5559,9 +5565,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -5930,9 +5936,9 @@ dependencies = [ [[package]] name = "yansi" -version = "1.0.0-rc.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1367295b8f788d371ce2dbc842c7b709c73ee1364d30351dd300ec2203b12377" +checksum = "6c2861d76f58ec8fc95708b9b1e417f7b12fd72ad33c01fa6886707092dea0d3" [[package]] name = "yasna" diff --git a/bin/main.rs b/bin/main.rs index cc7082c..ec96d83 100644 --- a/bin/main.rs +++ b/bin/main.rs @@ -1,6 +1,6 @@ use axum::body::Body; use axum::extract::{Query, Request}; -use axum::http::StatusCode; +use axum::http::{Method, StatusCode}; use axum::response::{IntoResponse, Response}; use axum::routing::{delete, get, post, put}; use axum::{ @@ -426,12 +426,20 @@ async fn table_foreign_insert( async fn table_get( State(state): State, + method: Method, Path((table, key)): Path<(String, String)>, ) -> Response { match state.iroh_node.read().await.table_get(&table, &key).await { - Ok(Some(reader)) => Response::builder() - .body(Body::from_stream(ReaderStream::new(reader))) - .unwrap(), + Ok(Some((reader, file_size))) => match method { + Method::HEAD => Response::builder() + .header("Content-Length", file_size) + .body(Body::default()) + .unwrap(), + Method::GET => Response::builder() + .body(Body::from_stream(ReaderStream::new(reader))) + .unwrap(), + _ => unreachable!(), + }, Ok(None) => Response::builder() .status(StatusCode::NOT_FOUND) .body(Body::default()) diff --git a/src/iroh_node.rs b/src/iroh_node.rs index 6e69d2f..d1ba7e8 100644 --- a/src/iroh_node.rs +++ b/src/iroh_node.rs @@ -280,7 +280,8 @@ impl IrohNode { .await .map_err(Error::doc)?; let storage0 = entry.get().clone(); - tokio::spawn(async move { storage0.download_missing().await }); + self.task_tracker + .spawn(async move { storage0.download_missing().await }); Ok(entry.get().iroh_doc().id()) } Entry::Vacant(entry) => { @@ -394,7 +395,7 @@ impl IrohNode { &self, table_name: &str, key: &str, - ) -> Result>> { + ) -> Result, u64)>> { match self.table_storages.get(table_name) { Some(table_storage) => table_storage.get(key).await, None => Err(Error::missing_table(table_name)), diff --git a/src/storage.rs b/src/storage.rs index 4017005..01262bf 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -20,6 +20,7 @@ use iroh_base::hash::BlobFormat; use lru::LruCache; use std::collections::{HashMap, HashSet}; use std::num::NonZeroUsize; +use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use std::sync::Arc; use tokio::io::AsyncRead; @@ -38,6 +39,7 @@ pub struct Storage { shards: HashMap, sinks: Vec>, table_config: TableConfig, + cancellation_token: CancellationToken, } impl Storage { @@ -67,6 +69,7 @@ impl Storage { shards, sinks, table_config, + cancellation_token: cancellation_token.clone(), }; let storage_clone = storage.clone(); let mut stream = storage_clone @@ -140,6 +143,7 @@ impl Storage { let storage_clone = storage.clone(); if storage_config.is_import_missing_enabled { + let task_tracker0 = task_tracker.clone(); task_tracker.spawn(async move { let all_keys: Arc> = Arc::new( storage_clone @@ -159,7 +163,7 @@ impl Storage { let all_keys = all_keys.clone(); let pool = pool.clone(); let cancellation_token = cancellation_token.clone(); - tokio::spawn(async move { + task_tracker0.spawn(async move { let base_path = shard.path().to_path_buf(); let mut read_dir_stream = tokio::fs::read_dir(&base_path) .await @@ -256,8 +260,22 @@ impl Storage { return Ok(()); }; let mut stream = self.iroh_doc.get_many(Query::all()).await.unwrap(); - while let Some(entry) = stream.try_next().await.unwrap() { - self.download_entry_from_peers(&entry, &peers).await?; + loop { + tokio::select! { + _ = self.cancellation_token.cancelled() => { + info!("cancel"); + break; + }, + entry = stream.try_next() => { + match entry.unwrap() { + Some(entry) => { + self.download_entry_from_peers(&entry, &peers).await?; + } + None => break, + } + + } + } } Ok(()) } @@ -355,7 +373,7 @@ impl Storage { &self.iroh_doc } - pub async fn get(&self, key: &str) -> Result>> { + pub async fn get(&self, key: &str) -> Result, u64)>> { let first_shard_path = self .hash_ring .range(key, 1) @@ -364,7 +382,10 @@ impl Storage { .ok_or_else(|| Error::storage("no shards"))?; let shard = &self.shards[&first_shard_path.name]; match shard.open_store(key).await { - Ok(Some(file)) => return Ok(Some(Box::new(file))), + Ok(Some(file)) => { + let file_size = file.metadata().await.unwrap().size(); + return Ok(Some((Box::new(file), file_size))); + } Err(e) => return Err(Error::io_error(e)), Ok(None) => {} } @@ -379,11 +400,15 @@ impl Storage { if let Ok(Some(peers)) = self.iroh_doc.get_sync_peers().await { self.download_entry_from_peers(&entry, &peers).await?; } - return Ok(Some(Box::new( - entry - .content_reader(&self.sync_client) - .await - .map_err(Error::storage)?, + let file_size = entry.content_len(); + return Ok(Some(( + Box::new( + entry + .content_reader(&self.sync_client) + .await + .map_err(Error::storage)?, + ), + file_size, ))); } Ok(None) diff --git a/trident-py/pyproject.toml b/trident-py/pyproject.toml index f59c105..0c27e72 100644 --- a/trident-py/pyproject.toml +++ b/trident-py/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "izihawa-trident-client" -version = "1.1.1" +version = "1.1.2" description = "" authors = ["Pasha Podolsky "] readme = "README.md" diff --git a/trident-py/trident/client.py b/trident-py/trident/client.py index 9f50983..988838c 100644 --- a/trident-py/trident/client.py +++ b/trident-py/trident/client.py @@ -101,7 +101,7 @@ async def table_get(self, table: str, key: str, timeout: float = None) -> bytes return await response.read() async def table_get_chunks(self, table: str, key: str, timeout: float = None) -> AsyncGenerator[bytes, None]: - url = f"/tables/{table}/{key}/" + url = f"/tables/{table}/{key}" response = await self.get(url, timeout=timeout) async for data, _ in response.content.iter_chunks(): yield data