Skip to content

Commit

Permalink
Merge pull request #4 from functionland/revert-3-remove_lifespans
Browse files Browse the repository at this point in the history
Revert "removed all `a"
  • Loading branch information
ehsan6sha authored Jul 16, 2023
2 parents 57bec66 + a21e595 commit c95b0cb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wnfsutils"
version = "1.0.2"
version = "1.0.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
26 changes: 13 additions & 13 deletions src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@ use bytes::Bytes;
use libipld::Cid;
use wnfs::common::{BlockStore, BlockStoreError};

pub trait FFIStore: FFIStoreClone {
pub trait FFIStore<'a>: FFIStoreClone<'a> {
fn get_block(&self, cid: Vec<u8>) -> Result<Vec<u8>>;
fn put_block(&self, cid: Vec<u8>, bytes: Vec<u8>) -> Result<()>;
}

pub trait FFIStoreClone {
fn clone_box(&self) -> Box<dyn FFIStore>;
pub trait FFIStoreClone<'a> {
fn clone_box(&self) -> Box<dyn FFIStore<'a> + 'a>;
}

impl<T> FFIStoreClone for T
impl<'a, T> FFIStoreClone<'a> for T
where
T: 'static + FFIStore + Clone,
T: 'a + FFIStore<'a> + Clone,
{
fn clone_box(&self) -> Box<dyn FFIStore> {
fn clone_box(&self) -> Box<dyn FFIStore<'a> + 'a> {
Box::new(self.clone())
}
}

impl Clone for Box<dyn FFIStore> {
fn clone(&self) -> Box<dyn FFIStore> {
impl<'a> Clone for Box<dyn FFIStore<'a> + 'a> {
fn clone(&self) -> Box<dyn FFIStore<'a> + 'a> {
self.clone_box()
}
}

#[derive(Clone)]
pub struct FFIFriendlyBlockStore {
pub ffi_store: Box<dyn FFIStore>,
pub struct FFIFriendlyBlockStore<'a> {
pub ffi_store: Box<dyn FFIStore<'a> + 'a>,
}

//--------------------------------------------------------------------------------------------------
// Implementations
//--------------------------------------------------------------------------------------------------

impl FFIFriendlyBlockStore {
impl<'a> FFIFriendlyBlockStore<'a> {
/// Creates a new kv block store.
pub fn new(ffi_store: Box<dyn FFIStore>) -> Self {
pub fn new(ffi_store: Box<dyn FFIStore<'a>>) -> Self {
Self { ffi_store }
}
}

#[async_trait(?Send)]
impl BlockStore for FFIFriendlyBlockStore {
impl<'a> BlockStore for FFIFriendlyBlockStore<'a> {
/// Retrieves an array of bytes from the block store with given CID.
async fn get_block(&self, cid: &Cid) -> Result<Bytes> {
let bytes = self
Expand Down
2 changes: 1 addition & 1 deletion src/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl KVBlockStore {
}
}

impl FFIStore for KVBlockStore {
impl<'a> FFIStore<'a> for KVBlockStore {
/// Retrieves an array of bytes from the block store with given CID.
fn get_block(&self, cid: Vec<u8>) -> Result<Vec<u8>> {
// A Bucket provides typed access to a section of the key/value store
Expand Down
48 changes: 24 additions & 24 deletions src/private_forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static mut STATE: Mutex<State> = Mutex::new(State {
wnfs_key: Vec::new(),
});

pub struct PrivateDirectoryHelper {
pub store: FFIFriendlyBlockStore,
pub struct PrivateDirectoryHelper<'a> {
pub store: FFIFriendlyBlockStore<'a>,
forest: Rc<PrivateForest>,
root_dir: Rc<PrivateDirectory>,
rng: ThreadRng,
Expand All @@ -55,11 +55,11 @@ pub struct PrivateDirectoryHelper {
// Single root (private ref) implementation of the wnfs private directory using KVBlockStore.
// TODO: we assumed all the write, mkdirs use same roots here. this could be done using prepend
// a root path to all path segments.
impl<'a> PrivateDirectoryHelper {
impl<'a> PrivateDirectoryHelper<'a> {
async fn reload(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
cid: Cid,
) -> Result<PrivateDirectoryHelper, String> {
) -> Result<PrivateDirectoryHelper<'a>, String> {
let initialized: bool;
let wnfs_key: Vec<u8>;
unsafe {
Expand All @@ -84,9 +84,9 @@ impl<'a> PrivateDirectoryHelper {
}

async fn init(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
wnfs_key: Vec<u8>,
) -> Result<(PrivateDirectoryHelper, AccessKey, Cid), String> {
) -> Result<(PrivateDirectoryHelper<'a>, AccessKey, Cid), String> {
let rng = &mut thread_rng();
let ratchet_seed: [u8; 32];
let inumber: [u8; 32];
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'a> PrivateDirectoryHelper {
STATE.lock().unwrap().update(true, wnfs_key.to_owned());
}
Ok((
PrivateDirectoryHelper {
Self {
store: store.to_owned(),
forest: forest.to_owned(),
root_dir: root_dir.to_owned(),
Expand Down Expand Up @@ -168,10 +168,10 @@ impl<'a> PrivateDirectoryHelper {
}

pub async fn load_with_wnfs_key(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
forest_cid: Cid,
wnfs_key: Vec<u8>,
) -> Result<PrivateDirectoryHelper, String> {
) -> Result<PrivateDirectoryHelper<'a>, String> {
let rng = &mut thread_rng();
let ratchet_seed: [u8; 32];
let inumber: [u8; 32];
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'a> PrivateDirectoryHelper {
unsafe {
STATE.lock().unwrap().update(true, wnfs_key.to_owned());
}
Ok(PrivateDirectoryHelper {
Ok(Self {
store: store.to_owned(),
forest: forest.to_owned(),
root_dir: latest_root_dir.unwrap(),
Expand Down Expand Up @@ -234,10 +234,10 @@ impl<'a> PrivateDirectoryHelper {
}

pub async fn load_with_access_key(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
forest_cid: Cid,
access_key: AccessKey,
) -> Result<PrivateDirectoryHelper, String> {
) -> Result<PrivateDirectoryHelper<'a>, String> {
let rng = thread_rng();

let forest_res =
Expand All @@ -251,7 +251,7 @@ impl<'a> PrivateDirectoryHelper {
if root_dir.is_ok() {
let latest_root_dir = root_dir.unwrap().search_latest(forest, store).await;
if latest_root_dir.is_ok() {
Ok(PrivateDirectoryHelper {
Ok(Self {
store: store.to_owned(),
forest: forest.to_owned(),
root_dir: latest_root_dir.unwrap(),
Expand Down Expand Up @@ -286,7 +286,7 @@ impl<'a> PrivateDirectoryHelper {
}

async fn create_private_forest(
store: FFIFriendlyBlockStore,
store: FFIFriendlyBlockStore<'a>,
) -> Result<(Rc<PrivateForest>, Cid), String> {
// Create the private forest (a HAMT), a map-like structure where file and directory ciphertexts are stored.
let forest = Rc::new(PrivateForest::new());
Expand All @@ -305,7 +305,7 @@ impl<'a> PrivateDirectoryHelper {
}

async fn load_private_forest(
store: FFIFriendlyBlockStore,
store: FFIFriendlyBlockStore<'a>,
forest_cid: Cid,
) -> Result<Rc<PrivateForest>, String> {
// Deserialize private forest from the blockstore.
Expand All @@ -322,7 +322,7 @@ impl<'a> PrivateDirectoryHelper {
}

pub async fn update_private_forest(
store: FFIFriendlyBlockStore,
store: FFIFriendlyBlockStore<'a>,
forest: Rc<PrivateForest>,
) -> Result<Cid, String> {
// Serialize the private forest to DAG CBOR.
Expand Down Expand Up @@ -962,20 +962,20 @@ impl<'a> PrivateDirectoryHelper {
}

// Implement synced version of the library for using in android jni.
impl PrivateDirectoryHelper {
impl<'a> PrivateDirectoryHelper<'a> {
pub fn synced_init(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
wnfs_key: Vec<u8>,
) -> Result<(PrivateDirectoryHelper, AccessKey, Cid), String> {
) -> Result<(PrivateDirectoryHelper<'a>, AccessKey, Cid), String> {
let runtime = tokio::runtime::Runtime::new().expect("Unable to create a runtime");
return runtime.block_on(PrivateDirectoryHelper::init(store, wnfs_key));
}

pub fn synced_load_with_wnfs_key(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
forest_cid: Cid,
wnfs_key: Vec<u8>,
) -> Result<PrivateDirectoryHelper, String> {
) -> Result<PrivateDirectoryHelper<'a>, String> {
let runtime = tokio::runtime::Runtime::new().expect("Unable to create a runtime");
return runtime.block_on(PrivateDirectoryHelper::load_with_wnfs_key(
store, forest_cid, wnfs_key,
Expand All @@ -994,9 +994,9 @@ impl PrivateDirectoryHelper {
// }

pub fn synced_reload(
store: &mut FFIFriendlyBlockStore,
store: &mut FFIFriendlyBlockStore<'a>,
forest_cid: Cid,
) -> Result<PrivateDirectoryHelper, String> {
) -> Result<PrivateDirectoryHelper<'a>, String> {
let runtime = tokio::runtime::Runtime::new().expect("Unable to create a runtime");
return runtime.block_on(PrivateDirectoryHelper::reload(store, forest_cid));
}
Expand Down

0 comments on commit c95b0cb

Please sign in to comment.