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

Catch bad peerid and update deps #39

Merged
merged 3 commits into from
Nov 15, 2018
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
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"coverage-publish": "aegir coverage --provider coveralls"
},
"pre-push": [
"lint",
"test"
"lint"
],
"repository": {
"type": "git",
Expand All @@ -43,28 +42,28 @@
"Victor Bjelkholm <victorbjelkholm@gmail.com>"
],
"devDependencies": {
"aegir": "^15.2.0",
"aegir": "^17.0.1",
"assert": "^1.4.1",
"chai": "^4.1.2",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"libp2p": "~0.23.0",
"libp2p-secio": "~0.10.0",
"libp2p": "~0.23.1",
"libp2p-secio": "~0.10.1",
"pull-protocol-buffers": "~0.1.2",
"sinon": "^6.3.4"
"sinon": "^7.1.1"
},
"dependencies": {
"async": "^2.6.0",
"debug": "^4.0.1",
"async": "^2.6.1",
"debug": "^4.1.0",
"defaults-deep": "~0.2.4",
"interface-connection": "~0.3.2",
"mafmt": "^6.0.0",
"multiaddr": "^5.0.0",
"multistream-select": "~0.14.1",
"peer-id": "~0.11.0",
"mafmt": "^6.0.2",
"multiaddr": "^5.0.2",
"multistream-select": "~0.14.3",
"peer-id": "~0.12.0",
"peer-info": "~0.14.1",
"protons": "^1.0.1",
"pull-abortable": "^4.1.1",
"pull-handshake": "^1.1.4",
"pull-stream": "^3.6.7"
"pull-stream": "^3.6.9"
}
}
12 changes: 9 additions & 3 deletions src/circuit/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Dialer {
*
* @param {PeerInfo} peer
* @param {Function} callback
* @returns {*}
* @returns {void}
*/
canHop (peer, callback) {
callback = once(callback || (() => { }))
Expand Down Expand Up @@ -209,6 +209,12 @@ class Dialer {
waterfall([
(cb) => {
log(`negotiating relay for peer ${dstMa.getPeerId()}`)
let dstPeerId
try {
dstPeerId = PeerId.createFromB58String(dstMa.getPeerId()).id
} catch (err) {
return cb(err)
}
sh.write(
proto.CircuitRelay.encode({
type: proto.CircuitRelay.Type.HOP,
Expand All @@ -217,7 +223,7 @@ class Dialer {
addrs: srcMas.map((addr) => addr.buffer)
},
dstPeer: {
id: PeerId.createFromB58String(dstMa.getPeerId()).id,
id: dstPeerId,
addrs: [dstMa.buffer]
}
}), cb)
Expand Down Expand Up @@ -247,7 +253,7 @@ class Dialer {
*
* @param {PeerInfo} peer - the PeerInfo of the relay peer
* @param {Function} cb - a callback with the connection to the relay peer
* @returns {Function|void}
* @returns {void}
* @private
*/
_dialRelay (peer, cb) {
Expand Down
6 changes: 3 additions & 3 deletions src/circuit/hop.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Hop extends EE {
* @param {PeerInfo} peer
* @param {StreamHandler} srcSh
* @param {function} callback
* @returns {function}
* @returns {void}
*/
_connectToStop (peer, srcSh, callback) {
this._dialPeer(peer, (err, dstConn) => {
Expand Down Expand Up @@ -156,7 +156,7 @@ class Hop extends EE {
* @param {StreamHandler} srcSh
* @param {CircuitRelay} message
* @param {function} callback
* @returns {function}
* @returns {void}
*/
_negotiateStop (dstSh, srcSh, message, callback) {
const stopMsg = Object.assign({}, message, {
Expand Down Expand Up @@ -241,7 +241,7 @@ class Hop extends EE {
*
* @param {Multiaddr} dstPeer
* @param {Function} callback
* @returns {Function|void}
* @returns {void}
* @private
*/
_dialPeer (dstPeer, callback) {
Expand Down
26 changes: 26 additions & 0 deletions test/dialer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ describe(`dialer tests`, function () {
})
})

it(`should fail with an invalid peer id`, function (done) {
const dstMa = multiaddr('/ip4/127.0.0.1/tcp/4001')
dialer._dialRelay.callsFake((_, cb) => {
pull(
p[0],
pb.decode(proto.CircuitRelay),
pull.asyncMap((msg, cb) => {
expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer)
cb(null, {
type: proto.CircuitRelay.Type.STATUS,
code: proto.CircuitRelay.Status.SUCCESS
})
}),
pb.encode(proto.CircuitRelay),
p[0]
)
cb(null, conn)
})

dialer._negotiateRelay(peer, dstMa, (err, conn) => {
expect(err).to.exist()
expect(conn).to.not.exist()
done()
})
})

it(`should handle failed relay negotiation`, function (done) {
dialer._dialRelay.callsFake((_, cb) => {
cb(null, conn)
Expand Down