mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-03 00:51:52 +00:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
ce4974b01c |
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,14 +1,7 @@
|
||||
**/node_modules/
|
||||
**/*.log
|
||||
test/repo-tests*
|
||||
**/bundle.js
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
coverage
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
@ -26,17 +19,11 @@ coverage
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
build
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
|
||||
lib
|
||||
dist
|
||||
test/test-data/go-ipfs-repo/LOCK
|
||||
test/test-data/go-ipfs-repo/LOG
|
||||
test/test-data/go-ipfs-repo/LOG.old
|
||||
|
||||
# while testing npm5
|
||||
package-lock.json
|
||||
docs
|
@ -27,3 +27,4 @@ build/Release
|
||||
node_modules
|
||||
|
||||
test
|
||||
docs
|
15
.travis.yml
15
.travis.yml
@ -1,20 +1,22 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- node_js: 4
|
||||
env: CXX=g++-4.8
|
||||
- node_js: 6
|
||||
env: CXX=g++-4.8
|
||||
- node_js: 8
|
||||
- node_js: stable
|
||||
env: CXX=g++-4.8
|
||||
# - node_js: stable
|
||||
# env: CXX=g++-4.8
|
||||
|
||||
# Make sure we have new NPM.
|
||||
before_install:
|
||||
- npm install -g npm
|
||||
|
||||
script:
|
||||
- npm run lint
|
||||
- npm run test
|
||||
- npm test
|
||||
- npm run coverage
|
||||
- make test
|
||||
|
||||
before_script:
|
||||
- export DISPLAY=:99.0
|
||||
@ -24,7 +26,6 @@ after_success:
|
||||
- npm run coverage-publish
|
||||
|
||||
addons:
|
||||
firefox: 'latest'
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
@ -7,7 +7,7 @@
|
||||
[](https://david-dm.org/libp2p/js-libp2p-tcp)
|
||||
[](https://github.com/feross/standard)
|
||||

|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
@ -5,10 +5,8 @@ machine:
|
||||
dependencies:
|
||||
pre:
|
||||
- google-chrome --version
|
||||
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
||||
- sudo dpkg -i google-chrome.deb || true
|
||||
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
|
||||
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install -f
|
||||
- sudo apt-get install --only-upgrade lsb-base
|
||||
- sudo dpkg -i google-chrome.deb
|
||||
- sudo apt-get --only-upgrade install google-chrome-stable
|
||||
- google-chrome --version
|
||||
|
38
package.json
38
package.json
@ -1,14 +1,15 @@
|
||||
{
|
||||
"name": "libp2p-tcp",
|
||||
"version": "0.11.0",
|
||||
"version": "0.9.1",
|
||||
"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": {
|
||||
"lint": "aegir-lint",
|
||||
"test": "aegir-test --env node",
|
||||
"release": "aegir-release --env no-build",
|
||||
"release-minor": "aegir-release --type minor --env no-build",
|
||||
"release-major": "aegir-release --type major --env no-build",
|
||||
"docs": "aegir-docs",
|
||||
"release": "aegir-release --env no-build --docs",
|
||||
"release-minor": "aegir-release --type minor --env no-build --docs",
|
||||
"release-major": "aegir-release --type major --env no-build --docs",
|
||||
"coverage": "aegir-coverage",
|
||||
"coverage-publish": "aegir-coverage publish"
|
||||
},
|
||||
@ -30,36 +31,31 @@
|
||||
},
|
||||
"homepage": "https://github.com/libp2p/js-libp2p-tcp",
|
||||
"engines": {
|
||||
"node": ">=6.0.0",
|
||||
"npm": ">=3.0.0"
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^11.0.2",
|
||||
"chai": "^4.1.2",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"interface-transport": "~0.3.5",
|
||||
"aegir": "^9.2.0",
|
||||
"chai": "^3.5.0",
|
||||
"interface-transport": "^0.3.3",
|
||||
"lodash.isfunction": "^3.0.8",
|
||||
"pre-commit": "^1.2.2",
|
||||
"pull-stream": "^3.6.0"
|
||||
"pre-commit": "^1.1.3",
|
||||
"pull-stream": "^3.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"interface-connection": "~0.3.2",
|
||||
"ip-address": "^5.8.8",
|
||||
"interface-connection": "0.3.0",
|
||||
"ip-address": "^5.8.2",
|
||||
"lodash.includes": "^4.3.0",
|
||||
"lodash.isfunction": "^3.0.8",
|
||||
"mafmt": "^3.0.0",
|
||||
"multiaddr": "^3.0.0",
|
||||
"once": "^1.4.0",
|
||||
"mafmt": "^2.1.2",
|
||||
"multiaddr": "^2.1.1",
|
||||
"stream-to-pull-stream": "^1.7.2"
|
||||
},
|
||||
"contributors": [
|
||||
"David Dias <daviddias.p@gmail.com>",
|
||||
"Evan Schwartz <evan.mark.schwartz@gmail.com>",
|
||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
"Greenkeeper <support@greenkeeper.io>",
|
||||
"João Antunes <j.goncalo.antunes@gmail.com>",
|
||||
"Prashanth Chandra <coolshanth94@gmail.com>",
|
||||
"Richard Littauer <richard.littauer@gmail.com>",
|
||||
"Stephen Whitmore <stephen.whitmore@gmail.com>"
|
||||
"Stephen Whitmore <stephen.whitmore@gmail.com>",
|
||||
"greenkeeperio-bot <support@greenkeeper.io>"
|
||||
]
|
||||
}
|
@ -4,7 +4,7 @@ const multiaddr = require('multiaddr')
|
||||
const Address6 = require('ip-address').Address6
|
||||
|
||||
module.exports = (socket) => {
|
||||
let mh
|
||||
var mh
|
||||
|
||||
if (socket.remoteFamily === 'IPv6') {
|
||||
var addr = new Address6(socket.remoteAddress)
|
||||
|
46
src/index.js
46
src/index.js
@ -6,52 +6,61 @@ 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')
|
||||
|
||||
const createListener = require('./listener')
|
||||
|
||||
function noop () {}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class TCP {
|
||||
/**
|
||||
* Dial to another peer.
|
||||
*
|
||||
* @param {Multiaddr} ma - The address of the peer we want to dial to.
|
||||
* @param {Object} [options={}]
|
||||
* @param {function(Error?, Array<Multiaddr>?)} [callback]
|
||||
* @returns {Connection}
|
||||
*/
|
||||
dial (ma, options, callback) {
|
||||
if (isFunction(options)) {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
callback = callback || noop
|
||||
if (!callback) {
|
||||
callback = () => {}
|
||||
}
|
||||
|
||||
callback = once(callback)
|
||||
const cOpts = ma.toOptions()
|
||||
log('Connecting to %s %s', cOpts.port, cOpts.host)
|
||||
|
||||
const rawSocket = net.connect(cOpts)
|
||||
const rawSocket = net.connect(cOpts, callback)
|
||||
|
||||
rawSocket.once('timeout', () => {
|
||||
log('timeout')
|
||||
rawSocket.emit('error', new Error('Timeout'))
|
||||
})
|
||||
|
||||
rawSocket.once('error', callback)
|
||||
|
||||
rawSocket.once('connect', () => {
|
||||
rawSocket.removeListener('error', callback)
|
||||
callback()
|
||||
})
|
||||
|
||||
const socket = toPull.duplex(rawSocket)
|
||||
|
||||
const conn = new Connection(socket)
|
||||
|
||||
conn.getObservedAddrs = (callback) => {
|
||||
return callback(null, [ma])
|
||||
conn.getObservedAddrs = (cb) => {
|
||||
return cb(null, [ma])
|
||||
}
|
||||
|
||||
return conn
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for incoming `TCP` connetions.
|
||||
*
|
||||
* @param {Object} [options={}]
|
||||
* @param {function(Connection)} [handler] - Called with newly incomin connections.
|
||||
* @returns {Listener}
|
||||
*/
|
||||
createListener (options, handler) {
|
||||
if (isFunction(options)) {
|
||||
handler = options
|
||||
@ -63,6 +72,13 @@ class TCP {
|
||||
return createListener(handler)
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of multiaddrs for those which contain
|
||||
* valid `TCP` addresses.
|
||||
*
|
||||
* @param {Multiaddr|Array<Multiaddr>} multiaddrs
|
||||
* @returns {Array<Multiaddr>}
|
||||
*/
|
||||
filter (multiaddrs) {
|
||||
if (!Array.isArray(multiaddrs)) {
|
||||
multiaddrs = [multiaddrs]
|
||||
|
@ -15,22 +15,58 @@ const getMultiaddr = require('./get-multiaddr')
|
||||
const IPFS_CODE = 421
|
||||
const CLOSE_TIMEOUT = 2000
|
||||
|
||||
function noop () {}
|
||||
/**
|
||||
* Listening for incoming connections.
|
||||
*
|
||||
* @event listening
|
||||
* @instance
|
||||
* @memberof Listener
|
||||
*/
|
||||
|
||||
/**
|
||||
* The server closes.
|
||||
*
|
||||
* @event close
|
||||
* @instance
|
||||
* @memberof Listener
|
||||
*/
|
||||
|
||||
/**
|
||||
* New connection established.
|
||||
*
|
||||
* @event connection
|
||||
* @instance
|
||||
* @type {Connection}
|
||||
* @memberof Listener
|
||||
*/
|
||||
|
||||
/**
|
||||
* The underlying server encountered an error.
|
||||
*
|
||||
* @event error
|
||||
* @instance
|
||||
* @type {Error}
|
||||
* @memberof Listener
|
||||
*/
|
||||
|
||||
module.exports = (handler) => {
|
||||
/**
|
||||
* @alias Listener
|
||||
* @type {Eventemitter}
|
||||
* @fires Listener#listening
|
||||
* @fires Listener#close
|
||||
* @fires Listener#connection
|
||||
* @fires Listener#error
|
||||
*/
|
||||
const listener = new EventEmitter()
|
||||
|
||||
const server = net.createServer((socket) => {
|
||||
// Avoid uncaught errors cause by unstable connections
|
||||
socket.on('error', noop)
|
||||
|
||||
const addr = getMultiaddr(socket)
|
||||
log('new connection', addr.toString())
|
||||
|
||||
const s = toPull.duplex(socket)
|
||||
|
||||
s.getObservedAddrs = (cb) => {
|
||||
cb(null, [addr])
|
||||
return cb(null, [addr])
|
||||
}
|
||||
|
||||
trackSocket(server, socket)
|
||||
@ -40,31 +76,36 @@ module.exports = (handler) => {
|
||||
listener.emit('connection', conn)
|
||||
})
|
||||
|
||||
server.on('listening', () => listener.emit('listening'))
|
||||
server.on('error', (err) => listener.emit('error', err))
|
||||
server.on('close', () => listener.emit('close'))
|
||||
server.on('listening', () => {
|
||||
listener.emit('listening')
|
||||
})
|
||||
|
||||
server.on('error', (err) => {
|
||||
listener.emit('error', err)
|
||||
})
|
||||
|
||||
server.on('close', () => {
|
||||
listener.emit('close')
|
||||
})
|
||||
|
||||
// Keep track of open connections to destroy in case of timeout
|
||||
server.__connections = {}
|
||||
|
||||
listener.close = (options, callback) => {
|
||||
listener.close = (options, cb) => {
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
cb = options
|
||||
options = {}
|
||||
}
|
||||
callback = callback || noop
|
||||
cb = cb || (() => {})
|
||||
options = options || {}
|
||||
|
||||
let closed = false
|
||||
server.close(callback)
|
||||
|
||||
server.close(cb)
|
||||
server.once('close', () => {
|
||||
closed = true
|
||||
})
|
||||
setTimeout(() => {
|
||||
if (closed) {
|
||||
return
|
||||
}
|
||||
if (closed) return
|
||||
|
||||
log('unable to close graciously, destroying conns')
|
||||
Object.keys(server.__connections).forEach((key) => {
|
||||
@ -77,7 +118,7 @@ module.exports = (handler) => {
|
||||
let ipfsId
|
||||
let listeningAddr
|
||||
|
||||
listener.listen = (ma, callback) => {
|
||||
listener.listen = (ma, cb) => {
|
||||
listeningAddr = ma
|
||||
if (includes(ma.protoNames(), 'ipfs')) {
|
||||
ipfsId = getIpfsId(ma)
|
||||
@ -86,15 +127,15 @@ module.exports = (handler) => {
|
||||
|
||||
const lOpts = listeningAddr.toOptions()
|
||||
log('Listening on %s %s', lOpts.port, lOpts.host)
|
||||
return server.listen(lOpts.port, lOpts.host, callback)
|
||||
return server.listen(lOpts.port, lOpts.host, cb)
|
||||
}
|
||||
|
||||
listener.getAddrs = (callback) => {
|
||||
listener.getAddrs = (cb) => {
|
||||
const multiaddrs = []
|
||||
const address = server.address()
|
||||
|
||||
if (!address) {
|
||||
return callback(new Error('Listener is not ready yet'))
|
||||
return cb(new Error('Listener is not ready yet'))
|
||||
}
|
||||
|
||||
// Because TCP will only return the IPv6 version
|
||||
@ -129,7 +170,7 @@ module.exports = (handler) => {
|
||||
multiaddrs.push(ma)
|
||||
}
|
||||
|
||||
callback(null, multiaddrs)
|
||||
cb(null, multiaddrs)
|
||||
}
|
||||
|
||||
return listener
|
||||
|
@ -2,10 +2,7 @@
|
||||
'use strict'
|
||||
|
||||
const pull = require('pull-stream')
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
const expect = require('chai').expect
|
||||
const TCP = require('../src')
|
||||
const net = require('net')
|
||||
const multiaddr = require('multiaddr')
|
||||
@ -14,7 +11,7 @@ const Connection = require('interface-connection').Connection
|
||||
describe('instantiate the transport', () => {
|
||||
it('create', () => {
|
||||
const tcp = new TCP()
|
||||
expect(tcp).to.exist()
|
||||
expect(tcp).to.exist
|
||||
})
|
||||
})
|
||||
|
||||
@ -74,7 +71,7 @@ describe('listen', () => {
|
||||
const listener = tcp.createListener((conn) => {})
|
||||
listener.listen(mh, () => {
|
||||
listener.getAddrs((err, multiaddrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(multiaddrs.length).to.equal(1)
|
||||
expect(multiaddrs[0]).to.deep.equal(mh)
|
||||
listener.close(done)
|
||||
@ -87,7 +84,7 @@ describe('listen', () => {
|
||||
const listener = tcp.createListener((conn) => {})
|
||||
listener.listen(mh, () => {
|
||||
listener.getAddrs((err, multiaddrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(multiaddrs.length).to.equal(1)
|
||||
listener.close(done)
|
||||
})
|
||||
@ -99,7 +96,7 @@ describe('listen', () => {
|
||||
const listener = tcp.createListener((conn) => {})
|
||||
listener.listen(mh, () => {
|
||||
listener.getAddrs((err, multiaddrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(multiaddrs.length > 0).to.equal(true)
|
||||
expect(multiaddrs[0].toString().indexOf('0.0.0.0')).to.equal(-1)
|
||||
listener.close(done)
|
||||
@ -112,7 +109,7 @@ describe('listen', () => {
|
||||
const listener = tcp.createListener((conn) => {})
|
||||
listener.listen(mh, () => {
|
||||
listener.getAddrs((err, multiaddrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(multiaddrs.length > 0).to.equal(true)
|
||||
expect(multiaddrs[0].toString().indexOf('0.0.0.0')).to.equal(-1)
|
||||
listener.close(done)
|
||||
@ -125,7 +122,7 @@ describe('listen', () => {
|
||||
const listener = tcp.createListener((conn) => {})
|
||||
listener.listen(mh, () => {
|
||||
listener.getAddrs((err, multiaddrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(multiaddrs.length).to.equal(1)
|
||||
expect(multiaddrs[0]).to.deep.equal(mh)
|
||||
listener.close(done)
|
||||
@ -160,8 +157,12 @@ describe('dial', () => {
|
||||
pull.values(['hey']),
|
||||
tcp.dial(ma),
|
||||
pull.collect((err, values) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(values).to.eql([new Buffer('hey!')])
|
||||
expect(err).to.not.exist
|
||||
expect(
|
||||
values
|
||||
).to.be.eql(
|
||||
[new Buffer('hey!')]
|
||||
)
|
||||
done()
|
||||
})
|
||||
)
|
||||
@ -172,7 +173,7 @@ describe('dial', () => {
|
||||
pull(
|
||||
tcp.dial(ma),
|
||||
pull.onEnd((err) => {
|
||||
expect(err).to.exist()
|
||||
expect(err).to.exist
|
||||
done()
|
||||
})
|
||||
)
|
||||
@ -188,9 +189,13 @@ describe('dial', () => {
|
||||
pull.values(['hey']),
|
||||
tcp.dial(ma),
|
||||
pull.collect((err, values) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
|
||||
expect(values).to.be.eql([new Buffer('hey')])
|
||||
expect(
|
||||
values
|
||||
).to.be.eql([
|
||||
new Buffer('hey')
|
||||
])
|
||||
|
||||
listener.close(done)
|
||||
})
|
||||
@ -253,7 +258,7 @@ describe('dial', () => {
|
||||
pull.values(['hey']),
|
||||
conn,
|
||||
pull.collect((err, res) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(res).to.be.eql([new Buffer('hey!')])
|
||||
done()
|
||||
})
|
||||
@ -302,9 +307,9 @@ describe('valid Connection', () => {
|
||||
let dialerObsAddrs
|
||||
|
||||
const listener = tcp.createListener((conn) => {
|
||||
expect(conn).to.exist()
|
||||
expect(conn).to.exist
|
||||
conn.getObservedAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
dialerObsAddrs = addrs
|
||||
pull(pull.empty(), conn)
|
||||
})
|
||||
@ -319,7 +324,7 @@ describe('valid Connection', () => {
|
||||
|
||||
function endHandler () {
|
||||
conn.getObservedAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
pull(pull.empty(), conn)
|
||||
closeAndAssert(listener, addrs)
|
||||
})
|
||||
@ -337,10 +342,10 @@ describe('valid Connection', () => {
|
||||
|
||||
it('get Peer Info', (done) => {
|
||||
const listener = tcp.createListener((conn) => {
|
||||
expect(conn).to.exist()
|
||||
expect(conn).to.exist
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.exist()
|
||||
expect(peerInfo).to.not.exist()
|
||||
expect(err).to.exist
|
||||
expect(peerInfo).to.not.exist
|
||||
pull(pull.empty(), conn)
|
||||
})
|
||||
})
|
||||
@ -351,8 +356,8 @@ describe('valid Connection', () => {
|
||||
pull(conn, pull.onEnd(endHandler))
|
||||
function endHandler () {
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.exist()
|
||||
expect(peerInfo).to.not.exist()
|
||||
expect(err).to.exist
|
||||
expect(peerInfo).to.not.exist
|
||||
|
||||
listener.close(done)
|
||||
})
|
||||
@ -362,10 +367,10 @@ describe('valid Connection', () => {
|
||||
|
||||
it('set Peer Info', (done) => {
|
||||
const listener = tcp.createListener((conn) => {
|
||||
expect(conn).to.exist()
|
||||
expect(conn).to.exist
|
||||
conn.setPeerInfo('batatas')
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(peerInfo).to.equal('batatas')
|
||||
pull(pull.empty(), conn)
|
||||
})
|
||||
@ -378,7 +383,7 @@ describe('valid Connection', () => {
|
||||
function endHandler () {
|
||||
conn.setPeerInfo('arroz')
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(peerInfo).to.equal('arroz')
|
||||
|
||||
listener.close(done)
|
||||
@ -419,11 +424,11 @@ describe('Connection wrap', () => {
|
||||
pull.values(['hey']),
|
||||
connWrap,
|
||||
pull.collect((err, chunks) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(chunks).to.be.eql([new Buffer('hey')])
|
||||
|
||||
connWrap.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(peerInfo).to.equal('peerInfo')
|
||||
done()
|
||||
})
|
||||
@ -438,7 +443,7 @@ describe('Connection wrap', () => {
|
||||
pull.values(['hey']),
|
||||
connWrap,
|
||||
pull.collect((err, chunks) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(chunks).to.be.eql([new Buffer('hey')])
|
||||
done()
|
||||
})
|
||||
@ -454,30 +459,23 @@ describe('Connection wrap', () => {
|
||||
callback(null, 'none')
|
||||
}
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.exist()
|
||||
expect(err).to.exist
|
||||
})
|
||||
connWrap.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(peerInfo).to.equal('none')
|
||||
})
|
||||
pull(
|
||||
pull.values(['hey']),
|
||||
connWrap,
|
||||
pull.collect((err, chunks) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(chunks).to.be.eql([new Buffer('hey')])
|
||||
done()
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
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)
|
||||
@ -491,10 +489,10 @@ describe('Connection wrap', () => {
|
||||
pull.values(['hey']),
|
||||
connWrap3,
|
||||
pull.collect((err, chunks) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(chunks).to.be.eql([new Buffer('hey')])
|
||||
connWrap3.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(err).to.not.exist
|
||||
expect(peerInfo).to.equal('inner doll')
|
||||
done()
|
||||
})
|
||||
|
Reference in New Issue
Block a user