Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

fix: use unidirectional streams #45

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class PubsubBaseProtocol extends EventEmitter {
protocols: [protocol]
}))

peer.attachConnection(stream)
this._processMessages(idB58Str, stream, peer)
}

Expand All @@ -200,7 +199,6 @@ class PubsubBaseProtocol extends EventEmitter {
try {
const { stream } = await conn.newStream(this.multicodecs)
peer.attachConnection(stream)
this._processMessages(idB58Str, stream, peer)
} catch (err) {
this.log.err(err)
}
Expand Down
2 changes: 2 additions & 0 deletions src/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Peer extends EventEmitter {
this.conn = conn
this.stream = pushable({
onEnd: () => {
// close readable side of the stream
this.conn.reset && this.conn.reset()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-up, I will create an issue to remove this validation and create a wrapper around it-pair for these tests.

it-pair provides a bare minimal duplex stream for testing, but it does not have the reset function, as a multiplex stream. I tested this with js-libp2p and the stream reset function is called there.

this.conn = null
this.stream = null
this.emit('close')
Expand Down