From a7c041ee8b47ad67157b1b294bcb6e476f5ced88 Mon Sep 17 00:00:00 2001 From: Jason Scatena Date: Wed, 3 Jul 2024 12:12:06 -0400 Subject: [PATCH] more chasing --- src/codec/meta/actor_settings.rs | 2 +- src/codec/meta/journal_checkpoint.rs | 18 +++++++++++++----- src/codec/meta/vector_clock/actor.rs | 2 +- src/codec/meta/vector_clock/filesystem.rs | 6 +++--- .../meta/vector_clock/filesystem_actor.rs | 2 +- src/filesystem/drive/access.rs | 7 +++++-- src/filesystem/drive/inner.rs | 10 ++++++---- src/filesystem/drive/mod.rs | 11 +++++++---- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/codec/meta/actor_settings.rs b/src/codec/meta/actor_settings.rs index 49aa879..d727a92 100644 --- a/src/codec/meta/actor_settings.rs +++ b/src/codec/meta/actor_settings.rs @@ -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, }; diff --git a/src/codec/meta/journal_checkpoint.rs b/src/codec/meta/journal_checkpoint.rs index 893ad75..d4a924e 100644 --- a/src/codec/meta/journal_checkpoint.rs +++ b/src/codec/meta/journal_checkpoint.rs @@ -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 { @@ -27,7 +27,7 @@ impl JournalCheckpoint { pub fn parse(input: Stream) -> ParserResult { 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, @@ -38,7 +38,7 @@ impl JournalCheckpoint { } pub const fn size() -> usize { - Cid::size() + VectorClockSnapshot::size() + Cid::size() + VectorClockFilesystemActorSnapshot::size() } } @@ -46,6 +46,11 @@ impl JournalCheckpoint { mod tests { use winnow::Partial; + use crate::codec::{ + crypto::Fingerprint, ActorId, VectorClockActor, VectorClockFilesystem, + VectorClockFilesystemSnapshot, + }; + use super::*; #[cfg(target_arch = "wasm32")] @@ -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()); diff --git a/src/codec/meta/vector_clock/actor.rs b/src/codec/meta/vector_clock/actor.rs index fa1efc8..f121d20 100644 --- a/src/codec/meta/vector_clock/actor.rs +++ b/src/codec/meta/vector_clock/actor.rs @@ -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() } diff --git a/src/codec/meta/vector_clock/filesystem.rs b/src/codec/meta/vector_clock/filesystem.rs index e804abc..c11cce0 100644 --- a/src/codec/meta/vector_clock/filesystem.rs +++ b/src/codec/meta/vector_clock/filesystem.rs @@ -17,7 +17,7 @@ impl Filesystem { Self::new(ClockInner::initialize()) } - pub fn to_snapshot(&self) -> FilesystemSnapshot { + pub fn as_snapshot(&self) -> FilesystemSnapshot { self.into() } } @@ -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() } diff --git a/src/codec/meta/vector_clock/filesystem_actor.rs b/src/codec/meta/vector_clock/filesystem_actor.rs index 7d4bed2..70f8308 100644 --- a/src/codec/meta/vector_clock/filesystem_actor.rs +++ b/src/codec/meta/vector_clock/filesystem_actor.rs @@ -11,7 +11,7 @@ impl FilesystemActorSnapshot { Self(filesystem, actor) } - pub fn size() -> usize { + pub const fn size() -> usize { FilesystemSnapshot::size() + ActorSnapshot::size() } diff --git a/src/filesystem/drive/access.rs b/src/filesystem/drive/access.rs index dc0b656..953044b 100644 --- a/src/filesystem/drive/access.rs +++ b/src/filesystem/drive/access.rs @@ -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, }; @@ -168,6 +169,7 @@ impl DriveAccess { pub(crate) fn initialize( rng: &mut impl CryptoRngCore, verifying_key: VerifyingKey, + vector_clock_actor_snapshot: VectorClockActorSnapshot, ) -> Result { let mut access = Self { actor_settings: HashMap::new(), @@ -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) } @@ -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 @@ -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 diff --git a/src/filesystem/drive/inner.rs b/src/filesystem/drive/inner.rs index 86b26e5..eb97640 100644 --- a/src/filesystem/drive/inner.rs +++ b/src/filesystem/drive/inner.rs @@ -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(), ) } } @@ -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(), ) } @@ -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; diff --git a/src/filesystem/drive/mod.rs b/src/filesystem/drive/mod.rs index 38e53d6..a5600df 100644 --- a/src/filesystem/drive/mod.rs +++ b/src/filesystem/drive/mod.rs @@ -160,23 +160,25 @@ impl Drive { pub fn initialize_private( rng: &mut impl CryptoRngCore, current_key: Arc, + vector_clock_actor: VectorClockActor, ) -> Result { 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, filesystem_id: FilesystemId, + vector_clock_actor: VectorClockActor, ) -> Result { 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, @@ -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(()) }