Skip to main content

coven_sync/
sequence_cut_off.rs

1//! The person's word that a lost owner device is cut off (§14.2, §20.9).
2
3use super::{SequenceSync, Session};
4use crate::{PendingRecord, SyncError};
5use coven_foundation::id_source::DeviceId;
6use coven_storage::StorageFailure;
7
8impl SequenceSync {
9    /// The person did the provider step for `device`, a lost device of the
10    /// owner's (§14.2): nothing it sent can land any more. Every account its
11    /// invite shares named that nothing intends now is taken back by a
12    /// request of its own, which runs after this call and so after anything
13    /// the device's grants did: its grant may have landed after this device's
14    /// earlier revocation of the account. An account a member or an open
15    /// invite uses stays shared.
16    ///
17    /// Refused with `CutOffRefused`, naming why: `NoAccountShared` on S3,
18    /// `NotStoreOwner` unless this device's member holds the store's account,
19    /// and `DeviceNotGone` unless the applied history has `device` gone for
20    /// good, which the next pass may bring. Fails with `ProviderRequestRunning`, changing
21    /// nothing, while a request to one of those accounts runs; the call is
22    /// made again once it ends.
23    pub async fn confirm_device_cut_off(&self, device: DeviceId) -> Result<(), SyncError> {
24        let mut session = self.session.lock().await;
25        let member = self.member.read()?.ok_or(StorageFailure::MemberKeysMissing)?;
26        let mut ring = self.ring(&mut session, &member).await?;
27        self.read_forward(&mut session, &mut ring, &member).await?;
28        self.settle_open(&mut session, &mut ring, &member).await?;
29        self.retake_accounts(&session, member.member(), device).await
30    }
31
32    /// Whether this device's member reaches storage through the account that
33    /// holds the store (§20.9): only their devices share it and take sharing
34    /// back, so only they can confirm a device cut off. Reads the sequence
35    /// forward first, so it answers for the history as it stands.
36    pub async fn holds_store(&self) -> Result<bool, SyncError> {
37        let mut session = self.session.lock().await;
38        let member = self.member.read()?.ok_or(StorageFailure::MemberKeysMissing)?;
39        let mut ring = self.ring(&mut session, &member).await?;
40        self.read_forward(&mut session, &mut ring, &member).await?;
41        Ok(session.history.holds_store(member.member()))
42    }
43
44    async fn retake_accounts(
45        &self,
46        session: &Session,
47        member: coven_foundation::id_source::MemberId,
48        device: DeviceId,
49    ) -> Result<(), SyncError> {
50        let changes = session.history.cut_off_retakes(member, device)?;
51        Ok(self.database.retake_provider_access::<PendingRecord>(changes).await?)
52    }
53}
54
55#[cfg(test)]
56#[path = "sequence_cut_off_tests.rs"]
57mod tests;