mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-05 18:41:41 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
4694f9dd47 | |||
dd6e067125 | |||
fb382a3e2a | |||
fd741367a2 | |||
4d4f295dd5 |
@ -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": [
|
||||
|
12
src/index.js
12
src/index.js
@ -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)
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user