use sectorsync_runtime::{
ReplicationReceiveBridge, ReplicationReceiveConfig, ReplicationReceiveError,
ReplicationReceivePump, ReplicationReceiveStats, ReplicationReceiveVisitError,
ReplicationReceiveVisitReport,
};
use sectorsync_transport::TransportReceiver;
use sectorsync_wire::ReplicationFrameRef;
#[derive(Clone, Debug)]
pub struct ReceiveExecutor {
bridge: ReplicationReceiveBridge,
}
impl ReceiveExecutor {
pub const fn new(config: ReplicationReceiveConfig) -> Self {
Self {
bridge: ReplicationReceiveBridge::new(config),
}
}
pub const fn stats(&self) -> ReplicationReceiveStats {
self.bridge.stats()
}
pub fn pump<T, F, V>(
&mut self,
transport: &mut T,
max_packets: usize,
visitor: F,
) -> Result<ReplicationReceiveVisitReport, ReplicationReceiveVisitError<T::Error, V>>
where
T: TransportReceiver,
F: for<'frame> FnMut(ReplicationFrameRef<'frame>) -> Result<(), V>,
{
self.bridge.pump(transport, max_packets, visitor)
}
pub fn pump_owned<T>(
&mut self,
transport: &mut T,
max_packets: usize,
) -> Result<ReplicationReceivePump, ReplicationReceiveError<T::Error>>
where
T: TransportReceiver,
{
self.bridge.pump_owned(transport, max_packets)
}
}
pub use sectorsync_runtime::ReplicationReceiveConfig as ReceiveExecutorConfig;