From 7aae30673f6b63637a123a55ff2d37fe472817e9 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 21 Apr 2020 13:40:19 +0200 Subject: [PATCH] chore: apply suggestions from code review Co-Authored-By: Jacob Heun --- package.json | 2 +- src/index.js | 12 +++++++++--- src/peer.js | 2 +- test/pubsub.spec.js | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a9cfee3f98..3f0316aa2a 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "it-pipe": "^1.0.1", "it-pushable": "^1.3.2", "libp2p-crypto": "~0.17.0", - "libp2p-interfaces": "libp2p/js-interfaces#v0.3.x", + "libp2p-interfaces": "^0.3.0", "peer-id": "~0.13.3", "protons": "^1.0.1" }, diff --git a/src/index.js b/src/index.js index 930ac289db..4429b65be1 100644 --- a/src/index.js +++ b/src/index.js @@ -79,7 +79,6 @@ class PubsubBaseProtocol extends EventEmitter { this.log.err = debug(`${debugName}:error`) this.multicodecs = utils.ensureArray(multicodecs) - this.signMessages = peerId this.registrar = registrar this.started = false @@ -174,7 +173,10 @@ class PubsubBaseProtocol extends EventEmitter { const peerId = connection.remotePeer const idB58Str = peerId.toB58String() - const peer = this._addPeer(new Peer(peerId, [protocol])) + const peer = this._addPeer(new Peer({ + id: peerId, + protocols: [protocol] + })) peer.attachConnection(stream) this._processMessages(idB58Str, stream, peer) @@ -190,7 +192,11 @@ class PubsubBaseProtocol extends EventEmitter { const idB58Str = peerId.toB58String() this.log('connected', idB58Str) - const peer = this._addPeer(new Peer(peerId, this.multicodecs)) + const peer = this._addPeer(new Peer({ + id: peerId, + protocols: this.multicodecs + })) + try { const { stream } = await conn.newStream(this.multicodecs) peer.attachConnection(stream) diff --git a/src/peer.js b/src/peer.js index aa016b3a7b..2e764313a2 100644 --- a/src/peer.js +++ b/src/peer.js @@ -16,7 +16,7 @@ class Peer extends EventEmitter { * @param {PeerId} id * @param {Array} protocols */ - constructor (id, protocols) { + constructor ({ id, protocols }) { super() /** diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 39f5ebdc58..a74b6b79de 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -301,7 +301,7 @@ describe('pubsub base protocol', () => { expect(peersSubscribed).to.be.empty() // Set mock peer subscribed - const peer = new Peer(peerId) + const peer = new Peer({ id: peerId }) const id = peer.id.toB58String() peer.topics.add(topic)