Compare commits

...

5 Commits

Author SHA1 Message Date
4694f9dd47 chore: release version v0.10.0 2017-03-27 16:21:35 +01:00
dd6e067125 chore: update contributors 2017-03-27 16:21:34 +01:00
fb382a3e2a codestyle: fix linting 2017-03-27 16:21:26 +01:00
fd741367a2 chore: update deps 2017-03-27 16:19:30 +01:00
4d4f295dd5 fix(dial): proper error handling on dial (#77) 2017-03-27 16:18:55 +01:00
3 changed files with 22 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "libp2p-tcp",
"version": "0.9.4",
"version": "0.10.0",
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
"main": "src/index.js",
"scripts": {
@ -33,7 +33,7 @@
"node": ">=4.0.0"
},
"devDependencies": {
"aegir": "^11.0.0",
"aegir": "^11.0.1",
"chai": "^3.5.0",
"dirty-chai": "^1.2.2",
"interface-transport": "~0.3.5",
@ -46,8 +46,9 @@
"ip-address": "^5.8.6",
"lodash.includes": "^4.3.0",
"lodash.isfunction": "^3.0.8",
"mafmt": "^2.1.6",
"multiaddr": "^2.2.2",
"mafmt": "^2.1.7",
"multiaddr": "^2.2.3",
"once": "^1.4.0",
"stream-to-pull-stream": "^1.7.2"
},
"contributors": [

View File

@ -6,6 +6,7 @@ const mafmt = require('mafmt')
const includes = require('lodash.includes')
const isFunction = require('lodash.isfunction')
const Connection = require('interface-connection').Connection
const once = require('once')
const debug = require('debug')
const log = debug('libp2p:tcp:dial')
@ -22,16 +23,23 @@ module.exports = class TCP {
cb = () => {}
}
cb = once(cb)
const cOpts = ma.toOptions()
log('Connecting to %s %s', cOpts.port, cOpts.host)
const rawSocket = net.connect(cOpts, cb)
const rawSocket = net.connect(cOpts)
rawSocket.once('timeout', () => {
log('timeout')
rawSocket.emit('error', new Error('Timeout'))
})
rawSocket.once('error', cb)
rawSocket.once('connect', () => {
rawSocket.removeListener('error', cb)
cb()
})
const socket = toPull.duplex(rawSocket)
const conn = new Connection(socket)

View File

@ -471,6 +471,13 @@ describe('Connection wrap', () => {
)
})
it('dial error', (done) => {
tcp.dial(multiaddr('/ip4/999.0.0.1/tcp/1234'), (err) => {
expect(err).to.exist()
done()
})
})
it('matryoshka wrap', (done) => {
const conn = tcp.dial(ma)
const connWrap1 = new Connection(conn)