diff --git a/Cargo.lock b/Cargo.lock index 33df7330..a50cda88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,14 @@ dependencies = [ "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "arrayref" version = "0.3.5" @@ -158,6 +166,26 @@ dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bindgen" +version = "0.43.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "1.0.4" @@ -257,6 +285,17 @@ dependencies = [ name = "cc" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cexpr" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "cfg-if" @@ -273,6 +312,30 @@ dependencies = [ "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clang-sys" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "clap" +version = "2.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clear_on_drop" version = "0.2.3" @@ -306,6 +369,15 @@ dependencies = [ "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-deque" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-deque" version = "0.7.1" @@ -315,6 +387,20 @@ dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-epoch" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-epoch" version = "0.7.1" @@ -336,6 +422,14 @@ dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-utils" version = "0.6.5" @@ -637,6 +731,11 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glob" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hmac" version = "0.7.0" @@ -718,6 +817,7 @@ dependencies = [ "parity-multihash 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)", "protobuf 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -760,6 +860,15 @@ name = "libc" version = "0.2.49" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libloading" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libp2p" version = "0.3.1" @@ -1086,6 +1195,18 @@ dependencies = [ "yamux 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "librocksdb-sys" +version = "5.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bindgen 0.43.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", + "make-cmd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lock_api" version = "0.1.5" @@ -1111,6 +1232,11 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "make-cmd" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "matches" version = "0.1.8" @@ -1213,9 +1339,9 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.18 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.41 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1242,6 +1368,15 @@ name = "nohash-hasher" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "nom" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num_cpus" version = "1.10.0" @@ -1257,7 +1392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl" -version = "0.10.18" +version = "0.10.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1265,7 +1400,7 @@ dependencies = [ "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.41 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1275,12 +1410,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl-sys" -version = "0.9.41" +version = "0.9.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1389,6 +1525,11 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1419,6 +1560,14 @@ name = "proc-macro-nested" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro2" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.27" @@ -1442,6 +1591,14 @@ name = "quick-error" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "quote" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.6.11" @@ -1579,6 +1736,27 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rayon" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon-core" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -1641,6 +1819,15 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rocksdb" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", + "librocksdb-sys 5.14.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.13" @@ -1887,6 +2074,11 @@ dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strsim" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "subtle" version = "1.0.0" @@ -1949,6 +2141,14 @@ dependencies = [ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "textwrap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread_local" version = "0.3.6" @@ -2322,6 +2522,11 @@ dependencies = [ "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-width" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.1.0" @@ -2361,6 +2566,11 @@ name = "vcpkg" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "version_check" version = "0.1.5" @@ -2391,6 +2601,14 @@ dependencies = [ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "which" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.2.8" @@ -2474,6 +2692,7 @@ dependencies = [ "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" "checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" "checksum aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f10b352bc3fc08ae24dc5d2d3ddcac153678533986122dc283d747b12071000" +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9893d63fc3b1c44231e667da6836a33f27d8b6b3bdc82f83da5dfd579d1b6528" @@ -2486,6 +2705,7 @@ dependencies = [ "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebecac13b3c745150d7b6c3ea7572d372f09d627c2077e893bf26c5c7f70d282" +"checksum bindgen 0.43.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d52d263eacd15d26cbcf215d254b410bd58212aaa2d3c453a04b2d3b3adcf41" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" "checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" @@ -2500,15 +2720,21 @@ dependencies = [ "checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa" "checksum cbor 0.4.1 (git+https://github.com/dvc94ch/rust-cbor?branch=read-data-item)" = "" "checksum cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "389803e36973d242e7fecb092b2de44a3d35ac62524b3b9339e51d577d668e02" +"checksum cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "644d693ecfa91955ed32dcc7eda4914e1be97a641fb6f0645a37348e20b230da" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum cid 0.3.0 (git+https://github.com/dvc94ch/rust-cid?branch=implement-hash)" = "" +"checksum clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ef0c1bcf2e99c649104bd7a7012d8f8802684400e03db0ec0af48583c6fa0e4" +"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980" "checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" +"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" @@ -2544,6 +2770,7 @@ dependencies = [ "checksum futures-util-preview 0.3.0-alpha.13 (registry+https://github.com/rust-lang/crates.io-index)" = "88b0edcc082d39a3379a96eb670c9b6b28689cd753cc351fb2c0a4739e4a1f97" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" +"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" @@ -2557,6 +2784,7 @@ dependencies = [ "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e" +"checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" "checksum libp2p 0.3.1 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" "checksum libp2p-core 0.3.4 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" "checksum libp2p-core-derive 0.3.2 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" @@ -2575,9 +2803,11 @@ dependencies = [ "checksum libp2p-uds 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" "checksum libp2p-websocket 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" "checksum libp2p-yamux 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" +"checksum librocksdb-sys 5.14.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b9024327233e7fac7982440f73301c00046d438c5b1011e8f4e394226ce19007" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum make-cmd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" @@ -2592,11 +2822,12 @@ dependencies = [ "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d138afcce92d219ccb6eb53d9b1e8a96ac0d633cfd3c53cd9856d96d1741bb8" +"checksum nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4836e9d6036552017e107edc598c97b2dee245161ff1b1ad4af215004774b354" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" -"checksum openssl 0.10.18 (registry+https://github.com/rust-lang/crates.io-index)" = "b90119d71b0a3596588da04bf7c2c42f2978cfa1217a94119d8ec9e963c7729c" +"checksum openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)" = "84321fb9004c3bce5611188a644d6171f895fa2889d155927d528782edb21c5d" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-sys 0.9.41 (registry+https://github.com/rust-lang/crates.io-index)" = "e4c77cdd67d31759b22aa72cfda3c65c12348f9e6c5420946b403c022fd0311a" +"checksum openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)" = "cb534d752bf98cf363b473950659ac2546517f9c6be9723771614ab3f03bbc9e" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-multiaddr 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=5655624)" = "" @@ -2607,15 +2838,18 @@ dependencies = [ "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66" "checksum proc-macro-nested 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9968e025d6368d1273a93bc23051e30dbf5482475e716d7385d8ec8fbd5b5b6" +"checksum proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "77997c53ae6edd6d187fec07ec41b207063b5ee6f33680e9fa86d405cdd313d4" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" "checksum protobuf 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d82d117bc7565ce6be0150159251c9b1eeec7b129f5a2aa86e10acb5970de1cb" "checksum quick-error 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5fb6ccf8db7bbcb9c2eae558db5ab4f3da1c2a87e4e597ed394726bc8ea6ca1d" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" +"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" @@ -2630,6 +2864,8 @@ dependencies = [ "checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" +"checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" @@ -2637,6 +2873,7 @@ dependencies = [ "checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" +"checksum rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1651697fefd273bfb4fd69466cc2a9d20de557a0213b97233b22b5e95924b5e" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" @@ -2668,6 +2905,7 @@ dependencies = [ "checksum stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1635afd059cbfac7d5b1274f0c44cec110c1e013c48e8bbc22e07e52696cf887" "checksum stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2f4a2eb556337b2d1a302630bbddf989ae383c70393e89b48152b9896cbda" "checksum stream-cipher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8861bc80f649f5b4c9bd38b696ae9af74499d479dbfb327f0607de6b326a36bc" +"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" "checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec" @@ -2675,6 +2913,7 @@ dependencies = [ "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" +"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" @@ -2709,15 +2948,18 @@ dependencies = [ "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2c64cdf40b4a9645534a943668681bcb219faf51874d4b65d2e0abda1b10a2ab" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum websocket 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7cc2d74d89f9df981ab41ae624e33cf302fdf456b93455c6a31911a99c9f0bb8" +"checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml index f4b8026e..a6908773 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ parity-multiaddr = { version = "*", git = "https://github.com/libp2p/rust-libp2p parity-multihash = { version = "*", git = "https://github.com/libp2p/rust-libp2p", rev = "5655624" } protobuf = "2.0.2" rand = "0.6" +rocksdb = "*" rustc-serialize = "0.3" serde = "1.0" serde_derive = "1.0" diff --git a/src/repo/fs.rs b/src/repo/fs.rs index 36b4170e..3ea7a431 100644 --- a/src/repo/fs.rs +++ b/src/repo/fs.rs @@ -1,6 +1,7 @@ //! Persistent fs backed repo use crate::block::{Cid, Block}; -use crate::repo::{BlockStore, DataStore}; +use crate::error::Error; +use crate::repo::{BlockStore, Column, DataStore}; use futures::compat::*; use futures::future::FutureObj; use std::collections::HashSet; @@ -24,11 +25,15 @@ impl BlockStore for FsBlockStore { } } - fn init(&self) -> FutureObj<'static, Result<(), std::io::Error>> { - FutureObj::new(Box::new(fs::create_dir_all(self.path.clone()).compat())) + fn init(&self) -> FutureObj<'static, Result<(), Error>> { + let path = self.path.clone(); + FutureObj::new(Box::new(async move { + await!(fs::create_dir_all(path).compat())?; + Ok(()) + })) } - fn open(&self) -> FutureObj<'static, Result<(), std::io::Error>> { + fn open(&self) -> FutureObj<'static, Result<(), Error>> { let path = self.path.clone(); let cids = self.cids.clone(); FutureObj::new(Box::new(async move { @@ -45,14 +50,14 @@ impl BlockStore for FsBlockStore { })) } - fn contains(&self, cid: &Cid) -> FutureObj<'static, Result> { + fn contains(&self, cid: &Cid) -> FutureObj<'static, Result> { let contains = self.cids.lock().unwrap().contains(cid); FutureObj::new(Box::new(async move { Ok(contains) }) } - fn get(&self, cid: &Cid) -> FutureObj<'static, Result, std::io::Error>> { + fn get(&self, cid: &Cid) -> FutureObj<'static, Result, Error>> { let path = block_path(self.path.clone(), cid); let cid = cid.to_owned(); FutureObj::new(Box::new(async move { @@ -62,7 +67,7 @@ impl BlockStore for FsBlockStore { if err.kind() == std::io::ErrorKind::NotFound { return Ok(None); } else { - return Err(err); + return Err(err.into()); } } }; @@ -72,7 +77,7 @@ impl BlockStore for FsBlockStore { })) } - fn put(&self, block: Block) -> FutureObj<'static, Result> { + fn put(&self, block: Block) -> FutureObj<'static, Result> { let path = block_path(self.path.clone(), &block.cid()); let cids = self.cids.clone(); FutureObj::new(Box::new(async move { @@ -84,13 +89,16 @@ impl BlockStore for FsBlockStore { })) } - fn remove(&self, cid: &Cid) -> FutureObj<'static, Result<(), std::io::Error>> { + fn remove(&self, cid: &Cid) -> FutureObj<'static, Result<(), Error>> { let path = block_path(self.path.clone(), cid); let cid = cid.to_owned(); let cids = self.cids.clone(); + let contains = self.contains(&cid); FutureObj::new(Box::new(async move { - await!(fs::remove_file(path).compat())?; - cids.lock().unwrap().remove(&cid); + if await!(contains)? { + await!(fs::remove_file(path).compat())?; + cids.lock().unwrap().remove(&cid); + } Ok(()) })) } @@ -99,18 +107,112 @@ impl BlockStore for FsBlockStore { #[derive(Clone, Debug)] pub struct RocksDataStore { path: PathBuf, + db: Arc>>, +} + +impl RocksDataStore { + fn get_cf(&self, col: Column) -> rocksdb::ColumnFamily { + let cf_name = match col { + Column::Ipns => "ipns" + }; + self.db.lock() + .unwrap() + .as_ref() + .unwrap() + .cf_handle(cf_name) + // TODO safe to unwrap + .unwrap() + } } impl DataStore for RocksDataStore { fn new(path: PathBuf) -> Self { RocksDataStore { - path + path, + db: Arc::new(Mutex::new(None)), } } - fn init(&self) -> FutureObj<'static, Result<(), std::io::Error>> { + fn init(&self) -> FutureObj<'static, Result<(), Error>> { FutureObj::new(Box::new(futures::future::ok(()))) } + + fn open(&self) -> FutureObj<'static, Result<(), Error>> { + let db = self.db.clone(); + let path = self.path.clone(); + FutureObj::new(Box::new(async move { + let mut db_opts = rocksdb::Options::default(); + db_opts.create_missing_column_families(true); + db_opts.create_if_missing(true); + + let ipns_opts = rocksdb::Options::default(); + let ipns_cf = rocksdb::ColumnFamilyDescriptor::new("ipns", ipns_opts); + let rdb = rocksdb::DB::open_cf_descriptors( + &db_opts, + &path, + vec![ipns_cf], + )?; + *db.lock().unwrap() = Some(rdb); + Ok(()) + })) + } + + fn contains(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result> + { + let cf = self.get_cf(col); + let db = self.db.clone(); + let key = key.to_owned(); + FutureObj::new(Box::new(async move { + let db = db.lock().unwrap(); + let db = db.as_ref().unwrap(); + let contains = db.get_cf(cf, &key)?.is_some(); + Ok(contains) + })) + } + + fn get(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result>, Error>> + { + let cf = self.get_cf(col); + let db = self.db.clone(); + let key = key.to_owned(); + FutureObj::new(Box::new(async move { + let db = db.lock().unwrap(); + let db = db.as_ref().unwrap(); + let get = db.get_cf(cf, &key)?.map(|value| value.to_vec()); + Ok(get) + })) + } + + fn put(&self, col: Column, key: &[u8], value: &[u8]) -> + FutureObj<'static, Result<(), Error>> + { + let cf = self.get_cf(col); + let db = self.db.clone(); + let key = key.to_owned(); + let value = value.to_owned(); + FutureObj::new(Box::new(async move { + let db = db.lock().unwrap(); + let db = db.as_ref().unwrap(); + db.put_cf(cf, &key, &value)?; + Ok(()) + })) + } + + fn remove(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result<(), Error>> + { + let cf = self.get_cf(col); + let db = self.db.clone(); + let key = key.to_owned(); + FutureObj::new(Box::new(async move { + let db = db.lock().unwrap(); + let db = db.as_ref().unwrap(); + db.delete_cf(cf, &key)?; + Ok(()) + })) + } } fn block_path(mut base: PathBuf, cid: &Cid) -> PathBuf { @@ -127,27 +229,38 @@ mod tests { #[test] fn test_fs_blockstore() { - let block = Block::from("1"); let mut tmp = temp_dir(); tmp.push("blockstore1"); std::fs::remove_dir_all(tmp.clone()).ok(); + let store = FsBlockStore::new(tmp.clone()); - let blockstore_path = tmp.clone(); tokio::run_async(async move { - let block_store = FsBlockStore::new(blockstore_path); - await!(block_store.init()).unwrap(); - await!(block_store.open()).unwrap(); + let block = Block::from("1"); + let cid = block.cid(); - assert!(!await!(block_store.contains(block.cid())).unwrap()); - assert_eq!(await!(block_store.get(block.cid())).unwrap(), None); + assert_eq!(await!(store.init()).unwrap(), ()); + assert_eq!(await!(store.open()).unwrap(), ()); - await!(block_store.put(block.clone())).unwrap(); - assert!(await!(block_store.contains(block.cid())).unwrap()); - assert_eq!(await!(block_store.get(block.cid())).unwrap().unwrap(), block); + let contains = store.contains(cid); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(cid); + assert_eq!(await!(get).unwrap(), None); + let remove = store.remove(cid); + assert_eq!(await!(remove).unwrap(), ()); - await!(block_store.remove(block.cid())).unwrap(); - assert!(!await!(block_store.contains(block.cid())).unwrap()); - assert_eq!(await!(block_store.get(block.cid())).unwrap(), None); + let put = store.put(block.clone()); + assert_eq!(await!(put).unwrap(), cid.to_owned()); + let contains = store.contains(cid); + assert_eq!(await!(contains).unwrap(), true); + let get = store.get(cid); + assert_eq!(await!(get).unwrap(), Some(block.clone())); + + let remove = store.remove(cid); + assert_eq!(await!(remove).unwrap(), ()); + let contains = store.contains(cid); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(cid); + assert_eq!(await!(get).unwrap(), None); }); std::fs::remove_dir_all(tmp).ok(); @@ -155,13 +268,14 @@ mod tests { #[test] fn test_fs_blockstore_open() { - let block = Block::from("1"); let mut tmp = temp_dir(); tmp.push("blockstore2"); std::fs::remove_dir_all(tmp.clone()).ok(); let blockstore_path = tmp.clone(); tokio::run_async(async move { + let block = Block::from("1"); + let block_store = FsBlockStore::new(blockstore_path.clone()); await!(block_store.init()).unwrap(); await!(block_store.open()).unwrap(); @@ -177,4 +291,44 @@ mod tests { std::fs::remove_dir_all(tmp).ok(); } + + #[test] + fn test_rocks_datastore() { + let mut tmp = temp_dir(); + tmp.push("datastore1"); + std::fs::remove_dir_all(tmp.clone()).ok(); + let store = RocksDataStore::new(tmp.clone()); + + tokio::run_async(async move { + let col = Column::Ipns; + let key = [1, 2, 3, 4]; + let value = [5, 6, 7, 8]; + + assert_eq!(await!(store.init()).unwrap(), ()); + assert_eq!(await!(store.open()).unwrap(), ()); + + let contains = store.contains(col, &key); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(col, &key); + assert_eq!(await!(get).unwrap(), None); + let remove = store.remove(col, &key); + assert_eq!(await!(remove).unwrap(), ()); + + let put = store.put(col, &key, &value); + assert_eq!(await!(put).unwrap(), ()); + let contains = store.contains(col, &key); + assert_eq!(await!(contains).unwrap(), true); + let get = store.get(col, &key); + assert_eq!(await!(get).unwrap(), Some(value.to_vec())); + + let remove = store.remove(col, &key); + assert_eq!(await!(remove).unwrap(), ()); + let contains = store.contains(col, &key); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(col, &key); + assert_eq!(await!(get).unwrap(), None); + }); + + std::fs::remove_dir_all(tmp).ok(); + } } diff --git a/src/repo/mem.rs b/src/repo/mem.rs index 51e6064b..d266d3a5 100644 --- a/src/repo/mem.rs +++ b/src/repo/mem.rs @@ -1,6 +1,7 @@ //! Volatile memory backed repo use crate::block::{Cid, Block}; -use crate::repo::{BlockStore, DataStore}; +use crate::error::Error; +use crate::repo::{BlockStore, DataStore, Column}; use futures::future::FutureObj; use std::collections::HashMap; use std::path::PathBuf; @@ -18,34 +19,34 @@ impl BlockStore for MemBlockStore { } } - fn init(&self) -> FutureObj<'static, Result<(), std::io::Error>> { + fn init(&self) -> FutureObj<'static, Result<(), Error>> { FutureObj::new(Box::new(futures::future::ok(()))) } - fn open(&self) -> FutureObj<'static, Result<(), std::io::Error>> { + fn open(&self) -> FutureObj<'static, Result<(), Error>> { FutureObj::new(Box::new(futures::future::ok(()))) } - fn contains(&self, cid: &Cid) -> FutureObj<'static, Result> { + fn contains(&self, cid: &Cid) -> FutureObj<'static, Result> { let contains = self.blocks.lock().unwrap().contains_key(cid); FutureObj::new(Box::new(futures::future::ok(contains))) } - fn get(&self, cid: &Cid) -> FutureObj<'static, Result, std::io::Error>> { + fn get(&self, cid: &Cid) -> FutureObj<'static, Result, Error>> { let block = self.blocks.lock().unwrap() .get(cid) .map(|block| block.to_owned()); FutureObj::new(Box::new(futures::future::ok(block))) } - fn put(&self, block: Block) -> FutureObj<'static, Result> { + fn put(&self, block: Block) -> FutureObj<'static, Result> { let cid = block.cid().to_owned(); self.blocks.lock().unwrap() .insert(cid.clone(), block); FutureObj::new(Box::new(futures::future::ok(cid))) } - fn remove(&self, cid: &Cid) -> FutureObj<'static, Result<(), std::io::Error>> { + fn remove(&self, cid: &Cid) -> FutureObj<'static, Result<(), Error>> { self.blocks.lock().unwrap().remove(cid); FutureObj::new(Box::new(futures::future::ok(()))) } @@ -53,15 +54,61 @@ impl BlockStore for MemBlockStore { #[derive(Clone, Debug)] pub struct MemDataStore { - + ipns: Arc, Vec>>>, } impl DataStore for MemDataStore { fn new(_path: PathBuf) -> Self { - MemDataStore {} + MemDataStore { + ipns: Arc::new(Mutex::new(HashMap::new())), + } } - fn init(&self) -> FutureObj<'static, Result<(), std::io::Error>> { + fn init(&self) -> FutureObj<'static, Result<(), Error>> { + FutureObj::new(Box::new(futures::future::ok(()))) + } + + fn open(&self) -> FutureObj<'static, Result<(), Error>> { + FutureObj::new(Box::new(futures::future::ok(()))) + } + + fn contains(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result> + { + let map = match col { + Column::Ipns => &self.ipns + }; + let contains = map.lock().unwrap().contains_key(key); + FutureObj::new(Box::new(futures::future::ok(contains))) + } + + fn get(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result>, Error>> + { + let map = match col { + Column::Ipns => &self.ipns + }; + let value = map.lock().unwrap().get(key).map(|value| value.to_owned()); + FutureObj::new(Box::new(futures::future::ok(value))) + } + + fn put(&self, col: Column, key: &[u8], value: &[u8]) -> + FutureObj<'static, Result<(), Error>> + { + let map = match col { + Column::Ipns => &self.ipns + }; + map.lock().unwrap().insert(key.to_owned(), value.to_owned()); + FutureObj::new(Box::new(futures::future::ok(()))) + } + + fn remove(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result<(), Error>> + { + let map = match col { + Column::Ipns => &self.ipns + }; + map.lock().unwrap().remove(key); FutureObj::new(Box::new(futures::future::ok(()))) } } @@ -73,23 +120,70 @@ mod tests { #[test] fn test_mem_blockstore() { - let block = Block::from("1"); let tmp = temp_dir(); - let block_store = MemBlockStore::new(tmp); + let store = MemBlockStore::new(tmp); tokio::run_async(async move { - await!(block_store.init()).unwrap(); - await!(block_store.open()).unwrap(); + let block = Block::from("1"); + let cid = block.cid(); - assert!(!await!(block_store.contains(block.cid())).unwrap()); - assert_eq!(await!(block_store.get(block.cid())).unwrap(), None); + assert_eq!(await!(store.init()).unwrap(), ()); + assert_eq!(await!(store.open()).unwrap(), ()); - await!(block_store.put(block.clone())).unwrap(); - assert!(await!(block_store.contains(block.cid())).unwrap()); - assert_eq!(await!(block_store.get(block.cid())).unwrap().unwrap(), block); + let contains = store.contains(cid); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(cid); + assert_eq!(await!(get).unwrap(), None); + let remove = store.remove(cid); + assert_eq!(await!(remove).unwrap(), ()); - await!(block_store.remove(block.cid())).unwrap(); - assert!(!await!(block_store.contains(block.cid())).unwrap()); - assert_eq!(await!(block_store.get(block.cid())).unwrap(), None); + let put = store.put(block.clone()); + assert_eq!(await!(put).unwrap(), cid.to_owned()); + let contains = store.contains(cid); + assert_eq!(await!(contains).unwrap(), true); + let get = store.get(cid); + assert_eq!(await!(get).unwrap(), Some(block.clone())); + + let remove = store.remove(cid); + assert_eq!(await!(remove).unwrap(), ()); + let contains = store.contains(cid); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(cid); + assert_eq!(await!(get).unwrap(), None); + }); + } + + #[test] + fn test_mem_datastore() { + let tmp = temp_dir(); + let store = MemDataStore::new(tmp); + tokio::run_async(async move { + let col = Column::Ipns; + let key = [1, 2, 3, 4]; + let value = [5, 6, 7, 8]; + + assert_eq!(await!(store.init()).unwrap(), ()); + assert_eq!(await!(store.open()).unwrap(), ()); + + let contains = store.contains(col, &key); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(col, &key); + assert_eq!(await!(get).unwrap(), None); + let remove = store.remove(col, &key); + assert_eq!(await!(remove).unwrap(), ()); + + let put = store.put(col, &key, &value); + assert_eq!(await!(put).unwrap(), ()); + let contains = store.contains(col, &key); + assert_eq!(await!(contains).unwrap(), true); + let get = store.get(col, &key); + assert_eq!(await!(get).unwrap(), Some(value.to_vec())); + + let remove = store.remove(col, &key); + assert_eq!(await!(remove).unwrap(), ()); + let contains = store.contains(col, &key); + assert_eq!(await!(contains).unwrap(), false); + let get = store.get(col, &key); + assert_eq!(await!(get).unwrap(), None); }); } } diff --git a/src/repo/mod.rs b/src/repo/mod.rs index b4d8078a..ca9e930d 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,5 +1,7 @@ //! IPFS repo use crate::block::{Cid, Block}; +use crate::error::Error; +use crate::ipld::IpldPath; use crate::future::BlockFuture; use crate::IpfsOptions; use core::future::Future; @@ -39,17 +41,39 @@ pub fn create_repo(options: RepoOptions) -> R pub trait BlockStore: Clone + Send + Sync + Unpin + 'static { fn new(path: PathBuf) -> Self; - fn init(&self) -> FutureObj<'static, Result<(), std::io::Error>>; - fn open(&self) -> FutureObj<'static, Result<(), std::io::Error>>; - fn contains(&self, cid: &Cid) -> FutureObj<'static, Result>; - fn get(&self, cid: &Cid) -> FutureObj<'static, Result, std::io::Error>>; - fn put(&self, block: Block) -> FutureObj<'static, Result>; - fn remove(&self, cid: &Cid) -> FutureObj<'static, Result<(), std::io::Error>>; + fn init(&self) -> + FutureObj<'static, Result<(), Error>>; + fn open(&self) -> + FutureObj<'static, Result<(), Error>>; + fn contains(&self, cid: &Cid) -> + FutureObj<'static, Result>; + fn get(&self, cid: &Cid) -> + FutureObj<'static, Result, Error>>; + fn put(&self, block: Block) -> + FutureObj<'static, Result>; + fn remove(&self, cid: &Cid) -> + FutureObj<'static, Result<(), Error>>; } pub trait DataStore: Clone + Send + Sync + Unpin + 'static { fn new(path: PathBuf) -> Self; - fn init(&self) -> FutureObj<'static, Result<(), std::io::Error>>; + fn init(&self) -> + FutureObj<'static, Result<(), Error>>; + fn open(&self) -> + FutureObj<'static, Result<(), Error>>; + fn contains(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result>; + fn get(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result>, Error>>; + fn put(&self, col: Column, key: &[u8], value: &[u8]) -> + FutureObj<'static, Result<(), Error>>; + fn remove(&self, col: Column, key: &[u8]) -> + FutureObj<'static, Result<(), Error>>; +} + +#[derive(Clone, Copy, Debug)] +pub enum Column { + Ipns } #[derive(Clone, Debug)] @@ -81,7 +105,7 @@ impl Repo { } } - pub fn init(&self) -> impl Future> { + pub fn init(&self) -> impl Future> { let block_store = self.block_store.clone(); let data_store = self.data_store.clone(); async move { @@ -96,12 +120,25 @@ impl Repo { } } - pub fn open(&self) -> impl Future> { - self.block_store.open() + pub fn open(&self) -> impl Future> { + let block_store = self.block_store.clone(); + let data_store = self.data_store.clone(); + async move { + let f1 = block_store.open(); + let f2 = data_store.open(); + let (r1, r2) = join!(f1, f2); + if r1.is_err() { + r1 + } else { + r2 + } + } } /// Puts a block into the block store. - pub fn put_block(&self, block: Block) -> impl Future> { + pub fn put_block(&self, block: Block) -> + impl Future> + { let events = self.events.clone(); let block_store = self.block_store.clone(); async move { @@ -112,7 +149,9 @@ impl Repo { } /// Retrives a block from the block store. - pub fn get_block(&self, cid: &Cid) -> impl Future> { + pub fn get_block(&self, cid: &Cid) -> + impl Future> + { let cid = cid.to_owned(); let events = self.events.clone(); let block_store = self.block_store.clone(); @@ -125,10 +164,41 @@ impl Repo { } /// Remove block from the block store. - pub fn remove_block(&self, cid: &Cid) -> impl Future> { - self.events.lock().unwrap().push_back(RepoEvent::UnprovideBlock(cid.to_owned())); + pub fn remove_block(&self, cid: &Cid) -> + impl Future> + { + self.events.lock().unwrap() + .push_back(RepoEvent::UnprovideBlock(cid.to_owned())); self.block_store.remove(cid) } + + /// Get an ipld path from the datastore. + pub fn get_ipns(&self, ipns: &Cid) -> + impl Future, Error>> + { + let data_store = self.data_store.clone(); + let key = ipns.to_bytes(); + async move { + let bytes = await!(data_store.get(Column::Ipns, &key))?; + match bytes { + Some(ref bytes) => { + let string = String::from_utf8_lossy(bytes); + let path = IpldPath::from_str(&string)?; + Ok(Some(path)) + } + None => Ok(None) + } + } + } + + /// Put an ipld path into the datastore. + pub fn put_ipns(&self, ipns: &Cid, path: &IpldPath) -> + impl Future> + { + let string = path.to_string(); + let value = string.as_bytes(); + self.data_store.put(Column::Ipns, &ipns.to_bytes(), value) + } } #[cfg(test)]