feat(readme): add pull-streams documentation

This commit is contained in:
David Dias
2016-08-31 06:41:34 -04:00
parent 5e89a2608b
commit d9f65e0b0c
6 changed files with 111 additions and 34 deletions

View File

@ -7,7 +7,7 @@ const contains = require('lodash.contains')
const isFunction = require('lodash.isfunction')
const Connection = require('interface-connection').Connection
const debug = require('debug')
const log = debug('libp2p:tcp')
const log = debug('libp2p:tcp:dial')
const createListener = require('./listener')
@ -24,13 +24,23 @@ module.exports = class TCP {
const cOpts = ma.toOptions()
log('Connecting to %s %s', cOpts.port, cOpts.host)
const socket = toPull.duplex(net.connect(cOpts, cb))
socket.getObservedAddrs = (cb) => {
const rawSocket = net.connect(cOpts, cb)
rawSocket.once('timeout', () => {
log('timeout')
rawSocket.emit('error', new Error('Timeout'))
})
const socket = toPull.duplex(rawSocket)
const conn = new Connection(socket)
conn.getObservedAddrs = (cb) => {
return cb(null, [ma])
}
return new Connection(socket)
return conn
}
createListener (options, handler) {
@ -39,6 +49,8 @@ module.exports = class TCP {
options = {}
}
handler = handler || (() => {})
return createListener(handler)
}