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

Commit 7789f5d

Browse files
committed
Merge pull request #59 from diasdavid/update/multistream
WIP add new version of multistream
2 parents 9d958c3 + a224b0b commit 7789f5d

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"ip-address": "^5.8.0",
5757
"lodash.contains": "^2.4.3",
5858
"multiaddr": "^2.0.0",
59-
"multistream-select": "^0.6.5",
59+
"multistream-select": "^0.9.0",
6060
"peer-id": "^0.6.6",
6161
"peer-info": "^0.6.2",
6262
"protocol-buffers-stream": "^1.3.1",
@@ -79,4 +79,4 @@
7979
"Richard Littauer <[email protected]>",
8080
"dignifiedquire <[email protected]>"
8181
]
82-
}
82+
}

src/default-handler.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ const multistream = require('multistream-select')
44

55
// incomming connection handler
66
module.exports = function connHandler (protocols, conn) {
7-
var msS = new multistream.Select()
8-
7+
const ms = new multistream.Listener()
98
Object.keys(protocols).forEach((protocol) => {
109
if (!protocol) {
1110
return
1211
}
1312

14-
msS.addHandler(protocol, protocols[protocol])
13+
ms.addHandler(protocol, protocols[protocol])
1514
})
1615

17-
msS.handle(conn)
16+
ms.handle(conn, (err) => {
17+
if (err) {
18+
return // the multistream handshake failed
19+
}
20+
})
1821
}

src/dial.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ module.exports = function dial (swarm) {
103103
nextMuxer(muxers.shift())
104104

105105
function nextMuxer (key) {
106-
var msI = new multistream.Interactive()
107-
msI.handle(conn, function () {
108-
msI.select(key, (err, conn) => {
106+
const ms = new multistream.Dialer()
107+
ms.handle(conn, (err) => {
108+
if (err) {
109+
return callback(new Error('multistream not supported'))
110+
}
111+
ms.select(key, (err, conn) => {
109112
if (err) {
110113
if (muxers.length === 0) {
111114
cb(new Error('could not upgrade to stream muxing'))
@@ -144,9 +147,12 @@ module.exports = function dial (swarm) {
144147
}
145148

146149
function protocolHandshake (conn, protocol, cb) {
147-
var msI = new multistream.Interactive()
148-
msI.handle(conn, function () {
149-
msI.select(protocol, (err, conn) => {
150+
const ms = new multistream.Dialer()
151+
ms.handle(conn, (err) => {
152+
if (err) {
153+
return callback(err)
154+
}
155+
ms.select(protocol, (err, conn) => {
150156
if (err) {
151157
return callback(err)
152158
}

src/identify.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => {
3030

3131
const conn = muxer.newStream()
3232

33-
var msI = new multistream.Interactive()
34-
msI.handle(conn, () => {
35-
msI.select(exports.multicodec, (err, ds) => {
33+
const ms = new multistream.Dialer()
34+
ms.handle(conn, (err) => {
35+
if (err) {
36+
return callback(err)
37+
}
38+
39+
ms.select(exports.multicodec, (err, ds) => {
3640
if (err) {
3741
return callback(err)
3842
}

0 commit comments

Comments
 (0)