Skip to content

Commit

Permalink
more chasing
Browse files Browse the repository at this point in the history
  • Loading branch information
jscatena88 committed Jul 3, 2024
1 parent 16d2ba7 commit a7c041e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/codec/meta/actor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use winnow::{binary::le_u8, token::take, Parser};
use crate::codec::{
crypto::{AccessKey, AsymLockedAccessKey, AsymLockedAccessKeyError, SigningKey, VerifyingKey},
header::AccessMask,
meta::{UserAgent, VectorClockActor, VectorClockActorSnapshot},
meta::{UserAgent, VectorClockActorSnapshot},
ParserResult, Stream,
};

Expand Down
18 changes: 13 additions & 5 deletions src/codec/meta/journal_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

use futures::io::AsyncWrite;

use crate::codec::meta::{Cid, VectorClockSnapshot};
use crate::codec::meta::{Cid, VectorClockFilesystemActorSnapshot};
use crate::codec::{ParserResult, Stream};

#[derive(Clone, Debug, PartialEq)]
pub struct JournalCheckpoint {
merkle_root_cid: Cid,
vector: VectorClockSnapshot,
vector: VectorClockFilesystemActorSnapshot,
}

impl JournalCheckpoint {
Expand All @@ -27,7 +27,7 @@ impl JournalCheckpoint {

pub fn parse(input: Stream) -> ParserResult<Self> {
let (input, merkle_root_cid) = Cid::parse(input)?;
let (input, vector) = VectorClockSnapshot::parse(input)?;
let (input, vector) = VectorClockFilesystemActorSnapshot::parse(input)?;

let journal_checkpoint = JournalCheckpoint {
merkle_root_cid,
Expand All @@ -38,14 +38,19 @@ impl JournalCheckpoint {
}

pub const fn size() -> usize {
Cid::size() + VectorClockSnapshot::size()
Cid::size() + VectorClockFilesystemActorSnapshot::size()
}
}

#[cfg(test)]
mod tests {
use winnow::Partial;

use crate::codec::{
crypto::Fingerprint, ActorId, VectorClockActor, VectorClockFilesystem,
VectorClockFilesystemSnapshot,
};

use super::*;

#[cfg(target_arch = "wasm32")]
Expand All @@ -56,7 +61,10 @@ mod tests {
async fn test_user_agent_roundtrip() {
let checkpoint = JournalCheckpoint {
merkle_root_cid: Cid::from([0; 32]),
vector: VectorClockSnapshot::from(0),
vector: VectorClockFilesystemActorSnapshot::from((
&VectorClockFilesystem::initialize(),
&VectorClockActor::initialize(ActorId::from(Fingerprint::from([0; 32]))),
)),
};

let mut buffer = Vec::with_capacity(JournalCheckpoint::size());
Expand Down
2 changes: 1 addition & 1 deletion src/codec/meta/vector_clock/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Actor {
Self::new(actor_id, ClockInner::initialize())
}

pub fn to_snapshot(&self) -> ActorSnapshot {
pub fn as_snapshot(&self) -> ActorSnapshot {
self.into()
}

Expand Down
6 changes: 3 additions & 3 deletions src/codec/meta/vector_clock/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Filesystem {
Self::new(ClockInner::initialize())
}

pub fn to_snapshot(&self) -> FilesystemSnapshot {
pub fn as_snapshot(&self) -> FilesystemSnapshot {
self.into()
}
}
Expand All @@ -34,11 +34,11 @@ pub struct FilesystemSnapshot {
}

impl FilesystemSnapshot {
fn new(clock: ClockInnerSnapshot) -> Self {
pub fn new(clock: ClockInnerSnapshot) -> Self {
Self { clock }
}

pub fn size() -> usize {
pub const fn size() -> usize {
ClockInnerSnapshot::size()
}

Expand Down
2 changes: 1 addition & 1 deletion src/codec/meta/vector_clock/filesystem_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl FilesystemActorSnapshot {
Self(filesystem, actor)
}

pub fn size() -> usize {
pub const fn size() -> usize {
FilesystemSnapshot::size() + ActorSnapshot::size()
}

Expand Down
7 changes: 5 additions & 2 deletions src/filesystem/drive/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use futures::io::AsyncWrite;
use crate::codec::{
crypto::{AccessKey, KeyId, SigningKey, VerifyingKey},
header::{AccessMask, AccessMaskBuilder, AccessMaskError},
meta::VectorClockActorSnapshot,
ActorId, ActorSettings, ActorSettingsError, ParserResult, Stream,
};

Expand Down Expand Up @@ -168,6 +169,7 @@ impl DriveAccess {
pub(crate) fn initialize(
rng: &mut impl CryptoRngCore,
verifying_key: VerifyingKey,
vector_clock_actor_snapshot: VectorClockActorSnapshot,
) -> Result<Self, DriveAccessError> {
let mut access = Self {
actor_settings: HashMap::new(),
Expand All @@ -182,7 +184,7 @@ impl DriveAccess {
.protected()
.build()?;

access.register_actor(rng, verifying_key, access_mask)?;
access.register_actor(rng, verifying_key, access_mask, vector_clock_actor_snapshot)?;

Ok(access)
}
Expand Down Expand Up @@ -291,6 +293,7 @@ impl DriveAccess {
rng: &mut impl CryptoRngCore,
key: VerifyingKey,
access_mask: AccessMask,
vector_clock_actor_snapshot: VectorClockActorSnapshot,
) -> Result<(), DriveAccessError> {
// todo(sstelfox): need to add a check that prevents a user from granting privileges beyond
// their own (they couldn't anyways as they don't have access to the symmetric keys
Expand All @@ -303,7 +306,7 @@ impl DriveAccess {
return Err(DriveAccessError::ActorAlreadyPresent);
}

let mut actor_settings = ActorSettings::new(key, access_mask);
let mut actor_settings = ActorSettings::new(key, access_mask, vector_clock_actor_snapshot);

if access_mask.has_data_key() {
let key = self
Expand Down
10 changes: 6 additions & 4 deletions src/filesystem/drive/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ impl InnerDrive {

pub fn vector_clock(&self) -> VectorClockFilesystemActorSnapshot {
VectorClockFilesystemActorSnapshot::new(
self.vector_clock_filesystem.to_snapshot(),
self.vector_clock_actor.to_snapshot(),
self.vector_clock_filesystem.as_snapshot(),
self.vector_clock_actor.as_snapshot(),
)
}
}
Expand All @@ -515,9 +515,11 @@ pub(crate) mod test {

let access = DriveAccess::initialize(&mut rng, verifying_key).unwrap();

let vector_clock_actor = VectorClockActor::initialize(actor_id);

(
actor_id,
InnerDrive::initialize(&mut rng, actor_id, access).unwrap(),
InnerDrive::initialize(&mut rng, actor_id, access, vector_clock_actor).unwrap(),
)
}

Expand Down Expand Up @@ -564,7 +566,7 @@ pub(crate) mod test {
let inner = build_interesting_inner(None).await;

let access = inner.access();
let vector_clock = inner.vector_clock.clone();
let vector_clock = inner.vector_clock();
let mut encoded = Vec::new();

let encoding_res = inner.encode(&mut encoded).await;
Expand Down
11 changes: 7 additions & 4 deletions src/filesystem/drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,25 @@ impl Drive {
pub fn initialize_private(
rng: &mut impl CryptoRngCore,
current_key: Arc<SigningKey>,
vector_clock_actor: VectorClockActor,
) -> Result<Self, DriveError> {
let filesystem_id = FilesystemId::generate(rng);
Self::initialize_private_with_id(rng, current_key, filesystem_id)
Self::initialize_private_with_id(rng, current_key, filesystem_id, vector_clock_actor)
}

pub fn initialize_private_with_id(
rng: &mut impl CryptoRngCore,
current_key: Arc<SigningKey>,
filesystem_id: FilesystemId,
vector_clock_actor: VectorClockActor,
) -> Result<Self, DriveError> {
let verifying_key = current_key.verifying_key();
let actor_id = verifying_key.actor_id();

trace!(?actor_id, ?filesystem_id, "drive::initializing_private");

let access = DriveAccess::initialize(rng, verifying_key)?;
let inner = InnerDrive::initialize(rng, actor_id, access)?;
let access = DriveAccess::initialize(rng, verifying_key, vector_clock_actor.as_snapshot())?;
let inner = InnerDrive::initialize(rng, actor_id, access, vector_clock_actor)?;

let drive = Self {
current_key,
Expand All @@ -197,9 +199,10 @@ impl Drive {
access_mask: AccessMask,
) -> Result<(), DriveAccessError> {
let mut inner_write = self.inner.write().await;
let vector_clock_snapshot = inner_write.vector_clock();
inner_write
.access_mut()
.register_actor(rng, key, access_mask)?;
.register_actor(rng, key, access_mask, vector_clock_snapshot)?;
Ok(())
}

Expand Down

0 comments on commit a7c041e

Please sign in to comment.