aranya_runtime/sync/
mod.rsuse aranya_buggy::Bug;
use postcard::Error as PostcardError;
use serde::{Deserialize, Serialize};
use crate::{
command::{Command, CommandId, Priority},
storage::{StorageError, MAX_COMMAND_LENGTH},
Address, Prior,
};
mod requester;
mod responder;
pub use requester::SyncRequester;
pub use responder::{PeerCache, SyncResponder};
pub const PEER_HEAD_MAX: usize = 10;
const COMMAND_SAMPLE_MAX: usize = 100;
const REQUEST_MISSING_MAX: usize = 100;
pub const COMMAND_RESPONSE_MAX: usize = 100;
const SEGMENT_BUFFER_MAX: usize = 100;
pub const MAX_SYNC_MESSAGE_SIZE: usize = 1024 + MAX_COMMAND_LENGTH * COMMAND_RESPONSE_MAX;
#[derive(Serialize, Deserialize, Debug)]
pub struct CommandMeta {
id: CommandId,
priority: Priority,
parent: Prior<Address>,
policy_length: u32,
length: u32,
max_cut: usize,
}
#[derive(Debug, thiserror::Error)]
pub enum SyncError {
#[error("sync session ID does not match")]
SessionMismatch,
#[error("missing sync response")]
MissingSyncResponse,
#[error("syncer state not valid for this message")]
SessionState,
#[error("syncer not ready for operation")]
NotReady,
#[error("too many commands sent")]
CommandOverflow,
#[error("storage error: {0}")]
Storage(#[from] StorageError),
#[error("serialize error: {0}")]
Serialize(#[from] PostcardError),
#[error(transparent)]
Bug(#[from] Bug),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SyncCommand<'a> {
priority: Priority,
id: CommandId,
parent: Prior<Address>,
policy: Option<&'a [u8]>,
data: &'a [u8],
max_cut: usize,
}
impl<'a> Command for SyncCommand<'a> {
fn priority(&self) -> Priority {
self.priority.clone()
}
fn id(&self) -> CommandId {
self.id
}
fn parent(&self) -> Prior<Address> {
self.parent
}
fn policy(&self) -> Option<&'a [u8]> {
self.policy
}
fn bytes(&self) -> &'a [u8] {
self.data
}
fn max_cut(&self) -> Result<usize, Bug> {
Ok(self.max_cut)
}
}