Struct iroh_gossip::net::Gossip
source · 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 from_endpoint(
endpoint: Endpoint,
config: Config,
my_addr: &AddrInfo
) -> Self
pub fn from_endpoint( endpoint: Endpoint, config: Config, my_addr: &AddrInfo ) -> Self
Spawn a gossip actor and get a handle for it
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<()>
pub async fn handle_connection(&self, conn: Connection) -> Result<()>
Handle an incoming [Connection
].
Make sure to check the ALPN protocol yourself before passing the connection.
sourcepub async fn join(
&self,
topic_id: TopicId,
bootstrap: Vec<NodeId>
) -> Result<GossipTopic>
pub async fn join( &self, topic_id: TopicId, bootstrap: Vec<NodeId> ) -> Result<GossipTopic>
Join a gossip topic with the default options and wait for at least one active connection.
sourcepub fn join_with_opts(
&self,
topic_id: TopicId,
opts: JoinOptions
) -> GossipTopic
pub fn join_with_opts( &self, topic_id: TopicId, opts: JoinOptions ) -> GossipTopic
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 fn join_with_stream(
&self,
topic_id: TopicId,
options: JoinOptions,
updates: CommandStream
) -> impl Stream<Item = Result<Event>> + Send + 'static
pub fn join_with_stream( &self, topic_id: TopicId, options: JoinOptions, updates: CommandStream ) -> impl Stream<Item = Result<Event>> + Send + 'static
Join a gossip topic with options and an externally-created update stream.
This method differs from Self::join_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 GossipEvent::Joined
event.
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.