Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Async Crypto Endeavour #99

Merged
merged 8 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -32,5 +32,4 @@ node_modules
# Optional REPL history
.node_repl_history

lib
dist
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
- 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:
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 @@ -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.

Expand Down
37 changes: 22 additions & 15 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,41 @@
const gulp = require('gulp')
const multiaddr = require('multiaddr')
const Node = require('libp2p-ipfs').Node
const Peer = require('peer-info')
const Id = require('peer-id')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const pull = require('pull-stream')

const sigServer = require('libp2p-webrtc-star/src/signalling-server')
let sigS

let node
const rawPeer = require('./test/peer.json')
const id = Id.createFromPrivKey(rawPeer.privKey)

gulp.task('libnode:start', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
const peer = new Peer(id)
peer.multiaddr.add(mh)

node = new Node(peer)
node.start(() => {
node.handle('/echo/1.0.0', (conn) => {
pull(conn, conn)
})
ready()
})

let count = 0
const ready = () => ++count === 2 ? done() : null

sigS = sigServer.start(15555, ready)

PeerId.createFromJSON(rawPeer, gotId)

function gotId (err, pid) {
if (err) {
return done(err)
}
const peer = new PeerInfo(pid)

const ma = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
peer.multiaddr.add(ma)

node = new Node(peer)
node.start(() => {
node.handle('/echo/1.0.0', (protocol, conn) => {
pull(conn, conn)
})
ready()
})
}
})

gulp.task('libnode:stop', (done) => {
Expand Down
34 changes: 16 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
"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": {
"test": "gulp test",
"lint": "aegir-lint",
"test": "gulp test",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"build": "gulp build",
Expand All @@ -31,35 +30,34 @@
},
"homepage": "https://github.com/ipfs/js-libp2p-ipfs-browser#readme",
"devDependencies": {
"aegir": "^8.0.1",
"aegir": "^9.1.1",
"async": "^2.1.2",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"libp2p-ipfs": "^0.14.1",
"peer-id": "^0.7.0",
"libp2p-ipfs": "^0.15.0",
"peer-id": "^0.8.0",
"pre-commit": "^1.1.3",
"pull-goodbye": "0.0.1",
"pull-serializer": "^0.3.2",
"pull-stream": "^3.4.5",
"run-parallel": "^1.1.6",
"pull-stream": "^3.5.0",
"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",
"libp2p-webrtc-star": "^0.4.3",
"libp2p-websockets": "^0.8.1",
"libp2p-secio": "^0.6.2",
"libp2p-spdy": "^0.10.0",
"libp2p-swarm": "^0.26.0",
"libp2p-webrtc-star": "^0.5.0",
"libp2p-websockets": "^0.9.0",
"mafmt": "^2.1.2",
"multiaddr": "^2.0.2",
"multiaddr": "^2.0.3",
"peer-book": "^0.3.0",
"peer-id": "^0.7.0",
"peer-info": "^0.7.0"
"peer-id": "^0.8.0",
"peer-info": "^0.8.0"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>"
]
}
}
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -54,6 +53,7 @@ exports.Node = function Node (pInfo, pBook) {
// if we have `webrtc-star` addrs, then add
// the WebRTCStar transport
const wstar = new WebRTCStar()

if (wstar.filter(this.peerInfo.multiaddrs).length > 0) {
this.swarm.transport.add('wstar', wstar)
wstar.discovery.on('peer', (peerInfo) => {
Expand Down Expand Up @@ -192,8 +192,8 @@ exports.Node = function Node (pInfo, pBook) {
this.swarm.hangUp(peer, callback)
}

this.handle = (protocol, handler) => {
return this.swarm.handle(protocol, handler)
this.handle = (protocol, handlerFunc, matchFunc) => {
return this.swarm.handle(protocol, handlerFunc, matchFunc)
}

this.unhandle = (protocol) => {
Expand Down
3 changes: 1 addition & 2 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

const w = require('webrtcsupport')

require('./websockets-only')
// require('./websockets-only')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently chasing why websockets fails in the browser


if (w.support) {
require('./webrtc-star-only')
require('./webrtc-star-and-websockets')
}
Empty file removed test/webrtc-star-and-websockets.js
Empty file.
68 changes: 38 additions & 30 deletions test/webrtc-star-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) => {
Expand All @@ -46,7 +51,7 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
})

it('handle a protocol on the first node', (done) => {
node2.handle('/echo/1.0.0', (conn) => {
node2.handle('/echo/1.0.0', (protocol, conn) => {
pull(conn, conn)
})
done()
Expand Down Expand Up @@ -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)
})
})
})
})
25 changes: 18 additions & 7 deletions test/websockets-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,36 @@ const serializer = require('pull-serializer')

const libp2p = require('../src')
const rawPeer = require('./peer.json')
const id = PeerId.createFromPrivKey(rawPeer.privKey)

describe('libp2p-ipfs-browser (websockets only)', function () {
describe('libp2p-ipfs-browser (websockets only)', () => {
let peerB
let nodeA

before((done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws/ipfs/' + rawPeer.id)
peerB = new PeerInfo(id)
peerB.multiaddr.add(mh)
done()

PeerId.createFromPrivKey(rawPeer.privKey, (err, id) => {
if (err) {
return done(err)
}

peerB = new PeerInfo(id)
peerB.multiaddr.add(mh)
done()
})
})

after((done) => {
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) => {
Expand Down