Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix: close streams
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and jacobheun committed Aug 10, 2018
1 parent 800c394 commit 546af97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
"interface-connection": "^0.3.2",
"lodash": "^4.17.5",
"mafmt": "^6.0.0",
"multiaddr": "^4.0.0",
"multiaddr": "^5.0.0",
"multistream-select": "^0.14.1",
"peer-id": "^0.10.7",
"peer-info": "^0.14.0",
"peer-info": "~0.14.1",
"protons": "^1.0.1",
"pull-abortable": "^4.1.1",
"pull-handshake": "^1.1.4",
Expand Down
12 changes: 8 additions & 4 deletions src/circuit/hop.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,27 @@ class Hop extends EE {
*/
handle (message, sh) {
if (!this.config.enabled) {
return this.utils.writeResponse(
this.utils.writeResponse(
sh,
proto.CircuitRelay.Status.HOP_CANT_SPEAK_RELAY)
return sh.close()
}

// check if message is `CAN_HOP`
if (message.type === proto.CircuitRelay.Type.CAN_HOP) {
return this.utils.writeResponse(
this.utils.writeResponse(
sh,
proto.CircuitRelay.Status.SUCCESS)
return sh.close()
}

// This is a relay request - validate and create a circuit
const srcPeerId = PeerId.createFromBytes(message.dstPeer.id)
if (srcPeerId.toB58String() === this.peerInfo.id.toB58String()) {
return this.utils.writeResponse(
this.utils.writeResponse(
sh,
proto.CircuitRelay.Status.HOP_CANT_RELAY_TO_SELF)
return sh.close()
}

const dstPeerId = PeerId.createFromBytes(message.dstPeer.id).toB58String()
Expand All @@ -95,9 +98,10 @@ class Hop extends EE {
const noPeer = (err) => {
log.err(err)
setImmediate(() => this.emit('circuit:error', err))
return this.utils.writeResponse(
this.utils.writeResponse(
sh,
proto.CircuitRelay.Status.HOP_NO_CONN_TO_DST)
return sh.close()
}

let dstPeer
Expand Down
2 changes: 1 addition & 1 deletion src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = (swarm, options, connHandler) => {
listener.listen = (ma, callback) => {
callback = callback || (() => {})

swarm.handle(multicodec.relay, (relayProto, conn) => {
swarm.handle(multicodec.relay, (_, conn) => {
const sh = new StreamHandler(conn)

sh.read((err, msg) => {
Expand Down

0 comments on commit 546af97

Please sign in to comment.