Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
Async Crypto Endeavour (#108)
Browse files Browse the repository at this point in the history
* test: update to async peerid

* update to latest

* refactor: replace run-* with async

* cr - round1

* ready for next aegir

* update aegir

* ready

* chore: update of the deps
  • Loading branch information
dignifiedquire authored and daviddias committed Nov 3, 2016
1 parent 483a536 commit 0c1d887
Show file tree
Hide file tree
Showing 22 changed files with 1,289 additions and 270 deletions.
19 changes: 0 additions & 19 deletions .aegir.js

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ node_modules
coverage

dist
lib
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
sudo: false
language: node_js
node_js:
- 4
- 5
matrix:
include:
- node_js: 4
env: CXX=g++-4.8
- node_js: 6
env:
- SAUCE=true
- CXX=g++-4.8
- node_js: stable
env: CXX=g++-4.8

# Make sure we have new NPM.
before_install:
Expand All @@ -13,12 +20,17 @@ script:
- 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

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ libp2p-swarm JavaScript implementation
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-swarm/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-swarm?branch=master)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-swarm.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-swarm)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/libp2p-js-swarm.svg)](https://saucelabs.com/u/libp2p-js-swarm)

> libp2p swarm implementation in JavaScript.
Expand Down
68 changes: 40 additions & 28 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,49 @@ let sigS

gulp.task('test:browser:before', (done) => {
function createListenerA (cb) {
const id = PeerId.createFromJSON(
JSON.parse(
fs.readFileSync(
path.join(__dirname, './test/test-data/id-1.json'))))

const peerA = new PeerInfo(id)
const maA = multiaddr('/ip4/127.0.0.1/tcp/9100/ws')

peerA.multiaddr.add(maA)
swarmA = new Swarm(peerA)
swarmA.transport.add('ws', new WebSockets())
swarmA.transport.listen('ws', {}, echo, cb)
PeerId.createFromJSON(
JSON.parse(
fs.readFileSync(
path.join(__dirname, './test/test-data/id-1.json'))
),
(err, id) => {
if (err) {
return cb(err)
}

const peerA = new PeerInfo(id)
const maA = multiaddr('/ip4/127.0.0.1/tcp/9100/ws')

peerA.multiaddr.add(maA)
swarmA = new Swarm(peerA)
swarmA.transport.add('ws', new WebSockets())
swarmA.transport.listen('ws', {}, echo, cb)
})
}

function createListenerB (cb) {
const id = PeerId.createFromJSON(
JSON.parse(
fs.readFileSync(
path.join(__dirname, './test/test-data/id-2.json'))))

const peerB = new PeerInfo(id)
const maB = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')

peerB.multiaddr.add(maB)
swarmB = new Swarm(peerB)

swarmB.transport.add('ws', new WebSockets())
swarmB.connection.addStreamMuxer(spdy)
swarmB.connection.reuse()
swarmB.listen(cb)
swarmB.handle('/echo/1.0.0', echo)
PeerId.createFromJSON(
JSON.parse(
fs.readFileSync(
path.join(__dirname, './test/test-data/id-2.json'))
),
(err, id) => {
if (err) {
return cb(err)
}

const peerB = new PeerInfo(id)
const maB = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')

peerB.multiaddr.add(maB)
swarmB = new Swarm(peerB)

swarmB.transport.add('ws', new WebSockets())
swarmB.connection.addStreamMuxer(spdy)
swarmB.connection.reuse()
swarmB.listen(cb)
swarmB.handle('/echo/1.0.0', echo)
})
}

let count = 0
Expand Down
37 changes: 17 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "libp2p-swarm",
"version": "0.23.0",
"description": "libp2p swarm implementation in JavaScript",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"scripts": {
"lint": "gulp lint",
"build": "gulp build",
Expand Down Expand Up @@ -34,39 +33,37 @@
"test"
],
"engines": {
"node": "^4.3.0"
"node": ">=4.0.0"
},
"devDependencies": {
"aegir": "^8.0.0",
"aegir": "^9.0.1",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"libp2p-multiplex": "^0.2.1",
"libp2p-secio": "^0.5.0",
"libp2p-spdy": "^0.9.0",
"libp2p-tcp": "^0.8.1",
"libp2p-webrtc-star": "^0.4.4",
"libp2p-websockets": "^0.8.1",
"libp2p-secio": "^0.6.0",
"libp2p-spdy": "^0.10.0",
"libp2p-tcp": "^0.9.1",
"libp2p-webrtc-star": "^0.5.0",
"libp2p-websockets": "^0.9.0",
"pre-commit": "^1.1.3",
"pull-goodbye": "0.0.1",
"pull-stream": "^3.4.5",
"pull-stream": "^3.5.0",
"webrtcsupport": "^2.2.0"
},
"dependencies": {
"babel-runtime": "^6.11.6",
"async": "^2.1.2",
"browserify-zlib": "github:ipfs/browserify-zlib",
"debug": "^2.2.0",
"interface-connection": "^0.2.1",
"interface-connection": "^0.3.0",
"ip-address": "^5.8.2",
"libp2p-identify": "^0.2.0",
"libp2p-identify": "^0.3.0",
"lodash.includes": "^4.3.0",
"multiaddr": "^2.0.2",
"multistream-select": "^0.11.0",
"peer-id": "^0.7.0",
"peer-info": "^0.7.1",
"protocol-buffers": "^3.1.6",
"run-parallel": "^1.1.6",
"run-waterfall": "^1.1.3"
"multiaddr": "^2.0.3",
"multistream-select": "^0.11.1",
"peer-id": "^0.8.0",
"peer-info": "^0.8.0",
"protocol-buffers": "^3.1.6"
},
"contributors": [
"David Dias <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const identify = require('libp2p-identify')
const multistream = require('multistream-select')
const waterfall = require('run-waterfall')
const waterfall = require('async/waterfall')
const debug = require('debug')
const log = debug('libp2p:swarm:connection')

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const util = require('util')
const EE = require('events').EventEmitter
const parallel = require('run-parallel')
const parallel = require('async/parallel')
const includes = require('lodash.includes')

const transport = require('./transport')
Expand Down
2 changes: 1 addition & 1 deletion src/transport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Connection = require('interface-connection').Connection
const parallel = require('run-parallel')
const parallel = require('async/parallel')
const debug = require('debug')
const log = debug('libp2p:swarm:transport')

Expand Down
45 changes: 31 additions & 14 deletions test/01-transport-tcp.node.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
/* eslint-env mocha */

'use strict'

const expect = require('chai').expect
const parallel = require('run-parallel')
const parallel = require('async/parallel')
const multiaddr = require('multiaddr')
const Peer = require('peer-info')
const TCP = require('libp2p-tcp')
const pull = require('pull-stream')

const utils = require('./utils')
const Swarm = require('../src')

describe('transport - tcp', function () {
let swarmA
let swarmB
let peerA = new Peer()
let peerB = new Peer()

before(() => {
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9888'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9999'))
swarmA = new Swarm(peerA)
swarmB = new Swarm(peerB)
let peerA
let peerB

before((done) => {
utils.createInfos(2, (err, infos) => {
if (err) {
return done(err)
}
peerA = infos[0]
peerB = infos[1]

peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9888'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9999'))
swarmA = new Swarm(peerA)
swarmB = new Swarm(peerB)
done()
})
})

let peer
beforeEach((done) => {
Peer.create((err, info) => {
if (err) {
return done(err)
}

peer = info
done()
})
})

it('add', (done) => {
Expand Down Expand Up @@ -99,7 +120,6 @@ describe('transport - tcp', function () {

it('support port 0', (done) => {
let swarm
let peer = new Peer()
peer.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/0'))
swarm = new Swarm(peer)
swarm.transport.add('tcp', new TCP())
Expand All @@ -116,7 +136,6 @@ describe('transport - tcp', function () {

it('support addr /ip4/0.0.0.0/tcp/9050', (done) => {
let swarm
let peer = new Peer()
peer.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/9050'))
swarm = new Swarm(peer)
swarm.transport.add('tcp', new TCP())
Expand All @@ -137,7 +156,6 @@ describe('transport - tcp', function () {

it('support addr /ip4/0.0.0.0/tcp/0', (done) => {
let swarm
let peer = new Peer()
peer.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0'))
swarm = new Swarm(peer)
swarm.transport.add('tcp', new TCP())
Expand All @@ -154,7 +172,6 @@ describe('transport - tcp', function () {

it('listen in several addrs', (done) => {
let swarm
let peer = new Peer()
peer.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9001'))
peer.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002'))
peer.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9003'))
Expand Down
27 changes: 18 additions & 9 deletions test/03-transport-websockets.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@

const expect = require('chai').expect

const parallel = require('run-parallel')
const parallel = require('async/parallel')
const multiaddr = require('multiaddr')
const Peer = require('peer-info')
const WebSockets = require('libp2p-websockets')
const pull = require('pull-stream')
const goodbye = require('pull-goodbye')

const utils = require('./utils')
const Swarm = require('../src')

describe('transport - websockets', function () {
var swarmA
var swarmB
var peerA = new Peer()
var peerB = new Peer()
var peerA
var peerB

before(() => {
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9888/ws'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9999/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'))
swarmA = new Swarm(peerA)
swarmB = new Swarm(peerB)
before((done) => {
utils.createInfos(2, (err, infos) => {
if (err) {
return done(err)
}
peerA = infos[0]
peerB = infos[1]

peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9888/ws'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9999/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'))
swarmA = new Swarm(peerA)
swarmB = new Swarm(peerB)
done()
})
})

it('add', (done) => {
Expand Down
Loading

0 comments on commit 0c1d887

Please sign in to comment.