pub struct Gossip { /* private fields */ }
net
only.Expand description
Publish and subscribe on gossiping topics.
Each topic is a separate broadcast tree with separate memberships.
A topic has to be joined before you can publish or subscribe on the topic.
To join the swarm for a topic, you have to know the [PublicKey
] of at least one peer that also joined the topic.
Messages published on the swarm will be delivered to all peers that joined the swarm for that topic. You will also be relaying (gossiping) messages published by other peers.
With the default settings, the protocol will maintain up to 5 peer connections per topic.
Even though the Gossip
is created from a [Endpoint
], it does not accept connections
itself. You should run an accept loop on the [Endpoint
] yourself, check the ALPN protocol of incoming
connections, and if the ALPN protocol equals GOSSIP_ALPN
, forward the connection to the
gossip actor through Self::handle_connection.
The gossip actor will, however, initiate new connections to other peers by itself.
Implementations§
Source§impl Gossip
impl Gossip
Sourcepub async fn listen(self, endpoint: Endpoint)
Available on crate feature rpc
only.
pub async fn listen(self, endpoint: Endpoint)
rpc
only.Listen on a quinn endpoint for incoming RPC connections.
Sourcepub fn max_message_size(&self) -> usize
pub fn max_message_size(&self) -> usize
Get the maximum message size configured for this gossip actor.
Sourcepub async fn handle_connection(&self, conn: Connection) -> Result<(), Error>
pub async fn handle_connection(&self, conn: Connection) -> Result<(), Error>
Handle an incoming [Connection
].
Make sure to check the ALPN protocol yourself before passing the connection.
Methods from Deref<Target = GossipApi>§
Sourcepub async fn subscribe_with_opts(
&self,
topic_id: TopicId,
opts: JoinOptions,
) -> Result<GossipTopic, ApiError>
Available on crate features net
or rpc
only.
pub async fn subscribe_with_opts( &self, topic_id: TopicId, opts: JoinOptions, ) -> Result<GossipTopic, ApiError>
net
or rpc
only.Join a gossip topic with options.
Returns a GossipTopic
instantly. To wait for at least one connection to be established,
you can await GossipTopic::joined
.
Messages will be queued until a first connection is available. If the internal channel becomes full, the oldest messages will be dropped from the channel.
Sourcepub async fn subscribe_and_join(
&self,
topic_id: TopicId,
bootstrap: Vec<NodeId>,
) -> Result<GossipTopic, ApiError>
Available on crate features net
or rpc
only.
pub async fn subscribe_and_join( &self, topic_id: TopicId, bootstrap: Vec<NodeId>, ) -> Result<GossipTopic, ApiError>
net
or rpc
only.Join a gossip topic with the default options and wait for at least one active connection.
Sourcepub async fn subscribe(
&self,
topic_id: TopicId,
bootstrap: Vec<NodeId>,
) -> Result<GossipTopic, ApiError>
Available on crate features net
or rpc
only.
pub async fn subscribe( &self, topic_id: TopicId, bootstrap: Vec<NodeId>, ) -> Result<GossipTopic, ApiError>
net
or rpc
only.Join a gossip topic with the default options.
Note that this will not wait for any bootstrap node to be available.
To ensure the topic is connected to at least one node, use GossipTopic::joined
or Self::subscribe_and_join