iroh_gossip::net

Struct 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 builder() -> Builder

Creates a default Builder, with the endpoint set.

Source

pub async fn listen(self, endpoint: Endpoint)

Available on crate feature rpc only.

Listen on a quinn endpoint for incoming RPC connections.

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<(), Error>

Handle an incoming [Connection].

Make sure to check the ALPN protocol yourself before passing the connection.

Source

pub async fn shutdown(&self) -> Result<()>

Shutdown the gossip instance.

This leaves all topics, sending Disconnect messages to peers, and then stops the gossip actor loop and drops all state and connections.

Source

pub fn metrics(&self) -> &Arc<Metrics>

Returns the metrics tracked for this gossip instance.

Methods from Deref<Target = GossipApi>§

Source

pub async fn subscribe_with_opts( &self, topic_id: TopicId, opts: JoinOptions, ) -> Result<GossipTopic, ApiError>

Available on crate features 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.

Source

pub async fn subscribe_and_join( &self, topic_id: TopicId, bootstrap: Vec<NodeId>, ) -> Result<GossipTopic, ApiError>

Available on crate features net or rpc only.

Join a gossip topic with the default options and wait for at least one active connection.

Source

pub async fn subscribe( &self, topic_id: TopicId, bootstrap: Vec<NodeId>, ) -> Result<GossipTopic, ApiError>

Available on crate features 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

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 Deref for Gossip

Source§

type Target = GossipApi

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl ProtocolHandler for Gossip

Source§

fn accept(&self, conn: Connection) -> BoxFuture<Result<()>>

Handle an incoming connection. Read more
Source§

fn shutdown(&self) -> BoxFuture<()>

Called when the node shuts down.
§

fn on_connecting( &self, connecting: Connecting, ) -> Pin<Box<dyn Future<Output = Result<Connection, Error>> + Send>>

Optional interception point to handle the Connecting state. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
Available on non-bootstrap only.
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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