From 5b6cdb9cba6c2025812e1bbbd62b05df5fbab227 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Wed, 2 Nov 2016 13:17:22 +0100 Subject: [PATCH] ready --- .gitignore | 1 - .travis.yml | 24 +++++++++++---- README.md | 4 +++ package.json | 18 +++++------ src/index.js | 3 +- test/webrtc-star-only.js | 66 ++++++++++++++++++++++------------------ test/websockets-only.js | 9 ++++-- 7 files changed, 75 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index db2ff1a..c2ba637 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,4 @@ node_modules # Optional REPL history .node_repl_history -lib dist diff --git a/.travis.yml b/.travis.yml index 0c44ec8..4fe6550 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,15 @@ sudo: false language: node_js -node_js: - - 4 - - stable +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: @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index b7d5f4e..01d1baa 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ [![Travis CI](https://travis-ci.org/ipfs/js-libp2p-ipfs-browser.svg?branch=master)](https://travis-ci.org/ipfs/js-libp2p-ipfs-browser) [![Circle CI](https://circleci.com/gh/ipfs/js-libp2p-ipfs-browser.svg?style=svg)](https://circleci.com/gh/ipfs/js-libp2p-ipfs-browser) [![Dependency Status](https://david-dm.org/ipfs/js-libp2p-ipfs-browser.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-ipfs-browser) [![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-ipfs-browser.svg)](https://saucelabs.com/u/libp2p-ipfs-browser) > libp2p build (module) used in js-ipfs when running it on the browser. diff --git a/package.json b/package.json index dc148d7..97e16e8 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,20 @@ "name": "libp2p-ipfs-browser", "version": "0.15.1", "description": "libp2p build (module) used in js-ipfs when running it on the browser", - "main": "lib/index.js", - "jsnext:main": "src/index.js", + "main": "src/index.js", "pre-commit": [ "lint", "test" ], "scripts": { "lint": "aegir-lint", - "test": "PHANTOM=off gulp test", + "test": "gulp test", "test:node": "gulp test:node", - "test:browser": "PHANTOM=off gulp test:browser", + "test:browser": "gulp test:browser", "build": "gulp build", - "release": "PHANTOM=off gulp release", - "release-minor": "PHANTOM=off gulp release --type minor", - "release-major": "PHANTOM=off gulp release --type major", + "release": "gulp release", + "release-minor": "gulp release --type minor", + "release-major": "gulp release --type major", "coverage": "gulp coverage", "coverage-publish": "aegir-coverage publish" }, @@ -31,7 +30,8 @@ }, "homepage": "https://github.com/ipfs/js-libp2p-ipfs-browser#readme", "devDependencies": { - "aegir": "^8.0.1", + "aegir": "^9.0.0", + "async": "^2.1.2", "chai": "^3.5.0", "gulp": "^3.9.1", "libp2p-ipfs": "^0.14.1", @@ -40,11 +40,9 @@ "pull-goodbye": "0.0.1", "pull-serializer": "^0.3.2", "pull-stream": "^3.4.5", - "run-parallel": "^1.1.6", "webrtcsupport": "^2.2.0" }, "dependencies": { - "babel-runtime": "^6.11.6", "libp2p-secio": "^0.5.0", "libp2p-spdy": "^0.9.0", "libp2p-swarm": "^0.23.0", diff --git a/src/index.js b/src/index.js index 514c328..2bb3799 100644 --- a/src/index.js +++ b/src/index.js @@ -23,8 +23,7 @@ exports.Node = function Node (pInfo, pBook) { } if (!pInfo) { - pInfo = new PeerInfo() - pInfo.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0')) + throw new Error('missing peer info') } if (!pBook) { diff --git a/test/webrtc-star-only.js b/test/webrtc-star-only.js index f3e86f7..682a8da 100644 --- a/test/webrtc-star-only.js +++ b/test/webrtc-star-only.js @@ -4,8 +4,8 @@ const expect = require('chai').expect const multiaddr = require('multiaddr') const PeerInfo = require('peer-info') -const peerId = require('peer-id') -const parallel = require('run-parallel') +const PeerId = require('peer-id') +const parallel = require('async/parallel') const pull = require('pull-stream') const libp2p = require('../src') @@ -19,17 +19,22 @@ describe('libp2p-ipfs-browser (webrtc only)', function () { let node2 it('create two peerInfo with webrtc-star addrs', (done) => { - const id1 = peerId.create() - peer1 = new PeerInfo(id1) - const mh1 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id1.toB58String()) - peer1.multiaddr.add(mh1) + parallel([ + (cb) => PeerId.create(cb), + (cb) => PeerId.create(cb) + ], (err, ids) => { + expect(err).to.not.exist - const id2 = peerId.create() - peer2 = new PeerInfo(id2) - const mh2 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id2.toB58String()) - peer2.multiaddr.add(mh2) + peer1 = new PeerInfo(ids[0]) + const mh1 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + ids[0].toB58String()) + peer1.multiaddr.add(mh1) - done() + peer2 = new PeerInfo(ids[1]) + const mh2 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + ids[1].toB58String()) + peer2.multiaddr.add(mh2) + + done() + }) }) it('create two libp2p nodes with those peers', (done) => { @@ -95,25 +100,28 @@ describe('libp2p-ipfs-browser (webrtc only)', function () { }) it('create a third node and check that discovery works', (done) => { - const id3 = peerId.create() - const peer3 = new PeerInfo(id3) - const mh3 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3.toB58String()) - peer3.multiaddr.add(mh3) - - node1.discovery.on('peer', (peerInfo) => { - node1.dialByPeerInfo(peerInfo, () => {}) - }) - node2.discovery.on('peer', (peerInfo) => { - node2.dialByPeerInfo(peerInfo, () => {}) - }) + PeerId.create((err, id3) => { + expect(err).to.not.exist - const node3 = new libp2p.Node(peer3) - node3.start(() => { - setTimeout(() => { - expect(Object.keys(node1.swarm.muxedConns).length).to.equal(1) - expect(Object.keys(node2.swarm.muxedConns).length).to.equal(1) - done() - }, 2000) + const peer3 = new PeerInfo(id3) + const mh3 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3.toB58String()) + peer3.multiaddr.add(mh3) + + node1.discovery.on('peer', (peerInfo) => { + node1.dialByPeerInfo(peerInfo, () => {}) + }) + node2.discovery.on('peer', (peerInfo) => { + node2.dialByPeerInfo(peerInfo, () => {}) + }) + + const node3 = new libp2p.Node(peer3) + node3.start(() => { + setTimeout(() => { + expect(Object.keys(node1.swarm.muxedConns).length).to.equal(1) + expect(Object.keys(node2.swarm.muxedConns).length).to.equal(1) + done() + }, 2000) + }) }) }) }) diff --git a/test/websockets-only.js b/test/websockets-only.js index e77a695..4f725d8 100644 --- a/test/websockets-only.js +++ b/test/websockets-only.js @@ -34,8 +34,13 @@ describe('libp2p-ipfs-browser (websockets only)', () => { nodeA.stop(done) }) - it('create libp2pNode', () => { - nodeA = new libp2p.Node() + it('create libp2pNode', (done) => { + PeerInfo.create((err, info) => { + expect(err).to.not.exist + info.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0')) + nodeA = new libp2p.Node(info) + done() + }) }) it('start libp2pNode', (done) => {