pub struct GossipModelSync { /* private fields */ }Expand description
GossipSub-based model synchronisation protocol.
Broadcasts ModelUpdate announcements via a shared in-process channel so
that tests can exercise the full send/receive/verify loop without a live
libp2p swarm.
Implementations§
Source§impl GossipModelSync
impl GossipModelSync
Sourcepub fn new(local_peer_id: impl Into<String>) -> Self
pub fn new(local_peer_id: impl Into<String>) -> Self
Create a new GossipModelSync backed by a broadcast channel of capacity 64.
Sourcepub fn subscribe(&self, peer_id: impl Into<String>) -> Self
pub fn subscribe(&self, peer_id: impl Into<String>) -> Self
Create a second endpoint subscribed to the same broadcast channel (for tests).
Sourcepub async fn broadcast_update(
&self,
model_cid: &str,
round_id: u32,
) -> Result<()>
pub async fn broadcast_update( &self, model_cid: &str, round_id: u32, ) -> Result<()>
Broadcast a local model-update CID to all mesh peers.
Sourcepub async fn collect_updates(
&mut self,
expected_peers: usize,
timeout_ms: u64,
) -> Result<Vec<ModelUpdate>>
pub async fn collect_updates( &mut self, expected_peers: usize, timeout_ms: u64, ) -> Result<Vec<ModelUpdate>>
Collect model-update CIDs from peers for up to timeout_ms milliseconds.
Returns as soon as expected_peers distinct peer updates are received or
the timeout expires.
Sourcepub fn verify_update(&self, update: &ModelUpdate) -> bool
pub fn verify_update(&self, update: &ModelUpdate) -> bool
Verify that a ModelUpdate has not been tampered with.
The current implementation checks that model_cid is a non-empty, valid
CIDv1 or CIDv0 string and that peer_id is non-empty. Tampered updates
with an empty or whitespace-only CID fail verification.
Auto Trait Implementations§
impl !RefUnwindSafe for GossipModelSync
impl !UnwindSafe for GossipModelSync
impl Freeze for GossipModelSync
impl Send for GossipModelSync
impl Sync for GossipModelSync
impl Unpin for GossipModelSync
impl UnsafeUnpin for GossipModelSync
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more