common/peer/jax_protocol/
state.rs

1use async_trait::async_trait;
2use uuid::Uuid;
3
4use crate::linked_data::Link;
5
6use super::messages::SyncStatus;
7
8/// Trait for providing bucket state information to the JAX protocol handler
9///
10/// This trait abstracts away the storage layer (database + blobs) so that
11/// the protocol handler in `common` can query bucket state without depending
12/// on the `service` crate.
13#[async_trait]
14pub trait BucketStateProvider: Send + Sync + std::fmt::Debug {
15    /// Check the sync status of a bucket given a target link
16    ///
17    /// This compares the target_link against the current state of the bucket:
18    /// - NotFound: The bucket doesn't exist
19    /// - InSync: The target_link matches the current bucket link
20    /// - Behind: The target_link is in the bucket's history (older version)
21    /// - Unsynced: The target_link is not in the bucket's history (different branch or newer)
22    async fn check_bucket_sync(
23        &self,
24        bucket_id: Uuid,
25        target_link: &Link,
26    ) -> Result<SyncStatus, anyhow::Error>;
27
28    /// Get the current link for a bucket
29    ///
30    /// Returns None if the bucket doesn't exist
31    async fn get_bucket_link(&self, bucket_id: Uuid) -> Result<Option<Link>, anyhow::Error>;
32
33    /// Handle an incoming announce message from a peer
34    ///
35    /// This should trigger a sync event to process the announced update
36    async fn handle_announce(
37        &self,
38        bucket_id: Uuid,
39        peer_id: String,
40        new_link: Link,
41        previous_link: Option<Link>,
42    ) -> Result<(), anyhow::Error>;
43}