Skip to content

Commit

Permalink
getting there with chasing types through
Browse files Browse the repository at this point in the history
  • Loading branch information
jscatena88 committed Jul 3, 2024
1 parent ead29dd commit 16d2ba7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
18 changes: 10 additions & 8 deletions src/codec/meta/actor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ use crate::codec::{
ParserResult, Stream,
};

use super::ActorId;

const KEY_PRESENT_BIT: u8 = 0b0000_0001;

#[derive(Clone, Debug)]
pub struct ActorSettings {
verifying_key: VerifyingKey,
vector_clock: VectorClockActor,
vector_clock: VectorClockActorSnapshot,

access_mask: AccessMask,
filesystem_key: Option<AsymLockedAccessKey>,
Expand Down Expand Up @@ -80,7 +78,7 @@ impl ActorSettings {
let mut written_bytes = 0;

written_bytes += self.verifying_key.encode(writer).await?;
written_bytes += self.vector_clock.to_snapshot().encode(writer).await?;
written_bytes += self.vector_clock.encode(writer).await?;
written_bytes += self.access_mask.encode(writer).await?;
written_bytes += self.user_agent().encode(writer).await?;

Expand Down Expand Up @@ -176,8 +174,12 @@ impl ActorSettings {
Ok(Some(open_key))
}

pub fn new(verifying_key: VerifyingKey, access_mask: AccessMask, actor_id: ActorId) -> Self {
let vector_clock = VectorClockActor::initialize(actor_id);
pub fn new(
verifying_key: VerifyingKey,
access_mask: AccessMask,
vector_clock: VectorClockActorSnapshot,
) -> Self {
// Should we test that the actor id associated with the verifying key matches the actor id of the vector clock?
let user_agent = UserAgent::current();

Self {
Expand All @@ -195,7 +197,7 @@ impl ActorSettings {

pub fn parse(input: Stream) -> ParserResult<Self> {
let (input, verifying_key) = VerifyingKey::parse(input)?;
let (input, vector_clock) = VectorClockActor::parse(input)?;
let (input, vector_clock) = VectorClockActorSnapshot::parse(input)?;
let (input, access_mask) = AccessMask::parse(input)?;
let (input, user_agent) = UserAgent::parse(input)?;

Expand Down Expand Up @@ -235,7 +237,7 @@ impl ActorSettings {
}

pub fn vector_clock(&self) -> VectorClockActorSnapshot {
(&self.vector_clock).into()
self.vector_clock
}

pub fn verifying_key(&self) -> VerifyingKey {
Expand Down
6 changes: 6 additions & 0 deletions src/codec/meta/vector_clock/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ impl Actor {
}
}

impl From<ActorSnapshot> for Actor {
fn from(value: ActorSnapshot) -> Self {
Self::new(value.id, value.clock.into())
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct ActorSnapshot {
id: ActorId,
Expand Down
10 changes: 10 additions & 0 deletions src/codec/meta/vector_clock/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ impl Filesystem {
pub fn initialize() -> Self {
Self::new(ClockInner::initialize())
}

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

impl From<FilesystemSnapshot> for Filesystem {
fn from(value: FilesystemSnapshot) -> Self {
Self::new(value.clock.into())
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down
6 changes: 5 additions & 1 deletion src/codec/meta/vector_clock/filesystem_actor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{actor::ActorSnapshot, filesystem::FilesystemSnapshot};
use super::{actor::ActorSnapshot, filesystem::FilesystemSnapshot, Actor, Filesystem};
use crate::codec::{ParserResult, Stream};

use futures::AsyncWrite;
Expand All @@ -15,6 +15,10 @@ impl FilesystemActorSnapshot {
FilesystemSnapshot::size() + ActorSnapshot::size()
}

pub fn reanimate(self) -> (Filesystem, Actor) {
(Filesystem::from(self.0), Actor::from(self.1))
}

pub async fn encode<W: AsyncWrite + Unpin + Send>(
&self,
writer: &mut W,
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/drive/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl DriveAccess {
return Err(DriveAccessError::ActorAlreadyPresent);
}

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

if access_mask.has_data_key() {
let key = self
Expand Down
24 changes: 16 additions & 8 deletions src/filesystem/drive/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub(crate) struct InnerDrive {
/// This is the filesystem-wide vector clock used for tracking what permanent IDs are present
/// within the filesystem as well as access control related changes. Changes to individual
/// node's or their entry specific data should make use of the [`Node`]'s vector clock instead.
vector_clock: VectorClockFilesystem,
vector_clock_filesystem: VectorClockFilesystem,
vector_clock_actor: VectorClockActor,
root_pid: PermanentId,

nodes: Slab<Node>,
Expand Down Expand Up @@ -312,8 +313,9 @@ impl InnerDrive {
rng: &mut impl CryptoRngCore,
actor_id: ActorId,
access: DriveAccess,
vector_clock_actor: VectorClockActor,
) -> Result<Self, OperationError> {
let vector_clock = VectorClockFilesystem::initialize();
let vector_clock_filesystem = VectorClockFilesystem::initialize();

let mut nodes = Slab::with_capacity(32);
let mut permanent_id_map = HashMap::new();
Expand All @@ -332,8 +334,8 @@ impl InnerDrive {

let inner = Self {
access,
vector_clock,

vector_clock_filesystem,
vector_clock_actor,
nodes,
root_pid,
permanent_id_map,
Expand Down Expand Up @@ -361,10 +363,12 @@ impl InnerDrive {
pub(crate) fn parse(
input: Stream<'_>,
drive_access: DriveAccess,
vector_clock: VectorClockFilesystem,
vector_clocks: VectorClockFilesystemActorSnapshot,
) -> ParserResult<'_, Self> {
tracing::trace!(available_data = ?input.len(), "inner_drive::parse");

let (vector_clock_filesystem, vector_clock_actor) = vector_clocks.reanimate();

let (remaining, root_pid) = PermanentId::parse(input)?;
let bytes_read = input.len() - remaining.len();

Expand Down Expand Up @@ -420,7 +424,8 @@ impl InnerDrive {

let inner_drive = InnerDrive {
access: drive_access,
vector_clock,
vector_clock_actor,
vector_clock_filesystem,
root_pid,
nodes,
permanent_id_map,
Expand Down Expand Up @@ -485,8 +490,11 @@ impl InnerDrive {
self.root_pid
}

pub fn vector_clock(&self) -> VectorClockFilesystemSnapshot {
VectorClockFilesystemSnapshot::from(&self.vector_clock)
pub fn vector_clock(&self) -> VectorClockFilesystemActorSnapshot {
VectorClockFilesystemActorSnapshot::new(
self.vector_clock_filesystem.to_snapshot(),
self.vector_clock_actor.to_snapshot(),
)
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/filesystem/drive/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::codec::parser::{
ParserResult, ParserStateMachine, ProgressType, SegmentStreamer, StateError, StateResult,
};
use crate::codec::Stream;
use crate::filesystem::drive::VectorClock;
use crate::filesystem::drive::VectorClockFilesystemActorSnapshot;
use crate::filesystem::{Drive, DriveAccess, InnerDrive};

pub struct DriveLoader<'a> {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl ParserStateMachine<Drive> for DriveLoader<'_> {
DriveLoaderState::EncryptedHeader(key_count, meta_key) => {
let payload_size = (**key_count as usize * DriveAccess::size())
+ ContentOptions::size()
+ VectorClock::size();
+ VectorClockFilesystemActorSnapshot::size();

let (input, header_buffer) =
EncryptedBuffer::parse_and_decrypt(buffer, payload_size, &[], meta_key)?;
Expand All @@ -168,7 +168,8 @@ impl ParserStateMachine<Drive> for DriveLoader<'_> {
let (hdr_stream, content_options) = ContentOptions::parse(hdr_stream)?;
trace!("drive_loader::encrypted_header::content_options");

let (hdr_stream, vector_clock) = VectorClock::parse(hdr_stream)?;
let (hdr_stream, vector_clock) =
VectorClockFilesystemActorSnapshot::parse(hdr_stream)?;
trace!("drive_loader::encrypted_header::vector_clock");

debug_assert!(hdr_stream.is_empty());
Expand Down Expand Up @@ -325,7 +326,7 @@ enum DriveLoaderState {

EscrowedAccessKeys(KeyCount),
EncryptedHeader(KeyCount, MetaKey),
PrivateContent(ContentOptions, VectorClock),
PrivateContent(ContentOptions, VectorClockFilesystemActorSnapshot),
//PublicPermissions(KeyCount),
//PublicContent,

Expand Down

0 comments on commit 16d2ba7

Please sign in to comment.