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

Implements

Constructors

Properties

_registrarTopologyIds: undefined | string[]
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

maxInboundStreams: number
maxOutboundStreams: number
multicodecs: string[]

Map of peer streams

started: boolean
subscriptions: Set<string>

List of our subscriptions

topicValidators: Map<string, TopicValidatorFn>

Topic validator map

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

topics: Map<string, PeerSet>

Map of topics to which peers are subscribed to

Methods

  • Whether to accept a message from a peer Override to create a graylist

    Parameters

    Returns boolean

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

  • Get a list of the peer-ids that are subscribed to one topic.

    Parameters

    • topic: string

    Returns PeerId[]

  • Get the list of topics which the peer is subscribed to.

    Returns string[]

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

  • Send an rpc object to a peer

    Parameters

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

    Returns void

  • Unregister the pubsub protocol and the streams with other peers will be closed.

    Returns Promise<void>

  • Subscribes to a given topic.

    Parameters

    • topic: string

    Returns void

  • Unsubscribe from the given topic

    Parameters

    • topic: string

    Returns void