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

Commit 5399d43

Browse files
michaelfakhridaviddias
authored andcommitted
Added error handling to transport.dial functionality when there is one multiaddr (#133)
1 parent 6400b82 commit 5399d43

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

gulpfile.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ const multiaddr = require('multiaddr')
1212
const fs = require('fs')
1313
const path = require('path')
1414

15-
const sigServer = require('libp2p-webrtc-star/src/signalling-server')
15+
const sigServer = require('libp2p-webrtc-star/src/signalling')
1616

1717
let swarmA
1818
let swarmB
1919
let sigS
2020

21+
const options = {
22+
port: 15555,
23+
host: '127.0.0.1'
24+
}
25+
2126
gulp.task('test:browser:before', (done) => {
2227
function createListenerA (cb) {
2328
PeerId.createFromJSON(
@@ -70,7 +75,7 @@ gulp.task('test:browser:before', (done) => {
7075

7176
createListenerA(ready)
7277
createListenerB(ready)
73-
sigS = sigServer.start(15555, ready)
78+
sigS = sigServer.start(options, ready)
7479

7580
function echo (protocol, conn) {
7681
pull(conn, conn)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"libp2p-secio": "^0.6.3",
4646
"libp2p-spdy": "^0.10.0",
4747
"libp2p-tcp": "^0.9.1",
48-
"libp2p-webrtc-star": "^0.6.0",
48+
"libp2p-webrtc-star": "^0.7.0",
4949
"libp2p-websockets": "^0.9.1",
5050
"pre-commit": "^1.1.3",
5151
"pull-goodbye": "0.0.1",
@@ -78,4 +78,4 @@
7878
"Richard Littauer <[email protected]>",
7979
"Sid Harder <[email protected]>"
8080
]
81-
}
81+
}

src/transport.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ module.exports = function (swarm) {
4141
// b) if multiaddrs.length = 1, return the conn from the
4242
// transport, otherwise, create a passthrough
4343
if (multiaddrs.length === 1) {
44-
const conn = t.dial(multiaddrs.shift())
45-
callback(null, new Connection(conn))
44+
const conn = t.dial(multiaddrs.shift(), (err) => {
45+
if (err) return callback(err)
46+
callback(null, new Connection(conn))
47+
})
4648
return
4749
}
4850

test/browser-01-transport-webrtc-star.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ describe('transport - webrtc-star', () => {
7575
)
7676
})
7777
})
78+
it('dial offline / non-existent node', (done) => {
79+
const mhOffline = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/ABCD')
80+
swarm1.transport.dial('wstar', mhOffline, (err, conn) => {
81+
expect(err).to.exist
82+
expect(conn).to.not.exist
83+
done()
84+
})
85+
})
7886

7987
it('close', (done) => {
8088
parallel([

0 commit comments

Comments
 (0)