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

Commit add8892

Browse files
authored
Merge pull request #99 from ipfs/webcrypto
Async Crypto Endeavour
2 parents c80b9c8 + 81bdc38 commit add8892

File tree

11 files changed

+120
-101
lines changed

11 files changed

+120
-101
lines changed

.aegir.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ node_modules
3232
# Optional REPL history
3333
.node_repl_history
3434

35-
lib
3635
dist

.travis.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
sudo: false
22
language: node_js
3-
node_js:
4-
- 4
5-
- stable
3+
matrix:
4+
include:
5+
- node_js: 4
6+
env: CXX=g++-4.8
7+
- node_js: 6
8+
env:
9+
- SAUCE=true
10+
- CXX=g++-4.8
11+
- node_js: stable
12+
env: CXX=g++-4.8
613

714
# Make sure we have new NPM.
815
before_install:
@@ -13,12 +20,17 @@ script:
1320
- npm test
1421
- npm run coverage
1522

16-
addons:
17-
firefox: 'latest'
18-
1923
before_script:
2024
- export DISPLAY=:99.0
2125
- sh -e /etc/init.d/xvfb start
2226

2327
after_success:
2428
- npm run coverage-publish
29+
30+
addons:
31+
firefox: 'latest'
32+
apt:
33+
sources:
34+
- ubuntu-toolchain-r-test
35+
packages:
36+
- g++-4.8

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
[![Travis CI](https://travis-ci.org/ipfs/js-libp2p-ipfs-browser.svg?branch=master)](https://travis-ci.org/ipfs/js-libp2p-ipfs-browser)
1010
[![Circle CI](https://circleci.com/gh/ipfs/js-libp2p-ipfs-browser.svg?style=svg)](https://circleci.com/gh/ipfs/js-libp2p-ipfs-browser)
1111
[![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)
12+
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
13+
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
14+
15+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/libp2p-ipfs-browser.svg)](https://saucelabs.com/u/libp2p-ipfs-browser)
1216

1317
> libp2p build (module) used in js-ipfs when running it on the browser.
1418

gulpfile.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,41 @@
33
const gulp = require('gulp')
44
const multiaddr = require('multiaddr')
55
const Node = require('libp2p-ipfs').Node
6-
const Peer = require('peer-info')
7-
const Id = require('peer-id')
6+
const PeerInfo = require('peer-info')
7+
const PeerId = require('peer-id')
88
const pull = require('pull-stream')
99

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

1313
let node
1414
const rawPeer = require('./test/peer.json')
15-
const id = Id.createFromPrivKey(rawPeer.privKey)
1615

1716
gulp.task('libnode:start', (done) => {
18-
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
19-
const peer = new Peer(id)
20-
peer.multiaddr.add(mh)
21-
22-
node = new Node(peer)
23-
node.start(() => {
24-
node.handle('/echo/1.0.0', (conn) => {
25-
pull(conn, conn)
26-
})
27-
ready()
28-
})
29-
3017
let count = 0
3118
const ready = () => ++count === 2 ? done() : null
3219

3320
sigS = sigServer.start(15555, ready)
21+
22+
PeerId.createFromJSON(rawPeer, gotId)
23+
24+
function gotId (err, pid) {
25+
if (err) {
26+
return done(err)
27+
}
28+
const peer = new PeerInfo(pid)
29+
30+
const ma = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
31+
peer.multiaddr.add(ma)
32+
33+
node = new Node(peer)
34+
node.start(() => {
35+
node.handle('/echo/1.0.0', (protocol, conn) => {
36+
pull(conn, conn)
37+
})
38+
ready()
39+
})
40+
}
3441
})
3542

3643
gulp.task('libnode:stop', (done) => {

package.json

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
"name": "libp2p-ipfs-browser",
33
"version": "0.15.1",
44
"description": "libp2p build (module) used in js-ipfs when running it on the browser",
5-
"main": "lib/index.js",
6-
"jsnext:main": "src/index.js",
5+
"main": "src/index.js",
76
"pre-commit": [
87
"lint",
98
"test"
109
],
1110
"scripts": {
12-
"test": "gulp test",
1311
"lint": "aegir-lint",
12+
"test": "gulp test",
1413
"test:node": "gulp test:node",
1514
"test:browser": "gulp test:browser",
1615
"build": "gulp build",
@@ -31,35 +30,34 @@
3130
},
3231
"homepage": "https://github.com/ipfs/js-libp2p-ipfs-browser#readme",
3332
"devDependencies": {
34-
"aegir": "^8.0.1",
33+
"aegir": "^9.1.1",
34+
"async": "^2.1.2",
3535
"chai": "^3.5.0",
3636
"gulp": "^3.9.1",
37-
"libp2p-ipfs": "^0.14.1",
38-
"peer-id": "^0.7.0",
37+
"libp2p-ipfs": "^0.15.0",
38+
"peer-id": "^0.8.0",
3939
"pre-commit": "^1.1.3",
4040
"pull-goodbye": "0.0.1",
4141
"pull-serializer": "^0.3.2",
42-
"pull-stream": "^3.4.5",
43-
"run-parallel": "^1.1.6",
42+
"pull-stream": "^3.5.0",
4443
"webrtcsupport": "^2.2.0"
4544
},
4645
"dependencies": {
47-
"babel-runtime": "^6.11.6",
48-
"libp2p-secio": "^0.5.0",
49-
"libp2p-spdy": "^0.9.0",
50-
"libp2p-swarm": "^0.23.0",
51-
"libp2p-webrtc-star": "^0.4.3",
52-
"libp2p-websockets": "^0.8.1",
46+
"libp2p-secio": "^0.6.3",
47+
"libp2p-spdy": "^0.10.0",
48+
"libp2p-swarm": "^0.26.1",
49+
"libp2p-webrtc-star": "^0.5.0",
50+
"libp2p-websockets": "^0.9.1",
5351
"mafmt": "^2.1.2",
54-
"multiaddr": "^2.0.2",
52+
"multiaddr": "^2.0.3",
5553
"peer-book": "^0.3.0",
56-
"peer-id": "^0.7.0",
57-
"peer-info": "^0.7.0"
54+
"peer-id": "^0.8.0",
55+
"peer-info": "^0.8.0"
5856
},
5957
"contributors": [
6058
"David Dias <[email protected]>",
6159
"Friedel Ziegelmayer <[email protected]>",
6260
"Richard Littauer <[email protected]>",
6361
"greenkeeperio-bot <[email protected]>"
6462
]
65-
}
63+
}

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ exports.Node = function Node (pInfo, pBook) {
2323
}
2424

2525
if (!pInfo) {
26-
pInfo = new PeerInfo()
27-
pInfo.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0'))
26+
throw new Error('missing peer info')
2827
}
2928

3029
if (!pBook) {
@@ -54,6 +53,7 @@ exports.Node = function Node (pInfo, pBook) {
5453
// if we have `webrtc-star` addrs, then add
5554
// the WebRTCStar transport
5655
const wstar = new WebRTCStar()
56+
5757
if (wstar.filter(this.peerInfo.multiaddrs).length > 0) {
5858
this.swarm.transport.add('wstar', wstar)
5959
wstar.discovery.on('peer', (peerInfo) => {
@@ -192,8 +192,8 @@ exports.Node = function Node (pInfo, pBook) {
192192
this.swarm.hangUp(peer, callback)
193193
}
194194

195-
this.handle = (protocol, handler) => {
196-
return this.swarm.handle(protocol, handler)
195+
this.handle = (protocol, handlerFunc, matchFunc) => {
196+
return this.swarm.handle(protocol, handlerFunc, matchFunc)
197197
}
198198

199199
this.unhandle = (protocol) => {

test/browser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ require('./websockets-only')
66

77
if (w.support) {
88
require('./webrtc-star-only')
9-
require('./webrtc-star-and-websockets')
109
}

test/webrtc-star-and-websockets.js

Whitespace-only changes.

test/webrtc-star-only.js

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
const expect = require('chai').expect
55
const multiaddr = require('multiaddr')
66
const PeerInfo = require('peer-info')
7-
const peerId = require('peer-id')
8-
const parallel = require('run-parallel')
7+
const PeerId = require('peer-id')
8+
const parallel = require('async/parallel')
99
const pull = require('pull-stream')
1010

1111
const libp2p = require('../src')
@@ -19,17 +19,22 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
1919
let node2
2020

2121
it('create two peerInfo with webrtc-star addrs', (done) => {
22-
const id1 = peerId.create()
23-
peer1 = new PeerInfo(id1)
24-
const mh1 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id1.toB58String())
25-
peer1.multiaddr.add(mh1)
22+
parallel([
23+
(cb) => PeerId.create(cb),
24+
(cb) => PeerId.create(cb)
25+
], (err, ids) => {
26+
expect(err).to.not.exist
2627

27-
const id2 = peerId.create()
28-
peer2 = new PeerInfo(id2)
29-
const mh2 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id2.toB58String())
30-
peer2.multiaddr.add(mh2)
28+
peer1 = new PeerInfo(ids[0])
29+
const mh1 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + ids[0].toB58String())
30+
peer1.multiaddr.add(mh1)
3131

32-
done()
32+
peer2 = new PeerInfo(ids[1])
33+
const mh2 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + ids[1].toB58String())
34+
peer2.multiaddr.add(mh2)
35+
36+
done()
37+
})
3338
})
3439

3540
it('create two libp2p nodes with those peers', (done) => {
@@ -46,7 +51,7 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
4651
})
4752

4853
it('handle a protocol on the first node', (done) => {
49-
node2.handle('/echo/1.0.0', (conn) => {
54+
node2.handle('/echo/1.0.0', (protocol, conn) => {
5055
pull(conn, conn)
5156
})
5257
done()
@@ -95,25 +100,28 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
95100
})
96101

97102
it('create a third node and check that discovery works', (done) => {
98-
const id3 = peerId.create()
99-
const peer3 = new PeerInfo(id3)
100-
const mh3 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3.toB58String())
101-
peer3.multiaddr.add(mh3)
102-
103-
node1.discovery.on('peer', (peerInfo) => {
104-
node1.dialByPeerInfo(peerInfo, () => {})
105-
})
106-
node2.discovery.on('peer', (peerInfo) => {
107-
node2.dialByPeerInfo(peerInfo, () => {})
108-
})
103+
PeerId.create((err, id3) => {
104+
expect(err).to.not.exist
109105

110-
const node3 = new libp2p.Node(peer3)
111-
node3.start(() => {
112-
setTimeout(() => {
113-
expect(Object.keys(node1.swarm.muxedConns).length).to.equal(1)
114-
expect(Object.keys(node2.swarm.muxedConns).length).to.equal(1)
115-
done()
116-
}, 2000)
106+
const peer3 = new PeerInfo(id3)
107+
const mh3 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3.toB58String())
108+
peer3.multiaddr.add(mh3)
109+
110+
node1.discovery.on('peer', (peerInfo) => {
111+
node1.dialByPeerInfo(peerInfo, () => {})
112+
})
113+
node2.discovery.on('peer', (peerInfo) => {
114+
node2.dialByPeerInfo(peerInfo, () => {})
115+
})
116+
117+
const node3 = new libp2p.Node(peer3)
118+
node3.start(() => {
119+
setTimeout(() => {
120+
expect(Object.keys(node1.swarm.muxedConns).length).to.equal(1)
121+
expect(Object.keys(node2.swarm.muxedConns).length).to.equal(1)
122+
done()
123+
}, 2000)
124+
})
117125
})
118126
})
119127
})

test/websockets-only.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,36 @@ const serializer = require('pull-serializer')
1212

1313
const libp2p = require('../src')
1414
const rawPeer = require('./peer.json')
15-
const id = PeerId.createFromPrivKey(rawPeer.privKey)
1615

17-
describe('libp2p-ipfs-browser (websockets only)', function () {
16+
describe('libp2p-ipfs-browser (websockets only)', () => {
1817
let peerB
1918
let nodeA
2019

2120
before((done) => {
2221
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws/ipfs/' + rawPeer.id)
23-
peerB = new PeerInfo(id)
24-
peerB.multiaddr.add(mh)
25-
done()
22+
23+
PeerId.createFromPrivKey(rawPeer.privKey, (err, id) => {
24+
if (err) {
25+
return done(err)
26+
}
27+
28+
peerB = new PeerInfo(id)
29+
peerB.multiaddr.add(mh)
30+
done()
31+
})
2632
})
2733

2834
after((done) => {
2935
nodeA.stop(done)
3036
})
3137

32-
it('create libp2pNode', () => {
33-
nodeA = new libp2p.Node()
38+
it('create libp2pNode', (done) => {
39+
PeerInfo.create((err, info) => {
40+
expect(err).to.not.exist
41+
info.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0'))
42+
nodeA = new libp2p.Node(info)
43+
done()
44+
})
3445
})
3546

3647
it('start libp2pNode', (done) => {

0 commit comments

Comments
 (0)