Explorar el Código

Started implementing FsProvider for FsClient.

Matthew Carr hace 1 año
padre
commit
4a0149520b
Se han modificado 3 ficheros con 197 adiciones y 42 borrados
  1. 52 40
      Cargo.lock
  2. 1 0
      crates/btfproto/Cargo.toml
  3. 144 2
      crates/btfproto/src/client.rs

+ 52 - 40
Cargo.lock

@@ -73,7 +73,7 @@ checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -184,6 +184,7 @@ dependencies = [
  "btserde",
  "bytes",
  "fuse-backend-rs",
+ "futures",
  "libc",
  "log",
  "paste",
@@ -584,7 +585,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb"
 dependencies = [
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -611,7 +612,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "scratch",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -628,7 +629,7 @@ checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -674,7 +675,7 @@ checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -739,9 +740,9 @@ dependencies = [
 
 [[package]]
 name = "futures"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0"
+checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
 dependencies = [
  "futures-channel",
  "futures-core",
@@ -754,9 +755,9 @@ dependencies = [
 
 [[package]]
 name = "futures-channel"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed"
+checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
 dependencies = [
  "futures-core",
  "futures-sink",
@@ -764,15 +765,15 @@ dependencies = [
 
 [[package]]
 name = "futures-core"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac"
+checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
 
 [[package]]
 name = "futures-executor"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2"
+checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
 dependencies = [
  "futures-core",
  "futures-task",
@@ -781,38 +782,38 @@ dependencies = [
 
 [[package]]
 name = "futures-io"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb"
+checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
 
 [[package]]
 name = "futures-macro"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d"
+checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 2.0.13",
 ]
 
 [[package]]
 name = "futures-sink"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9"
+checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
 
 [[package]]
 name = "futures-task"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea"
+checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
 
 [[package]]
 name = "futures-util"
-version = "0.3.25"
+version = "0.3.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6"
+checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
 dependencies = [
  "futures-channel",
  "futures-core",
@@ -1123,7 +1124,7 @@ checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -1208,7 +1209,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -1377,9 +1378,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.43"
+version = "1.0.56"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
+checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
 dependencies = [
  "unicode-ident",
 ]
@@ -1436,9 +1437,9 @@ dependencies = [
 
 [[package]]
 name = "quote"
-version = "1.0.21"
+version = "1.0.26"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
+checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
 dependencies = [
  "proc-macro2",
 ]
@@ -1769,7 +1770,7 @@ checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -1873,7 +1874,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "rustversion",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -1899,6 +1900,17 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "syn"
+version = "2.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
 [[package]]
 name = "synstructure"
 version = "0.12.6"
@@ -1907,7 +1919,7 @@ checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
  "unicode-xid",
 ]
 
@@ -1968,7 +1980,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -2033,7 +2045,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -2095,7 +2107,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -2246,7 +2258,7 @@ dependencies = [
  "once_cell",
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
  "wasm-bindgen-shared",
 ]
 
@@ -2268,7 +2280,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
  "wasm-bindgen-backend",
  "wasm-bindgen-shared",
 ]
@@ -2477,7 +2489,7 @@ checksum = "6505e6815af7de1746a08f69c69606bb45695a17149517680f3b2149713b19a3"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
 ]
 
 [[package]]
@@ -2497,6 +2509,6 @@ checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
+ "syn 1.0.100",
  "synstructure",
 ]

+ 1 - 0
crates/btfproto/Cargo.toml

@@ -25,3 +25,4 @@ fuse-backend-rs = { version = "0.9.6", optional = true }
 btserde = { path = "../btserde", optional = true }
 bytes = { version = "1.3.0", optional = true }
 zeroize = { version = "1.5.7" }
+futures = "0.3.25"

+ 144 - 2
crates/btfproto/src/client.rs

@@ -1,11 +1,13 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
-use crate::{msg::*, Handle, Inode};
+use crate::{msg::*, Handle, Inode, server::FsProvider};
 
-use btlib::{bterr, crypto::ConcretePub, IssuedProcRec, Result};
+use btlib::{bterr, crypto::ConcretePub, IssuedProcRec, Result, BlockPath};
 use btmsg::{DeserCallback, Transmitter};
 
 use core::future::{ready, Future, Ready};
+use std::{sync::Arc, ops::Deref};
 use paste::paste;
+use futures::FutureExt;
 
 macro_rules! extractor {
     ($variant:ident) => {
@@ -139,6 +141,146 @@ impl<T> FsClient<T> {
     }
 }
 
+impl<T: Send + Sync + Transmitter> FsProvider for FsClient<T> {
+    type LookupFut<'c> = impl 'c  + Send + Future<Output = Result<LookupReply>> where T: 'c;
+    fn lookup<'c>(&'c self, _from: &'c Arc<BlockPath>, msg: Lookup<'c>) -> Self::LookupFut<'c> {
+        self.tx.call(FsMsg::Lookup(msg), extractor!(Lookup)).map(|e| e?)
+    }
+
+    type CreateFut<'c> = impl Send + Future<Output = Result<CreateReply>> where T: 'c;
+    fn create<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Create<'c>) -> Self::CreateFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type OpenFut<'c> = impl Send + Future<Output = Result<OpenReply>> where T: 'c;
+    fn open<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Open) -> Self::OpenFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type ReadGuard = Vec<u8>;
+    type ReadFut<'c> = impl 'c + Send + Future<Output = Result<Self::ReadGuard>> where T: 'c;
+    /// Reads from the file specified in the given message.
+    /// ### WARNING
+    /// The returned guard must be dropped before another method is called on this provider.
+    /// Otherwise deadlock _will_ occur.
+    fn read<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Read) -> Self::ReadFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type WriteFut<'r> = impl 'r + Send + Future<Output = Result<WriteReply>> where T: 'r;
+    fn write<'c>(&'c self, from: &'c Arc<BlockPath>, write: Write<&'c [u8]>) -> Self::WriteFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type FlushFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn flush<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Flush) -> Self::FlushFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type ReadDirFut<'c> = impl 'c + Send + Future<Output = Result<ReadDirReply>> where T: 'c;
+    fn read_dir<'c>(&'c self, from: &'c Arc<BlockPath>, msg: ReadDir) -> Self::ReadDirFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type LinkFut<'c> = impl 'c + Send + Future<Output = Result<LinkReply>> where T: 'c;
+    fn link<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Link<'c>) -> Self::LinkFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type UnlinkFut<'c> = impl 'c +  Send + Future<Output = Result<()>> where T: 'c;
+    fn unlink<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Unlink<'c>) -> Self::UnlinkFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type ReadMetaFut<'c> = impl 'c + Send + Future<Output = Result<ReadMetaReply>> where T: 'c;
+    fn read_meta<'c>(&'c self, from: &'c Arc<BlockPath>, msg: ReadMeta) -> Self::ReadMetaFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type WriteMetaFut<'c> = impl 'c + Send + Future<Output = Result<WriteMetaReply>> where T: 'c;
+    fn write_meta<'c>(&'c self, from: &'c Arc<BlockPath>, msg: WriteMeta)
+        -> Self::WriteMetaFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type AllocateFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn allocate<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Allocate) -> Self::AllocateFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type CloseFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn close<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Close) -> Self::CloseFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type ForgetFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn forget<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Forget) -> Self::ForgetFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type LockFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn lock<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Lock) -> Self::LockFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type UnlockFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn unlock<'c>(&'c self, from: &'c Arc<BlockPath>, msg: Unlock) -> Self::UnlockFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type AddReacapFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn add_readcap<'c>(
+        &'c self,
+        from: &'c Arc<BlockPath>,
+        msg: AddReadcap,
+    ) -> Self::AddReacapFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+
+    type GrantAccessFut<'c> = impl 'c + Send + Future<Output = Result<()>> where T: 'c;
+    fn grant_access<'c>(
+        &'c self,
+        from: &'c Arc<BlockPath>,
+        msg: GrantAccess,
+    ) -> Self::GrantAccessFut<'c> {
+        async move {
+            todo!()
+        }
+    }
+}
+
 impl<T: Transmitter> FsClient<T> {
     /// Lookup up the given name under the given inode.
     pub async fn lookup(&self, parent: Inode, name: &str) -> Result<LookupReply> {