Struct iroh_gossip::net::Gossip

source ·
pub struct Gossip { /* private fields */ }
Available on crate feature 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

source

pub fn from_endpoint( endpoint: Endpoint, config: Config, my_addr: &AddrInfo ) -> Self

Spawn a gossip actor and get a handle for it

source

pub fn max_message_size(&self) -> usize

Get the maximum message size configured for this gossip actor.

source

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.

source

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.

source

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.

source

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

source

pub fn client(&self) -> &Client<FlumeConnector<Response, Request>>

Available on crate feature rpc only.

Get an in-memory gossip client

source

pub async fn handle_rpc_request<C: ChannelTypes<RpcService>>( self, msg: Request, chan: RpcChannel<RpcService, C> ) -> Result<(), RpcServerError<C>>

Available on crate feature rpc only.

Handle a gossip request from the RPC server.

Trait Implementations§

source§

impl Clone for Gossip

source§

fn clone(&self) -> Gossip

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Gossip

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ProtocolHandler for Gossip

source§

fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>>

Handle an incoming connection. Read more
§

fn shutdown(self: Arc<Self>) -> Pin<Box<dyn Future<Output = ()> + Send>>

Called when the node shuts down.

Auto Trait Implementations§

§

impl Freeze for Gossip

§

impl RefUnwindSafe for Gossip

§

impl Send for Gossip

§

impl Sync for Gossip

§

impl Unpin for Gossip

§

impl UnwindSafe for Gossip

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T