pub struct TopicChannel<T: SignedGossipMessage + Send + Sync> { /* private fields */ }Expand description
A typed gossip topic that can publish and subscribe to one message type.
Uses Gossip (syncweb’s wrapper around iroh_gossip::net::Gossip) for
lifecycle management. TopicChannel only handles publish and
per-subscription stream filtering — the underlying gossip connection,
subscription, and peer bootstrap are managed by GossipService.
Implementations§
Source§impl<T: SignedGossipMessage + Send + Sync> TopicChannel<T>
impl<T: SignedGossipMessage + Send + Sync> TopicChannel<T>
Sourcepub fn new(gossip: Arc<Gossip>, topic_name: &[u8], sender: GossipSender) -> Self
pub fn new(gossip: Arc<Gossip>, topic_name: &[u8], sender: GossipSender) -> Self
Create a deterministic topic ID from a byte-string topic name, and store a sender for publishing.
Sourcepub async fn publish(&self, message: &T) -> Result<()>
pub async fn publish(&self, message: &T) -> Result<()>
Publish a signed message to the topic. All subscribers receive it.
§Errors
Returns an error if signature verification or broadcasting fails.
Sourcepub fn receive_from(
&self,
stream: impl Stream<Item = Result<Event, ApiError>> + Send + 'static,
) -> impl Stream<Item = T> + Send
pub fn receive_from( &self, stream: impl Stream<Item = Result<Event, ApiError>> + Send + 'static, ) -> impl Stream<Item = T> + Send
Receive verified messages from an already-subscribed gossip event stream.
The caller must already have subscribed to self.topic_id via
GossipService. This method wraps the raw event stream with
deserialization and signature verification.
Returns a stream of verified, deserialized T messages. Messages that
fail deserialization or signature verification are silently dropped
(logged at debug level).
Sourcepub async fn collect_for(
&self,
stream: impl Stream<Item = Result<Event, ApiError>> + Send + 'static,
filter: impl Fn(&T) -> bool + Send + Sync + 'static,
timeout_duration: Duration,
) -> Result<Vec<T>>
pub async fn collect_for( &self, stream: impl Stream<Item = Result<Event, ApiError>> + Send + 'static, filter: impl Fn(&T) -> bool + Send + Sync + 'static, timeout_duration: Duration, ) -> Result<Vec<T>>
Collect messages matching a filter within a timeout.
The caller must already be subscribed to the topic via GossipService.
stream is the raw gossip event stream from the subscription.
§Errors
Returns an empty vector on timeout (not an error).
pub const fn topic_id(&self) -> TopicId
pub fn gossip(&self) -> &Gossip
Auto Trait Implementations§
impl<T> !RefUnwindSafe for TopicChannel<T>
impl<T> !UnwindSafe for TopicChannel<T>
impl<T> Freeze for TopicChannel<T>
impl<T> Send for TopicChannel<T>
impl<T> Sync for TopicChannel<T>
impl<T> Unpin for TopicChannel<T>where
T: Unpin,
impl<T> UnsafeUnpin for TopicChannel<T>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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