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 full)

Implements

Constructors

Properties

#private: any
_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

log: Logger
maxInboundStreams: number
maxOutboundStreams: number
multicodecs: string[]

A list of multicodecs that contain the pubsub protocol name.

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

  • Registrar notifies a closing connection with pubsub protocol

    Parameters

    Returns void

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

    Parameters

    Returns boolean

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

  • 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