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

Commit aa5b19f

Browse files
authored
Merge pull request #24 from ipfs/new-aegir
feat: ready for next aegir
2 parents 2818715 + 4480926 commit aa5b19f

File tree

8 files changed

+99
-84
lines changed

8 files changed

+99
-84
lines changed

.gitignore

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

35-
# Dignified.js builds
3635
dist
37-
lib

.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-
- 5
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ libp2p-ipfs
1111
[![Dependency Status](https://david-dm.org/ipfs/js-libp2p-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-ipfs)
1212
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
1313
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
14+
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
15+
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
1416

1517
> libp2p build (module) used in js-ipfs
1618

examples/echo/listener.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ nodeListener.start((err) => {
2121
console.log(peerInfo.id.toB58String())
2222
})
2323

24-
nodeListener.handle('/echo/1.0.0', (conn) => {
24+
nodeListener.handle('/echo/1.0.0', (protocol, conn) => {
2525
pull(
2626
conn,
2727
conn
2828
)
2929
})
3030

31-
nodeListener.handle('/hello/1.0.0', (conn) => {
31+
nodeListener.handle('/hello/1.0.0', (protocol, conn) => {
3232
pull(
3333
pull.values(['hello', 'world']),
3434
conn

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
"name": "libp2p-ipfs",
33
"version": "0.14.1",
44
"description": "The libp2p build (module) used by js-ipfs on Node.js",
5-
"main": "lib/index.js",
6-
"jsnext:main": "src/index.js",
5+
"main": "src/index.js",
76
"scripts": {
87
"test": "aegir-test node",
9-
"build": "aegir-build node",
108
"lint": "aegir-lint",
119
"release": "aegir-release node",
1210
"release-minor": "aegir-release node --type minor",
@@ -30,26 +28,28 @@
3028
"bugs": {
3129
"url": "https://github.com/ipfs/js-libp2p-ipfs/issues"
3230
},
31+
"engines": {
32+
"node": ">=4.0.0"
33+
},
3334
"homepage": "https://github.com/ipfs/js-libp2p-ipfs#readme",
3435
"devDependencies": {
35-
"aegir": "^8.0.0",
36+
"aegir": "^9.0.1",
37+
"async": "^2.1.2",
3638
"chai": "^3.5.0",
3739
"pre-commit": "^1.1.3",
38-
"pull-stream": "^3.4.5",
39-
"run-parallel": "^1.1.6"
40+
"pull-stream": "^3.5.0"
4041
},
4142
"dependencies": {
42-
"libp2p-secio": "^0.5.0",
43-
"libp2p-spdy": "^0.9.0",
44-
"libp2p-swarm": "^0.23.0",
45-
"libp2p-tcp": "^0.8.1",
46-
"libp2p-websockets": "^0.8.1",
43+
"libp2p-secio": "^0.6.2",
44+
"libp2p-spdy": "^0.10.0",
45+
"libp2p-swarm": "^0.26.0",
46+
"libp2p-tcp": "^0.9.1",
47+
"libp2p-websockets": "^0.9.0",
4748
"mafmt": "^2.1.2",
48-
"multiaddr": "^2.0.2",
49+
"multiaddr": "^2.0.3",
4950
"peer-book": "^0.3.0",
50-
"peer-id": "^0.7.0",
51-
"peer-info": "^0.7.0",
52-
"run-parallel": "^1.1.6"
51+
"peer-id": "^0.8.0",
52+
"peer-info": "^0.8.0"
5353
},
5454
"contributors": [
5555
"David Dias <daviddias.p@gmail.com>",

src/index.js

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

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

3130
if (!pBook) {
@@ -189,8 +188,8 @@ exports.Node = function Node (pInfo, pBook) {
189188
this.swarm.hangUp(peer, callback)
190189
}
191190

192-
this.handle = (protocol, handler) => {
193-
return this.swarm.handle(protocol, handler)
191+
this.handle = (protocol, handlerFunc, matchFunc) => {
192+
return this.swarm.handle(protocol, handlerFunc, matchFunc)
194193
}
195194

196195
this.unhandle = (protocol) => {

test/libp2p.spec.js

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const expect = require('chai').expect
55
const libp2p = require('../src')
66
const PeerInfo = require('peer-info')
77
const multiaddr = require('multiaddr')
8-
const parallel = require('run-parallel')
8+
const parallel = require('async/parallel')
9+
const map = require('async/map')
910
const spawn = require('child_process').spawn
1011
const path = require('path')
1112
const pull = require('pull-stream')
@@ -29,48 +30,46 @@ describe('libp2p-ipfs', () => {
2930
let spawnedNode
3031

3132
it('create 6 nodes', (done) => {
32-
parallel([
33-
(cb) => {
34-
nodeA = new libp2p.Node()
35-
cb()
36-
},
37-
(cb) => {
38-
nodeB = new libp2p.Node()
39-
cb()
40-
},
41-
(cb) => {
42-
nodeC = new libp2p.Node()
43-
cb()
44-
},
45-
(cb) => {
46-
nodeD = new libp2p.Node()
47-
cb()
48-
},
49-
(cb) => {
50-
nodeE = new libp2p.Node()
51-
const maddrWS = multiaddr('/ip4/127.0.0.1/tcp/25001/ws')
52-
nodeE.peerInfo.multiaddr.add(maddrWS)
53-
54-
nodeEMultiaddrWebSockets = multiaddr(
55-
nodeE.peerInfo.multiaddrs[1].toString() +
56-
'/ipfs/' + nodeE.peerInfo.id.toB58String()
57-
)
58-
cb()
59-
},
60-
(cb) => {
61-
const pInfo = new PeerInfo()
62-
const maddrWS = multiaddr('/ip4/127.0.0.1/tcp/25002/ws')
63-
64-
pInfo.multiaddr.add(maddrWS)
65-
nodeF = new libp2p.Node(pInfo)
66-
67-
nodeFMultiaddrWebSockets = multiaddr(
68-
nodeF.peerInfo.multiaddrs[0].toString() +
69-
'/ipfs/' + nodeF.peerInfo.id.toB58String()
70-
)
71-
cb()
33+
map([0, 1, 2, 3, 4, 5], (i, cb) => {
34+
PeerInfo.create(cb)
35+
}, (err, infos) => {
36+
if (err) {
37+
return done(err)
7238
}
73-
], done)
39+
40+
infos.forEach((info, i) => {
41+
if (i === 5) {
42+
return
43+
}
44+
info.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0'))
45+
})
46+
47+
nodeA = new libp2p.Node(infos[0])
48+
nodeB = new libp2p.Node(infos[1])
49+
nodeC = new libp2p.Node(infos[2])
50+
nodeD = new libp2p.Node(infos[3])
51+
nodeE = new libp2p.Node(infos[4])
52+
const maddrWS1 = multiaddr('/ip4/127.0.0.1/tcp/25001/ws')
53+
nodeE.peerInfo.multiaddr.add(maddrWS1)
54+
55+
nodeEMultiaddrWebSockets = multiaddr(
56+
nodeE.peerInfo.multiaddrs[1].toString() +
57+
'/ipfs/' + nodeE.peerInfo.id.toB58String()
58+
)
59+
60+
const pInfo = infos[5]
61+
const maddrWS2 = multiaddr('/ip4/127.0.0.1/tcp/25002/ws')
62+
pInfo.multiaddr.add(maddrWS2)
63+
64+
nodeF = new libp2p.Node(pInfo)
65+
66+
nodeFMultiaddrWebSockets = multiaddr(
67+
nodeF.peerInfo.multiaddrs[0].toString() +
68+
'/ipfs/' + nodeF.peerInfo.id.toB58String()
69+
)
70+
71+
done()
72+
})
7473
})
7574

7675
it('start 6 nodes', (done) => {
@@ -134,7 +133,7 @@ describe('libp2p-ipfs', () => {
134133
})
135134

136135
it('handle echo proto in 6 nodes', () => {
137-
function echo (conn) {
136+
function echo (protocol, conn) {
138137
pull(conn, conn)
139138
}
140139

test/spawn-libp2p-node.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ const multiaddr = require('multiaddr')
99
const pull = require('pull-stream')
1010

1111
const idBak = require('./test-data/test-id.json')
12+
PeerId.createFromJSON(idBak, (err, id) => {
13+
if (err) {
14+
throw err
15+
}
1216

13-
const pInfo = new PeerInfo(PeerId.createFromJSON(idBak))
14-
const maddr = multiaddr('/ip4/127.0.0.1/tcp/12345')
17+
const pInfo = new PeerInfo(id)
18+
const maddr = multiaddr('/ip4/127.0.0.1/tcp/12345')
1519

16-
pInfo.multiaddr.add(maddr)
20+
pInfo.multiaddr.add(maddr)
1721

18-
const node = new libp2p.Node(pInfo)
22+
const node = new libp2p.Node(pInfo)
1923

20-
node.handle('/echo/1.0.0', (conn) => {
21-
pull(conn, conn)
22-
})
24+
node.handle('/echo/1.0.0', (protocol, conn) => {
25+
pull(conn, conn)
26+
})
2327

24-
node.start((err) => {
25-
if (err) {
26-
throw err
27-
}
28-
console.log('Spawned node started')
28+
node.start((err) => {
29+
if (err) {
30+
throw err
31+
}
32+
console.log('Spawned node started')
33+
})
2934
})

0 commit comments

Comments
 (0)