Skip to content

Commit

Permalink
Add workspace_refresh_list / workspace_inbound_sync / workspace_outbo…
Browse files Browse the repository at this point in the history
…und_sync monitors to client \o/
  • Loading branch information
touilleMan committed Jan 29, 2024
1 parent 783236a commit 43727e4
Show file tree
Hide file tree
Showing 12 changed files with 679 additions and 356 deletions.
7 changes: 6 additions & 1 deletion libparsec/crates/client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
event_bus::EventBus,
monitors::{
start_certif_poll_monitor, start_connection_monitor, start_user_sync_monitor,
start_workspaces_boostrap_monitor, Monitor,
start_workspaces_boostrap_monitor, start_workspaces_refresh_list_monitor, Monitor,
},
user::UserOps,
};
Expand Down Expand Up @@ -136,6 +136,10 @@ impl Client {
let workspaces_boostrap_monitor =
start_workspaces_boostrap_monitor(client.event_bus.clone(), client.clone()).await;

let workspaces_refresh_list_monitor =
start_workspaces_refresh_list_monitor(client.event_bus.clone(), client.clone())
.await;

let user_sync_monitor =
start_user_sync_monitor(client.user_ops.clone(), client.event_bus.clone()).await;

Expand All @@ -152,6 +156,7 @@ impl Client {

let mut monitors = client.monitors.lock().expect("Mutex is poisoned");
monitors.push(workspaces_boostrap_monitor);
monitors.push(workspaces_refresh_list_monitor);
monitors.push(user_sync_monitor);
monitors.push(certif_poll_monitor);
monitors.push(connection_monitor);
Expand Down
26 changes: 20 additions & 6 deletions libparsec/crates/client/src/client/workspace_refresh_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ pub async fn refresh_workspaces_list(client: &Client) -> Result<(), RefreshWorks

// 3) Cook the new list of workspaces from the certificates

for (workspace_id, self_role, role_certificate_timestamp) in self_realms_role {
for (workspace_id, self_role, role_certificate_timestamp) in &self_realms_role {
// Filter out user realm as it is not a workspace
if workspace_id == client.device.user_realm_id {
if *workspace_id == client.device.user_realm_id {
continue;
}

Expand All @@ -80,7 +80,7 @@ pub async fn refresh_workspaces_list(client: &Client) -> Result<(), RefreshWorks
// Retrieve the name of the workspace
let outcome = client
.certificates_ops
.decrypt_current_realm_name(workspace_id)
.decrypt_current_realm_name(*workspace_id)
.await;

let (name, name_origin) = match outcome {
Expand Down Expand Up @@ -116,12 +116,12 @@ pub async fn refresh_workspaces_list(client: &Client) -> Result<(), RefreshWorks
}?;

local_workspaces.push(LocalUserManifestWorkspaceEntry {
id: workspace_id,
id: *workspace_id,
name,
name_origin,
role: self_role,
role: *self_role,
role_origin: CertificateBasedInfoOrigin::Certificate {
timestamp: role_certificate_timestamp,
timestamp: *role_certificate_timestamp,
},
});
}
Expand Down Expand Up @@ -150,13 +150,27 @@ pub async fn refresh_workspaces_list(client: &Client) -> Result<(), RefreshWorks
}
}
// Workspace is not in the new list, so it is either:
// - A workspace we've lost access to.
// - A workspace we've just created (hence currently local-only).
// - The certificates database is lagging behind (e.g. it has been cleared
// because we switch from/to OUTSIDER role).
// In this case we can also pretend we have just created the workspace
// thank to the workspace bootstrap being idempotent (and we will
// eventually receive the certificates and hence correct the entry).
None => {
let no_longer_access = self_realms_role
.iter()
.find_map(|(wid, role, _)| {
if *wid == old_entry.id {
Some(role.is_none())
} else {
None
}
})
.unwrap_or(false);
if no_longer_access {
continue;
}
local_workspaces.push(LocalUserManifestWorkspaceEntry {
id: old_entry.id,
name: old_entry.name.clone(),
Expand Down
26 changes: 24 additions & 2 deletions libparsec/crates/client/src/client/workspace_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use libparsec_platform_async::lock::MutexGuard as AsyncMutexGuard;
use libparsec_types::prelude::*;

use super::Client;
use crate::WorkspaceOps;
use crate::{
monitors::{start_workspace_inbound_sync_monitor, start_workspace_outbound_sync_monitor},
WorkspaceOps,
};

#[derive(Debug, thiserror::Error)]
pub enum ClientStartWorkspaceError {
Expand Down Expand Up @@ -60,7 +63,26 @@ pub async fn start_workspace(
// 4) Finally start the monitors

if client.config.with_monitors {
// TODO
let inbound_sync_monitor =
start_workspace_inbound_sync_monitor(workspace_ops.clone(), client.event_bus.clone())
.await;
let outbound_sync_monitor = if entry.role.can_write() {
let outbound_sync_monitor = start_workspace_outbound_sync_monitor(
workspace_ops.clone(),
client.event_bus.clone(),
client.device.clone(),
)
.await;
Some(outbound_sync_monitor)
} else {
None
};

let mut monitors = client.monitors.lock().expect("Mutex is poisoned");
monitors.push(inbound_sync_monitor);
if let Some(outbound_sync_monitor) = outbound_sync_monitor {
monitors.push(outbound_sync_monitor);
}
}

Ok(workspace_ops)
Expand Down
137 changes: 0 additions & 137 deletions libparsec/crates/client/src/monitors/inbound_sync.rs

This file was deleted.

12 changes: 6 additions & 6 deletions libparsec/crates/client/src/monitors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ mod base;
mod certif_poll;
mod connection;
mod user_sync;
// mod inbound_sync;
// mod outbound_sync;
mod workspace_inbound_sync;
mod workspace_outbound_sync;
mod workspaces_bootstrap;
// mod workspaces;
mod workspaces_refresh_list;

pub(crate) use base::*;
pub(crate) use certif_poll::*;
pub(crate) use connection::*;
pub(crate) use user_sync::*;
// pub(crate) use inbound_sync::*;
// pub(crate) use outbound_sync::*;
pub(crate) use workspace_inbound_sync::*;
pub(crate) use workspace_outbound_sync::*;
pub(crate) use workspaces_bootstrap::*;
// pub(crate) use workspaces::*;
pub(crate) use workspaces_refresh_list::*;

#[cfg(test)]
#[path = "../../tests/unit/monitors/mod.rs"]
Expand Down
Loading

0 comments on commit 43727e4

Please sign in to comment.