diff --git a/README.md b/README.md index d017240..bddaa97 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ TODO: add explanation for registrar! const Pubsub = require('libp2p-pubsub') class PubsubImplementation extends Pubsub { - constructor(peerInfo, registrar, options = {}) { + constructor({ peerInfo, registrar, ...options }) super({ debugName: 'libp2p:pubsub', multicodecs: '/pubsub-implementation/1.0.0', @@ -90,7 +90,7 @@ The following specified API should be the base API for a pubsub implementation o ### Start -Start the pubsub subsystem. The protocol will be registered to `libp2p`, which will notify about peers being connected and disconnected with the protocol. +Starts 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`. #### `pubsub.start()` @@ -102,7 +102,7 @@ Start the pubsub subsystem. The protocol will be registered to `libp2p`, which w ### Stop -Stop the pubsub subsystem. The protocol will be unregistered to `libp2p`, which will remove all listeners for the protocol and the streams with other peers will be closed. +Stops 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. #### `pubsub.stop()` @@ -169,7 +169,7 @@ Get the list of topics which the peer is subscribed to. ### Get Peers Subscribed to a topic -Get a list of the peer-ids that are subscribed to one topic. +Get a list of the [PeerId](https://github.com/libp2p/js-peer-id) strings that are subscribed to one topic. #### `pubsub.getPeersSubscribed(topic)` diff --git a/src/index.js b/src/index.js index e73ed2c..789b794 100644 --- a/src/index.js +++ b/src/index.js @@ -106,9 +106,12 @@ class PubsubBaseProtocol extends EventEmitter { this.registrar.handle(this.multicodecs, this._onIncomingStream) // register protocol with multicodec and handlers - this._registrarId = await this.registrar.register(this.multicodecs, { - onConnect: this._onPeerConnected, - onDisconnect: this._onPeerDisconnected + this._registrarId = await this.registrar.register({ + multicodecs: this.multicodecs, + handlers: { + onConnect: this._onPeerConnected, + onDisconnect: this._onPeerDisconnected + } }) this.log('started') diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 00d12a6..b8477dc 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -53,7 +53,7 @@ describe('pubsub base protocol', () => { expect(sinonMockRegistrar.unregister.calledOnce).to.be.true() }) - it('should not throw to start if already started', async () => { + it('starting should not throw if already started', async () => { await pubsub.start() await pubsub.start() expect(sinonMockRegistrar.handle.calledOnce).to.be.true() @@ -63,14 +63,14 @@ describe('pubsub base protocol', () => { expect(sinonMockRegistrar.unregister.calledOnce).to.be.true() }) - it('should not throw if stop before start', async () => { + it('stopping should not throw if not started', async () => { await pubsub.stop() expect(sinonMockRegistrar.register.calledOnce).to.be.false() expect(sinonMockRegistrar.unregister.calledOnce).to.be.false() }) }) - describe('should handle messages creating and signing', () => { + describe('should handle message creation and signing', () => { let peerInfo let pubsub diff --git a/test/utils/index.js b/test/utils/index.js index 3d8a75b..3eafa05 100644 --- a/test/utils/index.js +++ b/test/utils/index.js @@ -70,7 +70,7 @@ exports.createMockRegistrar = (registrarRecord) => ({ handler } }, - register: (multicodecs, handlers) => { + register: ({ multicodecs, handlers }) => { const rec = registrarRecord[multicodecs[0]] || {} registrarRecord[multicodecs[0]] = {