Libp2p implementation of PeerAwareMessageBus.

Hierarchy

Implements

Constructors

  • Parameters

    • pubsub: PubSub<PubSubEvents>

      Libp2p PubSub instance.

    • defaultTopic: string = DEFAULT_TOPIC

      Default topic to use when dispatching messages.

    • monitorPeers: number | false = DEFAULT_PEER_MONITOR_REFRESH_MS

      Specifies the interval in milliseconds to monitor peers' subscriptions and emit join / leave events. If set to false or <= 0, peers will not be monitored. Defaults to 1000 (1 second).

    Returns Libp2pMessageBus

Properties

defaultTopic: string = DEFAULT_TOPIC

Default topic to use when dispatching messages.

handlers: Map<string, PeerAwareMessageHandler<Uint8Array, PeerId>[]> = ...
monitor?: PeerSubscriptionMonitor<PeerId>
onMessage: ((...args) => MaybePromise<void>) = ...

Type declaration

    • (...args): MaybePromise<void>
    • Wraps a MaybePromise-yielding coroutine (generator function) into a function that returns MaybePromise. This allows you to use maybeAsync/yield in a similar way to async/await, where yield maybePromise will return awaited / resolved value.

      Parameters

      • Rest ...args: [message: CustomEvent<Message>]

      Returns MaybePromise<void>

      Example

      const add = maybeAsync(function* (a: number, b: number) {
      const result1: number = yield Promise.resolve(a); // result1 === a
      const result2 = yield b; // result2 === b
      return result + result2;
      });
      const result = await add(1, 2); // result === 3
pubsub: PubSub<PubSubEvents>

Libp2p PubSub instance.

validators: Map<string, PeerAwareMessageValidator<Uint8Array, PeerId>[]> = ...

Accessors

Methods

  • Returns void

  • Parameters

    • _: PeerId
    • message: Message

    Returns Promise<TopicValidatorResult>

Generated using TypeDoc