Implements the Waku v2 Relay protocol. Must be passed as a pubsub module to a Libp2p instance.

Implements

Hierarchy

  • GossipSub
    • WakuRelay

Constructors

Properties

#private: any
control: Map<string, IControlMessage>

Map of control messages peer id => control message

decryptionKeys: Map<Uint8Array, { contentTopics?: string[]; method?: DecryptionMethod }>
direct: Set<string>

Direct peers

fanout: Map<string, Set<string>>

Map of topics to set of peers. These mesh peers are the ones to which we are publishing without a topic membership topic => peer id set

globalSignaturePolicy: "StrictSign" | "StrictNoSign"

The signature policy to follow by default

gossip: Map<string, IControlIHave[]>

Map of pending messages to gossip peer id => control messages

gossipTracer: IWantTracer

Tracks IHAVE/IWANT promises broken by peers

mesh: Map<string, Set<string>>

Map of topic meshes topic => peer id set

multicodecs: string[]
observers: { [contentTopic: string]: Set<((message: waku_message.WakuMessage) => void)> }

observers called when receiving new message. Observers under key "" are always called.

Type declaration

opts: Required<GossipOptions>
peers: Set<string>
pubSubTopic: string
score: PeerScore

Peer score tracking

streamsInbound: Map<string, InboundStream>
streamsOutbound: Map<string, OutboundStream>
topicValidators: Map<string, TopicValidatorFn>
multicodec: string = ...

Accessors

  • get started(): boolean
  • Returns boolean

Methods

  • Whether to accept a message from a peer

    Parameters

    • id: string

    Returns boolean

  • Register a decryption key to attempt decryption of received messages. This can either be a private key for asymmetric encryption or a symmetric key. WakuRelay will attempt to decrypt messages using both methods.

    Strings must be in hex format.

    Parameters

    • key: string | Uint8Array
    • Optional options: { contentTopics?: string[]; method?: DecryptionMethod }

    Returns void

  • Type Parameters

    • K extends keyof GossipsubEvents

    Parameters

    • type: K
    • listener: null | EventHandler<GossipsubEvents[K]>
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Delete a decryption key that was used to attempt decryption of received messages.

    Strings must be in hex format.

    Parameters

    • key: string | Uint8Array

    Returns void

  • Parameters

    • event: Event

    Returns boolean

  • FOR DEBUG ONLY - Dump peer stats for all peers. Data is cloned, safe to mutate

    Returns PeerScoreStatsDump

  • Parameters

    • Optional topic: string

    Returns string[]

  • Returns PeerId[]

  • Return score of a peer.

    Parameters

    • peerId: string

    Returns number

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

  • Handles an rpc request from a peer

    Parameters

    • from: PeerId
    • rpc: IRPC

    Returns Promise<void>

  • Maintains the mesh and fanout maps in gossipsub.

    Returns Promise<void>

  • Pass libp2p components to interested system components

    Parameters

    • components: Components

    Returns Promise<void>

  • Returns boolean

  • Parameters

    • type: string

    Returns number

  • Parameters

    • id: string
    • outRpc: IRPC
    • ctrl: IControlMessage

    Returns void

  • App layer publishes a message to peers, return number of peers this message is published to Note: async due to crypto only if StrictSign, otherwise it's a sync fn.

    For messages not from us, this class uses forwardMessage.

    Parameters

    • topic: string
    • data: Uint8Array

    Returns Promise<PublishResult>

  • Type Parameters

    • K extends keyof GossipsubEvents

    Parameters

    • type: K
    • Optional listener: null | EventHandler<GossipsubEvents[K]>
    • Optional options: boolean | EventListenerOptions

    Returns void

  • This function should be called when asyncValidation is true after the message got validated by the caller. Messages are stored in the mcache and validation is expected to be fast enough that the messages should still exist in the cache. There are three possible validation outcomes and the outcome is given in acceptance.

    If acceptance = MessageAcceptance.Accept the message will get propagated to the network. The propagation_source parameter indicates who the message was received by and will not be forwarded back to that peer.

    If acceptance = MessageAcceptance.Reject the message will be deleted from the memcache and the P₄ penalty will be applied to the propagationSource.

    If acceptance = MessageAcceptance.Ignore the message will be deleted from the memcache but no P₄ penalty will be applied.

    This function will return true if the message was found in the cache and false if was not in the cache anymore.

    This should only be called once per message.

    Parameters

    • msgId: string
    • propagationSource: PeerId
    • acceptance: MessageAcceptance

    Returns void

  • Mounts the gossipsub protocol onto the libp2p node and subscribes to the default topic.

    Returns

    Returns Promise<void>

  • Unmounts the gossipsub protocol and shuts down every connection

    Returns Promise<void>

  • Subscribe to a pubsub topic and start emitting Waku messages to observers.

    Parameters

    • pubSubTopic: string

    Returns void

  • Unsubscribe to a topic

    Parameters

    • topic: string

    Returns void

Generated using TypeDoc