{"bugs":{"url":"https://github.com/libp2p/js-libp2p-pubsub/issues"},"dist":{"shasum":"4e6706227f60fd103a80975493163f962817f5bb","tarball":"https://registry.npmjs.org/libp2p-pubsub/-/libp2p-pubsub-0.5.0.tgz","fileCount":16,"integrity":"sha512-Ac9sb7oiQfGSTjPA6mFGdxihphzAna4XNS4ZOvwUOwSH5LcJkpp+M71/1f+jwdd+5yNSDBPUEb83RazKT087tw==","signatures":[{"sig":"MEYCIQC2sFdUwUrgmv3hTV6MvEWC6FhmfUWLFkPu9L+oLlRX9AIhANgTWumL/BAlWDjTroIROWo9UbdT3PPkrmwfsdlTnRA2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4553498,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeoFP0CRA9TVsSAnZWagAA75MQAJs6VRlzcgBuOG/Hk6Y8\nvrQ3pB393HTb9+BNRZ9XV0j1H8cbC1fP0CS891NeeEVXthaeoO+7fkRDLMQB\nAN6IZe0CMG1tBAIw+v/Y6fm5ZlPWjVYTbthEMLqGqKt/0q3cxm9t/aO0fTBP\nR0Bzd8rJedSjFMSZeaDpdbaKY4PPMJ7F4OMlu6LOopIYKDio9TZwPx8vAQwZ\nS5AF9B5vkrhrlsCQ4f+REULN1GKD8407lF3RkEC7IBIFsA1cG0wjL3S7dOXI\n5Itdky6ykHqUwbk5ZssFPPUclEUUMApfXbqG9JF9vDTWXkslQZ1GFME7OKhh\nyLqc8ELvujCatkDxeRMHkXCcw96H+1F7+HEVB/EFXne21210Xf/pNnA7jIqX\nNHKJxcpsMp3Hu90jA4JxHav/awpXhJegN3p8FxDX1Xy4hCZwuyyVKigkbkZn\njScpXZRoKpp6BTbTdin+iovbc+Wu6Dacob/RCMpdqPtCf6dyLz/IiWg8qdXG\n2ZQKbapMIM5A5l70M0pWWyuqwTjJU+lncXLD1HOmiPHaHAZhv82Ap38mmcsa\nLjs9vnMzdCoGM9STd3a3JSsU2aYlkUWnoYLSb7yimMtMvHn7DbqKWMPCB0bD\n660eMIlCb+X4mvli9ud0nKK4SWZmJuftOu6idOw2iF/uU8VZm7TeGQZbyecf\nGcza\r\n=Y4xd\r\n-----END PGP SIGNATURE-----\r\n"},"main":"src/index.js","name":"libp2p-pubsub","readme":"js-libp2p-pubsub\n==================\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://libp2p.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)\n[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-pubsub/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-pubsub?branch=master)\n[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-pubsub.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-pubsub)\n[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-pubsub.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-pubsub)\n[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-pubsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-pubsub) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-pubsub)\n\n> libp2p-pubsub is the base protocol for libp2p pubsub implementations. This module is responsible for registering the protocol with libp2p, as well as managing the logic regarding pubsub connections with other peers.\n\n## Lead Maintainer\n\n[Vasco Santos](https://github.com/vasco-santos).\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```sh\n> npm install libp2p-pubsub\n```\n\n## Usage\n\n`libp2p-pubsub` abstracts the implementation protocol registration within `libp2p` and takes care of all the protocol connections. This way, a pubsub implementation can focus on its routing algorithm, instead of also needing to create the setup for it.\n\nA pubsub implementation **MUST** override the `_processMessages`, `publish`, `subscribe`, `unsubscribe` and `getTopics` functions.\n\nOther functions, such as `_onPeerConnected`, `_onPeerDisconnected`, `_addPeer`, `_removePeer`, `start` and `stop` may be overwritten if the pubsub implementation needs to customize their logic. Implementations overriding  `start` and `stop` **MUST** call `super`. The `start` function is responsible for registering the pubsub protocol with libp2p, while the `stop` function is responsible for unregistering the pubsub protocol and closing pubsub connections.\n\nAll the remaining functions **MUST NOT** be overwritten.\n\nThe following example aims to show how to create your pubsub implementation extending this base protocol. The pubsub implementation will handle the subscriptions logic.\n\nTODO: add explanation for registrar!\n\n```JavaScript\nconst Pubsub = require('libp2p-pubsub')\n\nclass PubsubImplementation extends Pubsub {\n  constructor({ peerId, registrar, ...options })\n    super({\n      debugName: 'libp2p:pubsub',\n      multicodecs: '/pubsub-implementation/1.0.0',\n      peerId: peerId,\n      registrar: registrar,\n      signMessages: options.signMessages,\n      strictSigning: options.strictSigning\n    })\n  }\n\n  _processMessages(idB58Str, conn, peer) {\n    // Required to be implemented by the subclass\n    // Process each message accordingly\n  }\n\n  publish() {\n    // Required to be implemented by the subclass\n  }\n\n  subscribe() {\n    // Required to be implemented by the subclass\n  }\n\n  unsubscribe() {\n    // Required to be implemented by the subclass\n  }\n\n  getTopics() {\n    // Required to be implemented by the subclass\n  }\n}\n```\n\n## API\n\nThe following specified API should be the base API for a pubsub implementation on top of `libp2p`.\n\n### Start\n\nStarts the pubsub subsystem. The protocol will be registered to `libp2p`, which will result in pubsub being notified when peers who support the protocol connect/disconnect to `libp2p`.\n\n#### `pubsub.start()`\n\n##### Returns\n\n| Type | Description |\n|------|-------------|\n| `Promise<void>` | resolves once pubsub starts |\n\n### Stop\n\nStops the pubsub subsystem. The protocol will be unregistered from `libp2p`, which will remove all listeners for the protocol and the established connections will be closed.\n\n#### `pubsub.stop()`\n\n##### Returns\n\n| Type | Description |\n|------|-------------|\n| `Promise<void>` | resolves once pubsub stops |\n\n### Publish\n\nPublish data messages to pubsub topics.\n\n#### `pubsub.publish(topics, messages)`\n\n##### Parameters\n\n| Name | Type | Description |\n|------|------|-------------|\n| topics | `Array<string>|string` | set of pubsub topics |\n| messages | `Array<any>|any` | set of messages to publish |\n\n##### Returns\n\n| Type | Description |\n|------|-------------|\n| `Promise<void>` | resolves once messages are published to the network |\n\n### Subscribe\n\nSubscribe to the given topic(s).\n\n#### `pubsub.subscribe(topics)`\n\n##### Parameters\n\n| Name | Type | Description |\n|------|------|-------------|\n| topics | `Array<string>|string` | set of pubsub topics |\n\n### Unsubscribe\n\nUnsubscribe from the given topic(s).\n\n#### `pubsub.unsubscribe(topics)`\n\n##### Parameters\n\n| Name | Type | Description |\n|------|------|-------------|\n| topics | `Array<string>|string` | set of pubsub topics |\n\n### Get Topics\n\nGet the list of topics which the peer is subscribed to.\n\n#### `pubsub.getTopics()`\n\n##### Returns\n\n| Type | Description |\n|------|-------------|\n| `Array<String>` | Array of subscribed topics |\n\n### Get Peers Subscribed to a topic\n\nGet a list of the [PeerId](https://github.com/libp2p/js-peer-id) strings that are subscribed to one topic.\n\n#### `pubsub.getSubscribers(topic)`\n\n##### Parameters\n\n| Name | Type | Description |\n|------|------|-------------|\n| topic | `string` | pubsub topic |\n\n##### Returns\n\n| Type | Description |\n|------|-------------|\n| `Array<string>` | Array of base-58 PeerId's |\n\n### Validate\n\nValidates the signature of a message.\n\n#### `pubsub.validate(message)`\n\n##### Parameters\n\n| Name | Type | Description |\n|------|------|-------------|\n| message | `Message` | a pubsub message |\n\n#### Returns\n\n| Type | Description |\n|------|-------------|\n| `Promise<Boolean>` | resolves to true if the message is valid |\n\n## Implementations using this base protocol\n\nYou can use the following implementations as examples for building your own pubsub implementation.\n\n- [libp2p/js-libp2p-floodsub](https://github.com/libp2p/js-libp2p-floodsub)\n- [ChainSafe/gossipsub-js](https://github.com/ChainSafe/gossipsub-js)\n\n## Contribute\n\nFeel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-pubsub/issues)!\n\nThis repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\nCopyright (c) Protocol Labs, Inc. under the **MIT License**. See [LICENSE file](./LICENSE) for details.\n","gitHead":"363f65537fbfe62cfd48133959a6ff8b1ff39830","license":"MIT","scripts":{"docs":"aegir-docs","lint":"aegir lint","test":"aegir test","build":"aegir build","release":"aegir release --target node --docs","coverage":"aegir coverage","test:node":"aegir test -t node","test:browser":"aegir test -t browser","release-major":"aegir release --type major --docs","release-minor":"aegir release --type minor --docs","coverage-publish":"aegir coverage --provider coveralls"},"_npmUser":{"name":"vascosantos","email":"vasco.santos@moxy.studio"},"homepage":"https://github.com/libp2p/js-libp2p-pubsub#readme","keywords":["IPFS","libp2p","pubsub","gossip","flood","flooding"],"pre-push":["lint"],"repository":{"url":"git+https://github.com/libp2p/js-libp2p-pubsub.git","type":"git"},"_npmVersion":"6.13.4","description":"Pubsub base protocol for libp2p pubsub routers","directories":{},"maintainers":[{"name":"vascosantos","email":"vasco.santos@moxy.studio"}],"_nodeVersion":"12.14.0","contributors":[{"name":"Vasco Santos","email":"vasco.santos@moxy.studio"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Mikerah","email":"mikerahqc@protonmail.com"},{"name":"Topper Bowers","email":"topper@toppingdesign.com"},{"name":"Cayman","email":"caymannava@gmail.com"},{"name":"Alex Potsides","email":"alex@achingbrain.net"},{"name":"Alan Shaw","email":"alan.shaw@protocol.ai"}],"dependencies":{"bs58":"^4.0.1","debug":"^4.1.1","it-pipe":"^1.0.1","peer-id":"~0.13.3","protons":"^1.0.1","err-code":"^2.0.0","it-pushable":"^1.3.2","libp2p-crypto":"~0.17.0","libp2p-interfaces":"^0.3.0","it-length-prefixed":"^3.0.0"},"_hasShrinkwrap":false,"leadMaintainer":"Vasco Santos <santos.vasco10@gmail.com>","readmeFilename":"README.md","devDependencies":{"chai":"^4.2.0","aegir":"^21.2.0","sinon":"^9.0.0","it-pair":"^1.0.0","benchmark":"^2.1.4","multiaddr":"^7.2.1","chai-spies":"^1.0.0","dirty-chai":"^2.0.1"},"_npmOperationalInternal":{"tmp":"tmp/libp2p-pubsub_0.5.0_1587565555999_0.7873773823395549","host":"s3://npm-registry-packages"},"_id":"libp2p-pubsub@0.5.0","version":"0.5.0"}