Skip to content

Commit

Permalink
Merge branch 'main' into vera/eng-617-banyan-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
PlamenHristov authored May 30, 2024
2 parents 45a232b + a9057f0 commit a95298e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
31 changes: 30 additions & 1 deletion src/filesystem/drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::codec::crypto::*;
use crate::codec::header::*;
use crate::codec::*;

use crate::filesystem::nodes::{Node, NodeBuilderError};
use crate::filesystem::nodes::{Node, NodeBuilderError, NodeName};

/// The core entry point of the library, a `Drive` is the means through which the BanyanFS
/// filesystem's public or private data is accessed. Initial creation of a new drive requires a
Expand Down Expand Up @@ -282,10 +282,39 @@ impl Drive {
Ok(root_cid)
}


pub async fn verifying_keys(&self) -> Vec<(VerifyingKey, AccessMask)> {
let inner = self.inner.read().await;
inner.access().verifying_keys()
}

pub async fn full_path_from_root(
&self,
target: &PermanentId,
) -> Result<Vec<String>, OperationError> {
let inner_read = &self.inner.read().await;
let target_node = inner_read
.by_perm_id(target)
.map_err(|_| OperationError::MissingPermanentId(*target))?;

let target_node_name = match target_node.name() {
NodeName::Root => return Ok(Vec::new()),
NodeName::Named(name) => name.to_string(),
};

let mut path = vec![target_node_name];
while let Some(parent_id) = target_node.parent_id() {
let parent_node = inner_read.by_perm_id(&parent_id)?;

match parent_node.name() {
NodeName::Root => break,
NodeName::Named(name) => path.push(name.to_string()),
}
}
path.reverse();

Ok(path)
}
}

#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 0 additions & 2 deletions src/filesystem/nodes/node_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ impl NodeData {
}

pub(crate) fn size(&self) -> u64 {
tracing::warn!("size of child entries are not yet included in parents");

match self {
NodeData::AssociatedData { content } => content.size(),
NodeData::Directory { .. } => {
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn calculate_cid(data: &[u8]) -> Cid {
///
/// Selection of RNG may change in the future which would affect this return type. Should generally
/// treat the returned type as an object implementing the `rand::CrytoRngCore` trait.
#[cfg(not(taget_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
pub fn crypto_rng() -> ChaCha20Rng {
ChaCha20Rng::from_entropy()
}
Expand All @@ -31,11 +31,11 @@ pub fn crypto_rng() -> ChaCha20Rng {
///
/// Selection of RNG may change in the future which would affect this return type. Should generally
/// treat the returned type as an object implementing the `rand::CrytoRngCore` trait.
#[cfg(taget_arch = "wasm32")]
#[cfg(target_arch = "wasm32")]
pub fn crypto_rng() -> ChaCha20Rng {
let mut seed = [0u8; 32];
getrandom::getrandom(&mut seed).expect();
Ok(ChaCha20Rng::from_seed(seed))
getrandom::getrandom(&mut seed).expect("getrandom being available");
ChaCha20Rng::from_seed(seed)
}

/// Helper utility to get the current time in milliseconds since the Unix epoch. This is the finest
Expand Down

0 comments on commit a95298e

Please sign in to comment.