From 5466a110273f890e1549d0a64a3367ae1511bcfb Mon Sep 17 00:00:00 2001 From: Sam Stelfox Date: Tue, 13 Feb 2024 23:38:31 -0500 Subject: [PATCH] feat: concurrency aww yeah --- Cargo.lock | 529 ++++++++++++++++++++++++++- Cargo.toml | 1 + src/filesystem/drive.rs | 162 +++++--- src/filesystem/mod.rs | 2 +- src/filesystem/nodes/mod.rs | 8 +- src/filesystem/nodes/node_builder.rs | 4 +- src/filesystem/nodes/node_kind.rs | 4 +- src/filesystem/operations.rs | 3 + src/main.rs | 15 +- 9 files changed, 654 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4fa8582..e27bcc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,6 +48,150 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28243a43d821d11341ab73c80bed182dc015c514b951616cf79bd4af39af0c3" +dependencies = [ + "concurrent-queue", + "event-listener 5.0.0", + "event-listener-strategy 0.5.0", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" +dependencies = [ + "async-lock 3.3.0", + "async-task", + "concurrent-queue", + "fastrand 2.0.1", + "futures-lite 2.2.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.2.0", + "async-executor", + "async-io 2.3.1", + "async-lock 3.3.0", + "blocking", + "futures-lite 2.2.0", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f97ab0c5b00a7cdbe5a371b9a782ee7be1316095885c8a4ea1daf490eb0ef65" +dependencies = [ + "async-lock 3.3.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.2.0", + "parking", + "polling 3.4.0", + "rustix 0.38.31", + "slab", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" +dependencies = [ + "event-listener 4.0.3", + "event-listener-strategy 0.4.0", + "pin-project-lite", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" + [[package]] name = "async-trait" version = "0.1.77" @@ -65,6 +209,12 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.1.0" @@ -90,6 +240,7 @@ dependencies = [ name = "banyanfs" version = "0.1.0" dependencies = [ + "async-std", "async-trait", "blake3", "bytes", @@ -139,6 +290,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + [[package]] name = "blake3" version = "1.5.0" @@ -162,6 +319,22 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" +dependencies = [ + "async-channel 2.2.0", + "async-lock 3.3.0", + "async-task", + "fastrand 2.0.1", + "futures-io", + "futures-lite 2.2.0", + "piper", + "tracing", +] + [[package]] name = "bumpalo" version = "3.14.0" @@ -224,6 +397,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "concurrent-queue" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -377,6 +559,79 @@ dependencies = [ "zeroize", ] +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b72557800024fabbaa2449dd4bf24e37b93702d457a4d4f2b0dd1f0f039f20c1" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" +dependencies = [ + "event-listener 4.0.3", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feedafcaa9b749175d5ac357452a9d41ea2911da598fde46ce1fe02c37751291" +dependencies = [ + "event-listener 5.0.0", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "ff" version = "0.13.0" @@ -435,6 +690,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" +dependencies = [ + "fastrand 2.0.1", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -506,6 +789,18 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "group" version = "0.13.0" @@ -550,6 +845,26 @@ dependencies = [ "generic-array", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "itoa" version = "1.0.10" @@ -565,6 +880,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -577,6 +901,18 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + [[package]] name = "lock_api" version = "0.4.11" @@ -592,6 +928,9 @@ name = "log" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +dependencies = [ + "value-bag", +] [[package]] name = "matchers" @@ -631,7 +970,7 @@ checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -787,6 +1126,12 @@ dependencies = [ "sha2", ] +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "parking_lot" version = "0.12.1" @@ -807,7 +1152,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -831,6 +1176,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.1", + "futures-io", +] + [[package]] name = "pkcs8" version = "0.10.2" @@ -841,6 +1197,36 @@ dependencies = [ "spki", ] +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "polling" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30054e72317ab98eddd8561db0f6524df3367636884b7b21b703e4b280a84a14" +dependencies = [ + "cfg-if", + "concurrent-queue", + "pin-project-lite", + "rustix 0.38.31", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "poly1305" version = "0.8.0" @@ -927,7 +1313,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -990,6 +1376,33 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys 0.4.13", + "windows-sys 0.52.0", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -1090,6 +1503,16 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.5" @@ -1097,7 +1520,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1211,9 +1634,9 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.5", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1365,12 +1788,24 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126e423afe2dd9ac52142e7e9d5ce4135d7e13776c529d27fd6bc49f19e3280b" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1506,7 +1941,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -1515,13 +1959,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -1530,42 +1989,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "zeroize" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index 9a9df74..c3d3940 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ default = ["strict"] strict = [] [dependencies] +async-std = "^1" async-trait = "^0.1" futures = "^0.3" thiserror = "^1" diff --git a/src/filesystem/drive.rs b/src/filesystem/drive.rs index c3b0995..275ee2d 100644 --- a/src/filesystem/drive.rs +++ b/src/filesystem/drive.rs @@ -1,5 +1,8 @@ +use std::collections::HashMap; use std::path::{Component, Path}; +use std::sync::Arc; +use async_std::sync::RwLock; use elliptic_curve::rand_core::CryptoRngCore; use slab::Slab; @@ -8,25 +11,30 @@ use crate::codec::header::KeyAccessSettingsBuilder; use crate::codec::meta::{ActorId, FilesystemId}; use crate::filesystem::nodes::NodeKind; use crate::filesystem::operations::*; -use crate::filesystem::{DriveAccess, Node, NodeBuilder, NodeId, PermanentNodeId}; +use crate::filesystem::{DriveAccess, Node, NodeBuilder, NodeId, PermanentId}; pub struct Drive { current_key: SigningKey, - filesystem_id: FilesystemId, - access: DriveAccess, + inner: Arc>, +} +struct InnerDrive { + access: DriveAccess, nodes: Slab, root_node_id: NodeId, + permanent_id_map: HashMap, } impl Drive { - pub fn has_realized_view_access(&self, actor_id: ActorId) -> bool { - self.access.has_realized_view_access(actor_id) + pub async fn has_realized_view_access(&self, actor_id: ActorId) -> bool { + let inner = self.inner.read().await; + inner.access.has_realized_view_access(actor_id) } - pub fn has_write_access(&self, actor_id: ActorId) -> bool { - self.access.has_write_access(actor_id) + pub async fn has_write_access(&self, actor_id: ActorId) -> bool { + let inner = self.inner.read().await; + inner.access.has_write_access(actor_id) } //pub async fn encode_private( @@ -79,71 +87,133 @@ impl Drive { access.register_actor(verifying_key, kas); let mut nodes = Slab::with_capacity(32); + let mut permanent_id_map = HashMap::new(); let node_entry = nodes.vacant_entry(); let root_node_id = node_entry.key(); let directory = NodeBuilder::directory(root_node_id, actor_id).build(rng); + permanent_id_map.insert(directory.permanent_id(), root_node_id); node_entry.insert(directory); Self { current_key, - filesystem_id, - access, - nodes, - root_node_id, + inner: Arc::new(RwLock::new(InnerDrive { + access, + nodes, + root_node_id, + permanent_id_map, + })), } } - pub(crate) fn root_directory(&mut self) -> Directory { - Directory::new(self, self.root_node_id) + pub async fn mkdir( + &mut self, + _rng: &mut impl CryptoRngCore, + _path: &Path, + _recursive: bool, + ) -> Result { + todo!() + } + + pub(crate) async fn root_directory(&mut self) -> Directory { + let inner_read = self.inner.read().await; + let root_node_id = inner_read.root_node_id; + drop(inner_read); + + Directory::new(&self.current_key, root_node_id, self.inner.clone()).await } } pub struct Directory<'a> { - drive: &'a mut Drive, - node_id: NodeId, + current_key: &'a SigningKey, + cwd_id: NodeId, + inner: Arc>, } impl<'a> Directory<'a> { - //async fn ls(mut self, path: &Path) -> Result, OperationError> { - // let mut components = path.components(); - - // let mut active_path = components.next(); - // if let Some(Component::RootDir) = active_path { - // self.node_id = self.drive.root_node_id; - // active_path = components.next(); - // } - - // let node_children = match self.drive.nodes[self.node_id].kind() { - // NodeKind::Directory { children, .. } => children, - // _ => return Err(OperationError::IncompatibleType("ls")), - // }; - - // if active_path.is_none() || active_path == Some(Component::CurDir) { - // let contents: Vec<_> = node_children - // .iter() - // .map(|(name, pid)| (name.clone(), pid.clone())) - // .collect(); - - // return Ok(contents); - // } - // - // // todo: need to get the next node id , validate its a directory and then continue - - // self.ls(components.as_path()).await - //} + async fn walk_directory(&self, path: &Path) -> Result { + let mut components = path.components(); + let mut cwd_id = self.cwd_id; + + loop { + let mut active_path = match components.next() { + Some(path) => path, + None => return Err(OperationError::UnexpectedEmptyPath), + }; + + match active_path { + Component::RootDir => { + cwd_id = self.inner.read().await.root_node_id; + } + _ => (), + } + + let node_children = match self.inner.read().await.nodes[cwd_id].kind() { + NodeKind::Directory { children, .. } => children, + _ => return Err(OperationError::IncompatibleType("ls")), + }; + + todo!() + } + } + + async fn ls(mut self, path: &Path) -> Result, OperationError> { + let mut components = path.components(); + let mut cwd_id = self.cwd_id; + + let inner_read = self.inner.read().await; + + loop { + let mut active_path = components.next(); + if let Some(Component::RootDir) = active_path { + cwd_id = inner_read.root_node_id; + active_path = components.next(); + } + + let node_children = match inner_read.nodes[cwd_id].kind() { + NodeKind::Directory { children, .. } => children, + _ => return Err(OperationError::IncompatibleType("ls")), + }; + + match active_path { + Some(Component::CurDir) => (), + None => { + let contents: Vec<_> = node_children + .iter() + .map(|(name, pid)| (name.clone(), *pid)) + .collect(); + + return Ok(contents); + } + _ => (), + } + + todo!() + } + } + + pub async fn new( + current_key: &'a SigningKey, + cwd_id: NodeId, + inner: Arc>, + ) -> Self { + let inner_read = inner.read().await; - pub fn new(drive: &'a mut Drive, node_id: NodeId) -> Self { - debug_assert!(drive.nodes.contains(node_id)); + debug_assert!(inner_read.nodes.contains(cwd_id)); debug_assert!(matches!( - drive.nodes[node_id].kind(), + inner_read.nodes[cwd_id].kind(), NodeKind::Directory { .. } )); + drop(inner_read); - Self { drive, node_id } + Self { + current_key, + cwd_id, + inner, + } } pub fn mkdir( diff --git a/src/filesystem/mod.rs b/src/filesystem/mod.rs index a42eb48..52e99b8 100644 --- a/src/filesystem/mod.rs +++ b/src/filesystem/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod nodes; pub(crate) use content_reference::ContentReference; pub(crate) use file_content::FileContent; -pub(crate) use nodes::{Node, NodeBuilder, NodeId, PermanentNodeId}; +pub(crate) use nodes::{Node, NodeBuilder, NodeId, PermanentId}; pub(crate) use vector_clock::VectorClock; pub use drive::Drive; diff --git a/src/filesystem/nodes/mod.rs b/src/filesystem/nodes/mod.rs index 4fef0ee..0ac4406 100644 --- a/src/filesystem/nodes/mod.rs +++ b/src/filesystem/nodes/mod.rs @@ -12,14 +12,14 @@ use crate::codec::meta::ActorId; pub(crate) type NodeId = usize; -pub(crate) type PermanentNodeId = [u8; 16]; +pub(crate) type PermanentId = [u8; 16]; pub struct Node { node_id: NodeId, parent_id: Option, owner_id: ActorId, - permanent_id: PermanentNodeId, + permanent_id: PermanentId, created_at: OffsetDateTime, modified_at: OffsetDateTime, @@ -37,6 +37,10 @@ impl Node { self.owner_id } + pub fn permanent_id(&self) -> PermanentId { + self.permanent_id + } + pub fn set_attribute(&mut self, key: String, value: Vec) -> Option> { self.metadata.insert(key, value) } diff --git a/src/filesystem/nodes/node_builder.rs b/src/filesystem/nodes/node_builder.rs index 0eef614..ed4e5ff 100644 --- a/src/filesystem/nodes/node_builder.rs +++ b/src/filesystem/nodes/node_builder.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use time::OffsetDateTime; use crate::codec::meta::ActorId; -use crate::filesystem::nodes::{Node, NodeId, NodeKind, PermanentNodeId}; +use crate::filesystem::nodes::{Node, NodeId, NodeKind, PermanentId}; pub(crate) struct NodeBuilder { node_id: NodeId, @@ -30,7 +30,7 @@ impl NodeBuilder { } pub fn build(self, rng: &mut impl CryptoRngCore) -> Node { - let permanent_id: PermanentNodeId = rng.gen(); + let permanent_id: PermanentId = rng.gen(); Node { node_id: self.node_id, diff --git a/src/filesystem/nodes/node_kind.rs b/src/filesystem/nodes/node_kind.rs index 4cd8669..fb13cc6 100644 --- a/src/filesystem/nodes/node_kind.rs +++ b/src/filesystem/nodes/node_kind.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::codec::filesystem::DirectoryPermissions; use crate::codec::filesystem::FilePermissions; use crate::filesystem::FileContent; -use crate::filesystem::PermanentNodeId; +use crate::filesystem::PermanentId; pub enum NodeKind { File { @@ -12,7 +12,7 @@ pub enum NodeKind { }, Directory { permissions: DirectoryPermissions, - children: HashMap, + children: HashMap, children_size: u64, }, } diff --git a/src/filesystem/operations.rs b/src/filesystem/operations.rs index 2697cc2..0d37396 100644 --- a/src/filesystem/operations.rs +++ b/src/filesystem/operations.rs @@ -21,6 +21,9 @@ pub(crate) trait Movable { pub enum OperationError { #[error("the {0} operation is not supported by this node type")] IncompatibleType(&'static str), + + #[error("unable to make use of an empty path")] + UnexpectedEmptyPath, } #[async_trait] diff --git a/src/main.rs b/src/main.rs index 571c2a4..bb32bf3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,18 +34,19 @@ async fn main() -> BanyanFsResult<()> { let verifying_key = signing_key.verifying_key(); let actor_id = verifying_key.actor_id(); - let drive = Drive::initialize_private(&mut rng, signing_key.clone()); + let mut drive = Drive::initialize_private(&mut rng, signing_key.clone()); - if !drive.has_realized_view_access(actor_id) { + if !drive.has_realized_view_access(actor_id).await { tracing::error!("key doesn't have access to the drive"); return Err(BanyanFsError("key doesn't have access to the drive")); } - if drive.has_write_access(actor_id) { - // if let Err(err) = drive.mkdir(&mut rng, &["testing", "paths"], true) { - // tracing::error!("failed to create directory: {}", err); - // return Ok(()); - // } + if drive.has_write_access(actor_id).await { + let path_buf = std::path::PathBuf::from("/testing/paths"); + if let Err(err) = drive.mkdir(&mut rng, path_buf.as_path(), true).await { + tracing::error!("failed to create directory: {}", err); + return Ok(()); + } // // let fh = drive.open("/root/testing/deep/paths/file.txt")?; // // fh.write(b"hello world")?;