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

Commit 70fcc87

Browse files
committed
refactor: move active/passive check out of _readDstAddr
1 parent 7f51231 commit 70fcc87

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/circuit/hop.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ class Hop extends EE {
8787
return this._writeErr(streamHandler, constants.RESPONSE.HOP.CANT_CONNECT_TO_SELF, cb)
8888
}
8989

90-
if (!this.active && !utils.isPeerConnected(dstMa.getPeerId())) {
91-
return this._writeErr(streamHandler, constants.RESPONSE.HOP.NO_CONN_TO_DST, cb)
92-
}
93-
9490
cb(null, dstMa)
9591
})
9692
}
@@ -107,7 +103,17 @@ class Hop extends EE {
107103
this.swarm.handle(multicodec.hop, (proto, conn) => {
108104
const streamHandler = new StreamHandler(conn, 1000 * 60)
109105
waterfall([
110-
(cb) => this._readDstAddr(streamHandler, cb),
106+
(cb) => this._readDstAddr(streamHandler, (err, dstMa) => {
107+
if (err) {
108+
return cb(err)
109+
}
110+
111+
if (!this.active && !utils.isPeerConnected(dstMa.getPeerId())) {
112+
return this._writeErr(streamHandler, constants.RESPONSE.HOP.NO_CONN_TO_DST, cb)
113+
}
114+
115+
cb(null, dstMa)
116+
}),
111117
(dstMa, cb) => {
112118
this._readSrcAddr(streamHandler, (err, srcMa) => {
113119
cb(err, dstMa, srcMa)

src/circuit/stop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
require('setimmediate')
3+
const setImmediate = require('async/setImmediate')
44

55
const EE = require('events').EventEmitter
66
const Buffer = require('safe-buffer').Buffer

0 commit comments

Comments
 (0)