diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml
index 38600635..7b1a6cd9 100644
--- a/.github/workflows/cargo-build.yml
+++ b/.github/workflows/cargo-build.yml
@@ -73,16 +73,10 @@ jobs:
run: |
make cargo-b-release
- - name: cargo-build-release-tokio
- run: |
- make cargo-build-release-tokio
-
- name: cargo-build-release-async-std
run: |
make cargo-build-release-async-std
-
-
- name: Run tests
run: source "$HOME/.cargo/env" && cargo test --verbose
diff --git a/Cargo.lock b/Cargo.lock
index 500f67a3..41c8111b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -157,13 +157,13 @@ dependencies = [
[[package]]
name = "async-global-executor"
-version = "2.4.0"
+version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b4353121d5644cdf2beb5726ab752e79a8db1ebb52031770ec47db31d245526"
+checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c"
dependencies = [
"async-channel 2.1.1",
"async-executor",
- "async-io 2.2.1",
+ "async-io 2.2.2",
"async-lock 3.2.0",
"blocking",
"futures-lite 2.1.0",
@@ -192,9 +192,9 @@ dependencies = [
[[package]]
name = "async-io"
-version = "2.2.1"
+version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d6d3b15875ba253d1110c740755e246537483f152fa334f91abd7fe84c88b3ff"
+checksum = "6afaa937395a620e33dc6a742c593c01aced20aa376ffb0f628121198578ccc7"
dependencies = [
"async-lock 3.2.0",
"cfg-if",
@@ -203,7 +203,7 @@ dependencies = [
"futures-lite 2.1.0",
"parking",
"polling 3.3.1",
- "rustix 0.38.26",
+ "rustix 0.38.28",
"slab",
"tracing",
"windows-sys 0.52.0",
@@ -242,7 +242,7 @@ dependencies = [
"cfg-if",
"event-listener 3.1.0",
"futures-lite 1.13.0",
- "rustix 0.38.26",
+ "rustix 0.38.28",
"windows-sys 0.48.0",
]
@@ -252,13 +252,13 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5"
dependencies = [
- "async-io 2.2.1",
+ "async-io 2.2.2",
"async-lock 2.8.0",
"atomic-waker",
"cfg-if",
"futures-core",
"futures-io",
- "rustix 0.38.26",
+ "rustix 0.38.28",
"signal-hook-registry",
"slab",
"windows-sys 0.48.0",
@@ -306,7 +306,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -867,7 +867,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -1183,7 +1183,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -1352,12 +1352,13 @@ dependencies = [
"sha2",
"sluice",
"snow",
+ "tempfile",
"test-log",
"time",
"tokio",
"tracing",
"tracing-subscriber",
- "wasi 0.10.0+wasi-snapshot-preview1",
+ "wasi 0.10.2+wasi-snapshot-preview1",
]
[[package]]
@@ -1437,9 +1438,9 @@ dependencies = [
[[package]]
name = "http-body"
-version = "0.4.5"
+version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
+checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
dependencies = [
"bytes",
"http",
@@ -1641,9 +1642,9 @@ dependencies = [
[[package]]
name = "itoa"
-version = "1.0.9"
+version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
+checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "js-sys"
@@ -1671,9 +1672,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.150"
+version = "0.2.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
+checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
[[package]]
name = "libgit2-sys"
@@ -1935,9 +1936,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.18.0"
+version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "oorandom"
@@ -2130,7 +2131,7 @@ dependencies = [
"cfg-if",
"concurrent-queue",
"pin-project-lite 0.2.13",
- "rustix 0.38.26",
+ "rustix 0.38.28",
"tracing",
"windows-sys 0.52.0",
]
@@ -2534,9 +2535,9 @@ dependencies = [
[[package]]
name = "rustix"
-version = "0.38.26"
+version = "0.38.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a"
+checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316"
dependencies = [
"bitflags 2.4.1",
"errno",
@@ -2547,9 +2548,9 @@ dependencies = [
[[package]]
name = "rustls"
-version = "0.21.9"
+version = "0.21.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9"
+checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba"
dependencies = [
"log",
"ring",
@@ -2578,9 +2579,9 @@ dependencies = [
[[package]]
name = "ryu"
-version = "1.0.15"
+version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
+checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "same-file"
@@ -2666,7 +2667,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -2853,9 +2854,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.39"
+version = "2.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
+checksum = "13fa70a4ee923979ffb522cacce59d34421ebdea5625e1073c4326ef9d2dd42e"
dependencies = [
"proc-macro2",
"quote",
@@ -2910,7 +2911,7 @@ dependencies = [
"cfg-if",
"fastrand 2.0.1",
"redox_syscall",
- "rustix 0.38.26",
+ "rustix 0.38.28",
"windows-sys 0.48.0",
]
@@ -2925,13 +2926,23 @@ dependencies = [
[[package]]
name = "test-log"
-version = "0.2.13"
+version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f66edd6b6cd810743c0c71e1d085e92b01ce6a72782032e3f794c8284fe4bcdd"
+checksum = "6159ab4116165c99fc88cce31f99fa2c9dbe08d3691cb38da02fc3b45f357d2b"
+dependencies = [
+ "test-log-macros",
+ "tracing-subscriber",
+]
+
+[[package]]
+name = "test-log-macros"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ba277e77219e9eea169e8508942db1bf5d8a41ff2db9b20aab5a5aadc9fa25d"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -2957,7 +2968,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -2972,12 +2983,11 @@ dependencies = [
[[package]]
name = "time"
-version = "0.1.45"
+version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
+checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
- "wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
@@ -3008,9 +3018,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
-version = "1.34.0"
+version = "1.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
+checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c"
dependencies = [
"backtrace",
"bytes",
@@ -3032,7 +3042,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -3111,7 +3121,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
]
[[package]]
@@ -3161,9 +3171,9 @@ checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3"
[[package]]
name = "try-lock"
-version = "0.2.4"
+version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
+checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "tungstenite"
@@ -3202,9 +3212,9 @@ dependencies = [
[[package]]
name = "unicode-bidi"
-version = "0.3.13"
+version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
+checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416"
[[package]]
name = "unicode-ident"
@@ -3339,9 +3349,9 @@ dependencies = [
[[package]]
name = "wasi"
-version = "0.10.0+wasi-snapshot-preview1"
+version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasi"
@@ -3370,7 +3380,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
"wasm-bindgen-shared",
]
@@ -3404,7 +3414,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.39",
+ "syn 2.0.40",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
diff --git a/Cargo.toml b/Cargo.toml
index 24ebc93e..e74bf707 100755
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -47,7 +47,7 @@ tracing = "0.1"
pretty-hash = "0.4"
futures-timer = "3"
futures-lite = "1"
-hypercore = { version = "0.12", default-features = false }
+hypercore = { version = "0.12", default-features = false, features = ["async-std", "cache", "js_interop_tests", "moka", "sparse"] }
sha2 = "0.10"
curve25519-dalek = "4"
crypto_secretstream = "0.2"
@@ -61,14 +61,26 @@ nostr-sdk = "0.24.0"
wasi = { version = "0.10.0", features = ["std"] }
oorandom = "11.1.3"
+##$ cargo add random-access-disk
+## Updating crates.io index
+## Adding random-access-disk v3.0.0 to dependencies.
+## Features:
+## + async-std
+## + libc
+## + sparse
+## - tokio
+## NOTE:We favor async-std in this build config
+
+random-access-storage = "5.0.0"
+random-access-disk = { version = "3.0.0", default-features = false }
+random-access-memory = "3.0.0"
+tempfile = "3.8.1"
+
[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes", "unstable"] }
async-compat = "0.2.1"
tokio = { version = "1.27.0", features = ["macros", "net", "process", "rt", "rt-multi-thread", "sync", "time"] }
env_logger = "0.7.1"
-random-access-storage = "5.0.0"
-random-access-disk = { version = "3.0.0", default-features = false }
-random-access-memory = "3.0.0"
anyhow = "1.0.28"
instant = "0.1"
criterion = { version = "0.4", features = ["async_std"] }
diff --git a/GNUmakefile b/GNUmakefile
index 9dfad5d4..b4e5186d 100755
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -95,20 +95,26 @@ export RUSTC
RUSTUP:=$(shell which rustup)
export RUSTUP
+FEATURES:=\
+async-std\
+
+RELEASE:=\
+stable\
+
+
-:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?##/ {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
help:## help
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
-rustup-install:rustup-install-stable## rustup-install
-rustup-install-stable:## rustup-install-stable
+rustup-install:rustup-install-$(RELEASE)## rustup-install
+rustup-install-$(RELEASE):## rustup-install-$(RELEASE)
## install rustup sequence
- $(shell echo which rustup) || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain stable --profile default && . "$(HOME)/.cargo/env"
- $(shell echo which rustup) && rustup default stable
-rustup-install-nightly:## rustup-install-nightly
-## install rustup sequence
- $(shell echo which rustup) || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain nightly --profile default && . "$(HOME)/.cargo/env"
- $(shell echo which rustup) && rustup default nightly
-
+ $(shell echo which rustup) || \
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
+ sh -s -- -y --no-modify-path \
+ --default-toolchain $(RELEASE) \
+ --profile default && . "$(HOME)/.cargo/env"
+ $(shell echo which rustup) && rustup default $(RELEASE)
cargo-b:## cargo-b
[ -x "$(shell command -v $(RUSTUP))" ] || $(MAKE) rustup-install-stable
diff --git a/cargo.mk b/cargo.mk
index 166c14e7..bf892e00 100755
--- a/cargo.mk
+++ b/cargo.mk
@@ -3,8 +3,8 @@
cargo-help:### cargo-help
@awk 'BEGIN {FS = ":.*?###"} /^[a-zA-Z_-]+:.*?###/ {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
-cargo-bt:cargo-build-tokio### cargo-bt
-cargo-build-tokio:### cargo-build-tokio
+cargo-bt:cargo-build-tokio
+cargo-build-tokio:
## make cargo-build-tokio q=true
@. $(HOME)/.cargo/env
@RUST_BACKTRACE=all cargo b $(QUIET) --no-default-features --features tokio
@@ -20,10 +20,10 @@ cargo-install:### cargo install --path .
#@cargo install --path $(PWD)
@cargo install --locked --path $(PWD)
-cargo-br-tokio:cargo-build-release-tokio### cargo-br-tokio
+cargo-br-tokio:cargo-build-release-tokio
## make cargo-br-tokio q=true
-cargo-build-release-tokio:### cargo-build-release-tokio
+cargo-build-release-tokio:
## make cargo-build-release-tokio q=true
@. $(HOME)/.cargo/env
@cargo b $(QUIET) --profile=$(PROFILE) --no-default-features --features tokio
@@ -41,7 +41,7 @@ cargo-check:### cargo-check
@. $(HOME)/.cargo/env
@cargo c
-cargo-check-tokio:### cargo-check-tokio
+cargo-check-tokio:
## cargo c --no-default-features --features tokio
@. $(HOME)/.cargo/env
@cargo check --no-default-features --features tokio
@@ -56,28 +56,52 @@ cargo-bench:### cargo-bench
@. $(HOME)/.cargo/env
@cargo bench
-cargo-tt:cargo-test-tokio### cargo-tt
-cargo-test-tokio:### cargo-test-tokio
-## cargo tt
+cargo-examples:### cargo-examples
+## cargo b --examples
+ @. $(HOME)/.cargo/env
+ @cargo b --examples
+
+cargo-example-disk:### cargo-example-disk
+## cargo run --example
+ @. $(HOME)/.cargo/env
+ @cargo run --example disk
+
+cargo-example-memory:### cargo-example-memory
+## cargo run --example
+ @. $(HOME)/.cargo/env
+ @cargo run --example memory
+
+cargo-example-template:### cargo-example-template
+## cargo run --example
+ @. $(HOME)/.cargo/env
+ @cargo run --example template
+
+cargo-example-replication:### cargo-example-replication
+## cargo run --example
+ @. $(HOME)/.cargo/env
+ cargo run --example replication
+
+cargo-t-tok:cargo-test-tokio
+cargo-test-tokio:
+## cargo-t-tok
@. $(HOME)/.cargo/env && cargo test --no-default-features --features tokio
-cargo-ts:cargo-test-async-std### cargo-ts
+cargo-t-async:cargo-test-async-std### cargo-t-async
cargo-test-async-std:### cargo-test-async-std
-## cargo ts
+## cargo t-async
@. $(HOME)/.cargo/env && cargo test --no-default-features --features async-std
cargo-jits:### cargo-jits
## cargo-jits
@. $(HOME)/.cargo/env && $(MAKE) cargo-t-jit-tokio cargo-t-jit-as
-cargo-t-jit-tokio:cargo-test-js-interop-tokio### cargo-test-jit-tokio
+cargo-t-jit-tokio:cargo-test-js-interop-tokio
cargo-test-js-interop-tokio:
@. $(HOME)/.cargo/env && cargo test --no-default-features --features js_interop_tests,tokio
cargo-t-jit-as:cargo-test-js-interop-async-std### cargo-test-jit-as
cargo-test-js-interop-async-std:
@. $(HOME)/.cargo/env && cargo test --no-default-features --features js_interop_tests,async-std
-
cargo-test-benches:### cargo-test-benches
cargo test --benches
diff --git a/examples/disk.rs b/examples/disk.rs
new file mode 100755
index 00000000..50fd47e8
--- /dev/null
+++ b/examples/disk.rs
@@ -0,0 +1,93 @@
+#[cfg(feature = "async-std")]
+use async_std::main as async_main;
+use hypercore::{HypercoreBuilder, HypercoreError, Storage};
+use tempfile::Builder;
+#[cfg(feature = "tokio")]
+use tokio::main as async_main;
+
+/// Example about using an in-memory hypercore.
+#[async_main]
+async fn main() {
+
+ // For the purposes of this example, first create a
+ // temporary directory to hold hypercore.
+ let dir = Builder::new()
+ .prefix("gnostr")
+ .tempdir()
+ .unwrap()
+ .into_path();
+
+ println!(
+ "{}",
+ dir.display());
+
+ // Create a disk storage, overwriting existing values.
+ let overwrite = true;
+ let storage = Storage::new_disk(&dir, overwrite)
+ .await
+ .expect("Could not create disk storage");
+
+ // Build a new disk hypercore
+ let mut hypercore = HypercoreBuilder::new(storage)
+ .build()
+ .await
+ .expect("Could not create disk hypercore");
+
+ // Append values to the hypercore
+ hypercore.append(b"Hello, ").await.unwrap();
+ hypercore.append(b"from ").await.unwrap();
+
+ // Close hypercore
+ drop(hypercore);
+
+ // Open hypercore again from same directory, not
+ // overwriting.
+ let overwrite = false;
+ let storage = Storage::new_disk(&dir, overwrite)
+ .await
+ .expect("Could not open existing disk storage");
+ let mut hypercore = HypercoreBuilder::new(storage)
+ .open(true)
+ .build()
+ .await
+ .expect("Could not open disk hypercore");
+
+ // Append new values to the hypercore
+ hypercore.append(b" disk hypercore!").await.unwrap();
+
+ // Add three values and clear the first two
+ let batch: &[&[u8]] = &[
+ b"first value to clear",
+ b"second value to clear",
+ b"third value to keep",
+ ];
+ let new_length = hypercore.append_batch(batch).await.unwrap().length;
+ hypercore
+ .clear(new_length - 3, new_length - 1)
+ .await
+ .unwrap();
+
+ // The two values return None, but the last one returns correctly
+ assert!(hypercore.get(3).await.unwrap().is_none());
+ assert!(hypercore.get(4).await.unwrap().is_none());
+ assert_eq!(
+ hypercore.get(5).await.unwrap().unwrap(),
+ b"third value to keep"
+ );
+
+ // Print the first three values, converting binary back to string
+ println!(
+ "{}{}{}",
+ format_res(hypercore.get(0).await),
+ format_res(hypercore.get(1).await),
+ format_res(hypercore.get(2).await)
+ ); // prints "Hello, from disk hypercore!"
+}
+
+fn format_res(res: Result