libp2p
    Preparing search index...

    Class PubSubBaseProtocol<Events>Abstract

    PubSubBaseProtocol handles the peers and connections logic for pubsub routers and specifies the API that pubsub routers should have.

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    canRelayMessage: boolean

    If router can relay received messages, even if not subscribed

    components: PubSubComponents
    emitSelf: boolean

    if publish should emit to self, if subscribed

    enabled: boolean
    globalSignaturePolicy: "StrictSign" | "StrictNoSign"

    The signature policy to follow by default

    log: Logger
    multicodecs: string[]

    A list of multicodecs that contain the pubsub protocol name.

    Map of peer streams

    queue: PQueue
    started: boolean
    subscriptions: Set<string>

    List of our subscriptions

    topics: Map<string, PeerSet>

    Map of topics to which peers are subscribed to

    topicValidators: Map<string, TopicValidatorFn>

    Topic validator map

    Keyed by topic Topic validators are functions with the following input:

    Methods

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Type Parameters

      • K extends string | number | symbol

      Parameters

      Returns void

    • Normalizes the message and signs it, if signing is enabled. Should be used by the routers to create the message to send.

      Parameters

      • message: { data: Uint8Array; from: PeerId; sequenceNumber: bigint; topic: string }

      Returns Promise<Message>

    • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

      MDN Reference

      Parameters

      Returns boolean

    • Overriding the implementation of publish should handle the appropriate algorithms for the publish/subscriber implementation. For example, a Floodsub implementation might simply publish each message to each topic for every peer.

      sender might be this peer, or we might be forwarding a message on behalf of another peer, in which case sender is the peer we received the message from, which may not be the peer the message was created by.

      Parameters

      Returns Promise<PublishResult>

    • Removes the event listener in target's event listener list with the same type, callback, and options.

      MDN Reference

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • type: K
      • Optionallistener: null | EventHandler<Events[K]>
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Send an rpc object to a peer

      Parameters

      • peer: PeerId
      • data: { messages?: Message[]; subscribe?: boolean; subscriptions?: string[] }

      Returns void