Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: rename peer to peer streams
  • Loading branch information
wemeetagain committed Jul 16, 2020
commit be7ee92a8dde3d8ddaab9f064fe8f4bb1c4b581d
34 changes: 18 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class PubsubBaseProtocol extends EventEmitter {
await this.registrar.unregister(this._registrarId)

this.log('stopping')
this.peers.forEach((peer) => peer.close())
this.peers.forEach((peerStreams) => peerStreams.close())

this.peers = new Map()
this.started = false
Expand Down Expand Up @@ -221,23 +221,25 @@ class PubsubBaseProtocol extends EventEmitter {
*/
_addPeer (peerId, protocol) {
const id = peerId.toB58String()
let existing = this.peers.get(id)
const existing = this.peers.get(id)
// If peer streams already exists, do nothing
if (existing) {
return existing
}

if (!existing) {
this.log('new peer', id)
// else create a new peer streams

const peer = new PeerStreams({
id: peerId,
protocol
})
this.log('new peer', id)

this.peers.set(id, peer)
existing = peer
const peerStreams = new PeerStreams({
id: peerId,
protocol
})

peer.once('close', () => this._removePeer(peerId))
}
this.peers.set(id, peerStreams)
peerStreams.once('close', () => this._removePeer(peerId))

return existing
return peerStreams
}

/**
Expand All @@ -249,13 +251,13 @@ class PubsubBaseProtocol extends EventEmitter {
_removePeer (peerId) {
if (!peerId) return
const id = peerId.toB58String()
const peer = this.peers.get(id)
if (!peer) return
const peerStreams = this.peers.get(id)
if (!peerStreams) return

this.log('delete peer', id)
this.peers.delete(id)

return peer
return peerStreams
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/peerStreams.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const abortable = require('abortable-iterator')
const AbortController = require('abort-controller')
const debug = require('debug')

const log = debug('libp2p-pubsub:peer')
log.error = debug('libp2p-pubsub:peer:error')
const log = debug('libp2p-pubsub:peer-streams')
log.error = debug('libp2p-pubsub:peer-streams:error')

/**
* Thin wrapper around a peer's inbound / outbound pubsub streams
Expand Down