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 fn max_message_size(&self) -> usize
pub fn max_message_size(&self) -> usize
Returns 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>
Handles an incoming [Connection
].
Make sure to check the ALPN protocol yourself before passing the connection.
Sourcepub async fn subscribe_and_join(
&self,
topic_id: TopicId,
bootstrap: Vec<NodeId>,
) -> Result<GossipTopic, Error>
pub async fn subscribe_and_join( &self, topic_id: TopicId, bootstrap: Vec<NodeId>, ) -> Result<GossipTopic, Error>
Joins a gossip topic with the default options and waits for at least one active connection to be established.
Sourcepub fn subscribe(
&self,
topic_id: TopicId,
bootstrap: Vec<NodeId>,
) -> Result<GossipTopic, Error>
pub fn subscribe( &self, topic_id: TopicId, bootstrap: Vec<NodeId>, ) -> Result<GossipTopic, Error>
Joins 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 Gossip::subscribe_and_join
Sourcepub fn subscribe_with_opts(
&self,
topic_id: TopicId,
opts: JoinOptions,
) -> GossipTopic
pub fn subscribe_with_opts( &self, topic_id: TopicId, opts: JoinOptions, ) -> GossipTopic
Joins 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 fn subscribe_with_stream(
&self,
topic_id: TopicId,
options: JoinOptions,
updates: CommandStream,
) -> EventStream
pub fn subscribe_with_stream( &self, topic_id: TopicId, options: JoinOptions, updates: CommandStream, ) -> EventStream
Joins a gossip topic with options and an externally-created update stream.
This method differs from Self::subscribe_with_opts
by letting you pass in a updates
command stream yourself
instead of using a channel created for you.
It returns a stream of events. If you want to wait for the topic to become active, wait for
the first GossipEvent::NeighborUp
.
Source§impl Gossip
impl Gossip
Sourcepub fn client(&self) -> &Client<FlumeConnector<Response, Request>>
Available on crate feature rpc
only.
pub fn client(&self) -> &Client<FlumeConnector<Response, Request>>
rpc
only.Get an in-memory gossip client
Sourcepub async fn handle_rpc_request<C: ChannelTypes<RpcService>>(
self,
msg: Request,
chan: RpcChannel<RpcService, C>,
) -> Result<(), RpcServerError<C>>
Available on crate feature rpc
only.
pub async fn handle_rpc_request<C: ChannelTypes<RpcService>>( self, msg: Request, chan: RpcChannel<RpcService, C>, ) -> Result<(), RpcServerError<C>>
rpc
only.Handle a gossip request from the RPC server.