1use anyhow::Result;
7use async_trait::async_trait;
8use thiserror::Error;
9
10use crate::bucket_log::BucketLogProvider;
11use crate::linked_data::Link;
12
13#[derive(Debug, Error)]
15pub enum ProvenanceError {
16 #[error("invalid signature on manifest")]
17 InvalidSignature,
18 #[error("author not in manifest shares")]
19 AuthorNotInShares,
20 #[error("author does not have write permission")]
21 AuthorNotWriter,
22 #[error("invalid manifest in chain at {link}: {reason}")]
23 InvalidManifestInChain { link: Link, reason: String },
24 #[error("unauthorized share removal: only owners can remove shares")]
25 UnauthorizedShareRemoval,
26 #[error("{0}")]
27 Other(#[from] anyhow::Error),
28}
29
30pub mod download_pins;
31pub mod ping_peer;
32pub mod sync_bucket;
33
34pub use download_pins::DownloadPinsJob;
36pub use ping_peer::PingPeerJob;
37pub use sync_bucket::{SyncBucketJob, SyncTarget};
38
39#[derive(Debug, Clone)]
43pub enum SyncJob {
44 SyncBucket(SyncBucketJob),
46 DownloadPins(DownloadPinsJob),
48 PingPeer(PingPeerJob),
50}
51
52pub async fn execute_job<L>(peer: &crate::peer::Peer<L>, job: SyncJob) -> Result<()>
57where
58 L: BucketLogProvider + Clone + Send + Sync + 'static,
59 L::Error: std::error::Error + Send + Sync + 'static,
60{
61 match job {
62 SyncJob::DownloadPins(job) => download_pins::execute(peer, job).await,
63 SyncJob::SyncBucket(job) => sync_bucket::execute(peer, job).await,
64 SyncJob::PingPeer(job) => ping_peer::execute(peer, job).await,
65 }
66}
67
68#[async_trait]
81pub trait SyncProvider<L>: Send + Sync + std::fmt::Debug
82where
83 L: BucketLogProvider + Clone + Send + Sync + 'static,
84 L::Error: std::error::Error + Send + Sync + 'static,
85{
86 async fn execute(&self, peer: &crate::peer::Peer<L>, job: SyncJob) -> Result<()>;
91}