use anyhow::Result;
use async_trait::async_trait;
use thiserror::Error;
use crate::bucket_log::BucketLogProvider;
use crate::linked_data::Link;
#[derive(Debug, Error)]
pub enum ProvenanceError {
#[error("invalid signature on manifest")]
InvalidSignature,
#[error("author not in manifest shares")]
AuthorNotInShares,
#[error("author does not have write permission")]
AuthorNotWriter,
#[error("invalid manifest in chain at {link}: {reason}")]
InvalidManifestInChain { link: Link, reason: String },
#[error("unauthorized share removal: only owners can remove shares")]
UnauthorizedShareRemoval,
#[error("{0}")]
Other(#[from] anyhow::Error),
}
pub mod download_pins;
pub mod ping_peer;
pub mod sync_bucket;
pub use download_pins::DownloadPinsJob;
pub use ping_peer::PingPeerJob;
pub use sync_bucket::{SyncBucketJob, SyncTarget};
#[derive(Debug, Clone)]
pub enum SyncJob {
SyncBucket(SyncBucketJob),
DownloadPins(DownloadPinsJob),
PingPeer(PingPeerJob),
}
pub async fn execute_job<L>(peer: &crate::peer::Peer<L>, job: SyncJob) -> Result<()>
where
L: BucketLogProvider + Clone + Send + Sync + 'static,
L::Error: std::error::Error + Send + Sync + 'static,
{
match job {
SyncJob::DownloadPins(job) => download_pins::execute(peer, job).await,
SyncJob::SyncBucket(job) => sync_bucket::execute(peer, job).await,
SyncJob::PingPeer(job) => ping_peer::execute(peer, job).await,
}
}
#[async_trait]
pub trait SyncProvider<L>: Send + Sync + std::fmt::Debug
where
L: BucketLogProvider + Clone + Send + Sync + 'static,
L::Error: std::error::Error + Send + Sync + 'static,
{
async fn execute(&self, peer: &crate::peer::Peer<L>, job: SyncJob) -> Result<()>;
}