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 fn max_message_size(&self) -> usize

Returns the maximum message size configured for this gossip actor.

Source

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.

Source

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.

Source

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

Source

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.

Source

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

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, conn: Connection) -> BoxFuture<Result<()>>

Handle an incoming connection. Read more
§

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
§

fn shutdown(&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> 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
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<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