mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-04-25 21:32:21 +00:00
refactor: use aegir
This commit is contained in:
parent
11c46ac995
commit
3f4f163f40
3
.gitignore
vendored
3
.gitignore
vendored
@ -25,3 +25,6 @@ build/Release
|
|||||||
# Dependency directory
|
# Dependency directory
|
||||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
lib
|
||||||
|
dist
|
29
.npmignore
Normal file
29
.npmignore
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
test
|
16
.travis.yml
16
.travis.yml
@ -1,11 +1,25 @@
|
|||||||
sudo: false
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "4.0"
|
- 4
|
||||||
|
- 5
|
||||||
|
- stable
|
||||||
|
|
||||||
# Make sure we have new NPM.
|
# Make sure we have new NPM.
|
||||||
before_install:
|
before_install:
|
||||||
- npm install -g npm
|
- npm install -g npm
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- npm run lint
|
||||||
- npm test
|
- npm test
|
||||||
|
- npm run coverage
|
||||||
|
|
||||||
|
addons:
|
||||||
|
firefox: 'latest'
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- export DISPLAY=:99.0
|
||||||
|
- sh -e /etc/init.d/xvfb start
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- npm run coverage-publish
|
||||||
|
14
circle.yml
14
circle.yml
@ -1,8 +1,12 @@
|
|||||||
dependencies:
|
|
||||||
pre:
|
|
||||||
# setup ipv6
|
|
||||||
- sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0 net.ipv6.conf.default.disable_ipv6=0 net.ipv6.conf.all.disable_ipv6=0
|
|
||||||
|
|
||||||
machine:
|
machine:
|
||||||
node:
|
node:
|
||||||
version: stable
|
version: stable
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
pre:
|
||||||
|
- google-chrome --version
|
||||||
|
- 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 --only-upgrade install google-chrome-stable
|
||||||
|
- google-chrome --version
|
||||||
|
26
package.json
26
package.json
@ -2,14 +2,17 @@
|
|||||||
"name": "libp2p-tcp",
|
"name": "libp2p-tcp",
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
||||||
"main": "src/index.js",
|
"main": "lib/index.js",
|
||||||
|
"jsnext:main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:compliance:connection": "node tests/connection.js",
|
"lint": "aegir-lint",
|
||||||
"test:compliance:transport": "node tests/transport.js",
|
"build": "aegir-build --env node",
|
||||||
"test:specific": "mocha tests/*-test.js",
|
"test": "aegir-test --env node",
|
||||||
"test": "npm run test:specific",
|
"release": "aegir-release --env node",
|
||||||
"test-2": "npm run test:specific && npm run test:compliance:transport && npm run test:compliance:connection",
|
"release-minor": "aegir-release --type minor",
|
||||||
"lint": "standard"
|
"release-major": "aegir-release --type major",
|
||||||
|
"coverage": "aegir-coverage",
|
||||||
|
"coverage-publish": "aegir-coverage publish"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint",
|
"lint",
|
||||||
@ -29,18 +32,17 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/diasdavid/js-libp2p-tcp",
|
"homepage": "https://github.com/diasdavid/js-libp2p-tcp",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"aegir": "^3.0.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"interface-connection": "0.0.3",
|
"interface-connection": "0.0.3",
|
||||||
"interface-transport": "^0.1.1",
|
"interface-transport": "^0.1.1",
|
||||||
"istanbul": "^0.4.2",
|
|
||||||
"mocha": "^2.4.5",
|
|
||||||
"pre-commit": "^1.1.2",
|
"pre-commit": "^1.1.2",
|
||||||
"standard": "^6.0.7",
|
"tape": "^4.5.1"
|
||||||
"tape": "^4.2.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ip-address": "^5.8.0",
|
"ip-address": "^5.8.0",
|
||||||
"mafmt": "^1.0.1",
|
"mafmt": "^1.0.1",
|
||||||
"multiaddr": "^1.1.1"
|
"multiaddr": "^1.1.1",
|
||||||
|
"run-parallel": "^1.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/index.js
25
src/index.js
@ -1,9 +1,12 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
const debug = require('debug')
|
const debug = require('debug')
|
||||||
const log = debug('libp2p:tcp')
|
const log = debug('libp2p:tcp')
|
||||||
const tcp = require('net')
|
const tcp = require('net')
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
const Address6 = require('ip-address').Address6
|
const Address6 = require('ip-address').Address6
|
||||||
const mafmt = require('mafmt')
|
const mafmt = require('mafmt')
|
||||||
|
const parallel = require('run-parallel')
|
||||||
|
|
||||||
exports = module.exports = TCP
|
exports = module.exports = TCP
|
||||||
|
|
||||||
@ -31,10 +34,9 @@ function TCP () {
|
|||||||
multiaddrs = [multiaddrs]
|
multiaddrs = [multiaddrs]
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = 0
|
|
||||||
const freshMultiaddrs = []
|
const freshMultiaddrs = []
|
||||||
|
|
||||||
multiaddrs.forEach((m) => {
|
parallel(multiaddrs.map((m) => (cb) => {
|
||||||
const listener = tcp.createServer((conn) => {
|
const listener = tcp.createServer((conn) => {
|
||||||
conn.getObservedAddrs = () => {
|
conn.getObservedAddrs = () => {
|
||||||
return [getMultiaddr(conn)]
|
return [getMultiaddr(conn)]
|
||||||
@ -49,15 +51,16 @@ function TCP () {
|
|||||||
m = m.encapsulate('/tcp/' + address.port)
|
m = m.encapsulate('/tcp/' + address.port)
|
||||||
freshMultiaddrs.push(m)
|
freshMultiaddrs.push(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (address.family === 'IPv6') {
|
if (address.family === 'IPv6') {
|
||||||
freshMultiaddrs.push(multiaddr('/ip6/' + address.address + '/tcp/' + address.port))
|
freshMultiaddrs.push(multiaddr('/ip6/' + address.address + '/tcp/' + address.port))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++count === multiaddrs.length) {
|
cb()
|
||||||
callback(null, freshMultiaddrs)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
listeners.push(listener)
|
listeners.push(listener)
|
||||||
|
}), (err) => {
|
||||||
|
callback(err, freshMultiaddrs)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,14 +69,10 @@ function TCP () {
|
|||||||
log('Called close with no active listeners')
|
log('Called close with no active listeners')
|
||||||
return callback()
|
return callback()
|
||||||
}
|
}
|
||||||
var count = 0
|
|
||||||
listeners.forEach((listener) => {
|
parallel(listeners.map((listener) => {
|
||||||
listener.close(() => {
|
return (cb) => listener.close(cb)
|
||||||
if (++count === listeners.length && callback) {
|
}), callback)
|
||||||
callback()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filter = (multiaddrs) => {
|
this.filter = (multiaddrs) => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
const expect = require('chai').expect
|
const expect = require('chai').expect
|
||||||
const TCPlibp2p = require('../src')
|
const TCPlibp2p = require('../src')
|
23
test/interface-transport.spec.js
Normal file
23
test/interface-transport.spec.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const tape = require('tape')
|
||||||
|
const tests = require('interface-transport/tests')
|
||||||
|
const TCP = require('../src')
|
||||||
|
|
||||||
|
// Not adhering to this interface anymore!
|
||||||
|
describe.skip('interface-transport', () => {
|
||||||
|
it('works', (done) => {
|
||||||
|
const common = {
|
||||||
|
setup (t, cb) {
|
||||||
|
cb(null, new TCP())
|
||||||
|
},
|
||||||
|
teardown (t, cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tape.onFinish(done)
|
||||||
|
tests(tape, common)
|
||||||
|
})
|
||||||
|
})
|
@ -1,14 +0,0 @@
|
|||||||
var tape = require('tape')
|
|
||||||
var tests = require('interface-transport/tests')
|
|
||||||
var conn = require('../src')
|
|
||||||
|
|
||||||
var common = {
|
|
||||||
setup: function (t, cb) {
|
|
||||||
cb(null, conn)
|
|
||||||
},
|
|
||||||
teardown: function (t, cb) {
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tests(tape, common)
|
|
Loading…
x
Reference in New Issue
Block a user