JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2097
  • Score
    100M100P100Q147503F
  • License MIT

Pubsub base protocol for libp2p pubsub routers

Package Exports

  • libp2p-pubsub

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libp2p-pubsub) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

js-libp2p-pubsub

Discourse posts Coverage Status Travis CI Circle CI Dependency Status js-standard-style standard-readme compliant

libp2p-pubsub consits on the base protocol for libp2p pubsub implementation. This module is responsible for all the logic regarding peer connections.

Lead Maintainer

Vasco Santos.

Table of Contents

Install

> npm install libp2p-pubsub

Usage

A pubsub implementation MUST override the _processConnection, publish, subscribe and unsubscribe functions.

Other functions, such as _addPeer, _removePeer, _onDial, start and stop may be overwritten if the pubsub implementation needs to add custom logic on them. It is important pointing out that start and stop must call super. The start function is responsible for mounting the pubsub protocol onto the libp2p node and sending its' subscriptions to every peer connected, while the stop function is responsible for unmounting the pubsub protocol and shutting down every connection

All the remaining functions MUST NOT be overwritten.

The following example aims to show how to create your pubsub implementation extending this base protocol. The pubsub implementation will handle the subscriptions logic.

const Pubsub = require('libp2p-pubsub')

class PubsubImplementation extends Pubsub {
  constructor(libp2p) {
    super('libp2p:pubsub', '/pubsub-implementation/1.0.0', libp2p)
  }

  _processConnection(idB58Str, conn, peer) {
    // Required to be implemented by the subclass
    // Process each message accordingly
  }

  publish() {
    // Required to be implemented by the subclass
  }

  subscribe() {
    // Required to be implemented by the subclass
  }

  unsubscribe() {
    // Required to be implemented by the subclass
  }
}

Validate

Validates the signature of a message.

pubsub.validate(message, callback)

Parameters
Name Type Description
message Message a pubsub message
callback function(Error, Boolean) calls back with true if the message is valid

Implementations using this base protocol

You can use the following implementations as examples for building your own pubsub implementation.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

Copyright (c) Protocol Labs, Inc. under the MIT License. See LICENSE file for details.