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

feat: ready for next aegir #24

Merged
merged 2 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ node_modules
# Optional REPL history
.node_repl_history

# Dignified.js builds
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ libp2p-ipfs
[![Dependency Status](https://david-dm.org/ipfs/js-libp2p-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-ipfs)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
![](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)

> libp2p build (module) used in js-ipfs

Expand Down
4 changes: 2 additions & 2 deletions examples/echo/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ nodeListener.start((err) => {
console.log(peerInfo.id.toB58String())
})

nodeListener.handle('/echo/1.0.0', (conn) => {
nodeListener.handle('/echo/1.0.0', (protocol, conn) => {
pull(
conn,
conn
)
})

nodeListener.handle('/hello/1.0.0', (conn) => {
nodeListener.handle('/hello/1.0.0', (protocol, conn) => {
pull(
pull.values(['hello', 'world']),
conn
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
"name": "libp2p-ipfs",
"version": "0.14.1",
"description": "The libp2p build (module) used by js-ipfs on Node.js",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"scripts": {
"test": "aegir-test node",
"build": "aegir-build node",
"lint": "aegir-lint",
"release": "aegir-release node",
"release-minor": "aegir-release node --type minor",
Expand All @@ -30,26 +28,28 @@
"bugs": {
"url": "https://github.com/ipfs/js-libp2p-ipfs/issues"
},
"engines": {
"node": ">=4.0.0"
},
"homepage": "https://github.com/ipfs/js-libp2p-ipfs#readme",
"devDependencies": {
"aegir": "^8.0.0",
"aegir": "^9.0.1",
"async": "^2.1.2",
"chai": "^3.5.0",
"pre-commit": "^1.1.3",
"pull-stream": "^3.4.5",
"run-parallel": "^1.1.6"
"pull-stream": "^3.5.0"
},
"dependencies": {
"libp2p-secio": "^0.5.0",
"libp2p-spdy": "^0.9.0",
"libp2p-swarm": "^0.23.0",
"libp2p-tcp": "^0.8.1",
"libp2p-websockets": "^0.8.1",
"libp2p-secio": "^0.6.2",
"libp2p-spdy": "^0.10.0",
"libp2p-swarm": "^0.26.0",
"libp2p-tcp": "^0.9.1",
"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",
"run-parallel": "^1.1.6"
"peer-id": "^0.8.0",
"peer-info": "^0.8.0"
},
"contributors": [
"David Dias <[email protected]>",
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,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 @@ -189,8 +188,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
85 changes: 42 additions & 43 deletions test/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const expect = require('chai').expect
const libp2p = require('../src')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')
const parallel = require('run-parallel')
const parallel = require('async/parallel')
const map = require('async/map')
const spawn = require('child_process').spawn
const path = require('path')
const pull = require('pull-stream')
Expand All @@ -29,48 +30,46 @@ describe('libp2p-ipfs', () => {
let spawnedNode

it('create 6 nodes', (done) => {
parallel([
(cb) => {
nodeA = new libp2p.Node()
cb()
},
(cb) => {
nodeB = new libp2p.Node()
cb()
},
(cb) => {
nodeC = new libp2p.Node()
cb()
},
(cb) => {
nodeD = new libp2p.Node()
cb()
},
(cb) => {
nodeE = new libp2p.Node()
const maddrWS = multiaddr('/ip4/127.0.0.1/tcp/25001/ws')
nodeE.peerInfo.multiaddr.add(maddrWS)

nodeEMultiaddrWebSockets = multiaddr(
nodeE.peerInfo.multiaddrs[1].toString() +
'/ipfs/' + nodeE.peerInfo.id.toB58String()
)
cb()
},
(cb) => {
const pInfo = new PeerInfo()
const maddrWS = multiaddr('/ip4/127.0.0.1/tcp/25002/ws')

pInfo.multiaddr.add(maddrWS)
nodeF = new libp2p.Node(pInfo)

nodeFMultiaddrWebSockets = multiaddr(
nodeF.peerInfo.multiaddrs[0].toString() +
'/ipfs/' + nodeF.peerInfo.id.toB58String()
)
cb()
map([0, 1, 2, 3, 4, 5], (i, cb) => {
PeerInfo.create(cb)
}, (err, infos) => {
if (err) {
return done(err)
}
], done)

infos.forEach((info, i) => {
if (i === 5) {
return
}
info.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/0'))
})

nodeA = new libp2p.Node(infos[0])
nodeB = new libp2p.Node(infos[1])
nodeC = new libp2p.Node(infos[2])
nodeD = new libp2p.Node(infos[3])
nodeE = new libp2p.Node(infos[4])
const maddrWS1 = multiaddr('/ip4/127.0.0.1/tcp/25001/ws')
nodeE.peerInfo.multiaddr.add(maddrWS1)

nodeEMultiaddrWebSockets = multiaddr(
nodeE.peerInfo.multiaddrs[1].toString() +
'/ipfs/' + nodeE.peerInfo.id.toB58String()
)

const pInfo = infos[5]
const maddrWS2 = multiaddr('/ip4/127.0.0.1/tcp/25002/ws')
pInfo.multiaddr.add(maddrWS2)

nodeF = new libp2p.Node(pInfo)

nodeFMultiaddrWebSockets = multiaddr(
nodeF.peerInfo.multiaddrs[0].toString() +
'/ipfs/' + nodeF.peerInfo.id.toB58String()
)

done()
})
})

it('start 6 nodes', (done) => {
Expand Down Expand Up @@ -134,7 +133,7 @@ describe('libp2p-ipfs', () => {
})

it('handle echo proto in 6 nodes', () => {
function echo (conn) {
function echo (protocol, conn) {
pull(conn, conn)
}

Expand Down
29 changes: 17 additions & 12 deletions test/spawn-libp2p-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ const multiaddr = require('multiaddr')
const pull = require('pull-stream')

const idBak = require('./test-data/test-id.json')
PeerId.createFromJSON(idBak, (err, id) => {
if (err) {
throw err
}

const pInfo = new PeerInfo(PeerId.createFromJSON(idBak))
const maddr = multiaddr('/ip4/127.0.0.1/tcp/12345')
const pInfo = new PeerInfo(id)
const maddr = multiaddr('/ip4/127.0.0.1/tcp/12345')

pInfo.multiaddr.add(maddr)
pInfo.multiaddr.add(maddr)

const node = new libp2p.Node(pInfo)
const node = new libp2p.Node(pInfo)

node.handle('/echo/1.0.0', (conn) => {
pull(conn, conn)
})
node.handle('/echo/1.0.0', (protocol, conn) => {
pull(conn, conn)
})

node.start((err) => {
if (err) {
throw err
}
console.log('Spawned node started')
node.start((err) => {
if (err) {
throw err
}
console.log('Spawned node started')
})
})