Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
vasco-santos and jacobheun committed Apr 21, 2020
1 parent 21a63cb commit 7aae306
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
},
Expand Down
12 changes: 9 additions & 3 deletions src/index.js
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/peer.js
Expand Up @@ -16,7 +16,7 @@ class Peer extends EventEmitter {
* @param {PeerId} id
* @param {Array<string>} protocols
*/
constructor (id, protocols) {
constructor ({ id, protocols }) {
super()

/**
Expand Down
2 changes: 1 addition & 1 deletion test/pubsub.spec.js
Expand Up @@ -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)
Expand Down

0 comments on commit 7aae306

Please sign in to comment.