Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: integrate libp2p-ipfs-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 12, 2016
1 parent 9763f86 commit 6022b46
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 127 deletions.
39 changes: 39 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

const gulp = require('gulp')
const async = require('async')
const createTempNode = require('./test/utils/temp-node')
const API = require('./src/http-api')

const nodes = []

function startNode (num, done) {
createTempNode(num, (err, node) => {
if (err) throw err

const api = new API(node.repo.path())
nodes.push(api)
api.start(done)
})
}

gulp.task('libnode:start', (done) => {
async.parallel([
(cb) => startNode(7, cb),
(cb) => startNode(8, cb),
(cb) => startNode(9, cb)
], done)
})

gulp.task('libnode:stop', (done) => {
async.eachSeries(nodes, (node, cb) => {
setTimeout(() => node.stop(cb), 500)
}, done)
})

gulp.task('test:browser:before', ['libnode:start'])
gulp.task('test:node:before', ['libnode:start'])
gulp.task('test:browser:after', ['libnode:stop'])
gulp.task('test:node:after', ['libnode:stop'])

require('aegir/gulp')(gulp)
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"jsnext:main": "src/core/index.js",
"scripts": {
"lint": "aegir-lint",
"coverage": "aegir-coverage",
"test": "aegir-test",
"test:node": "aegir-test node",
"test:browser": "aegir-test browser",
"build": "aegir-build",
"release": "aegir-release",
"release:minor": "aegir-release --type minor",
"release:major": "aegir-release --type major",
"coverage": "gulp coverage",
"test": "gulp test",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"build": "gulp build",
"release": "gulp release",
"release:minor": "gulp release --type minor",
"release:major": "gulp release --type major",
"coverage-publish": "aegir-coverage publish"
},
"pre-commit": [
Expand All @@ -43,7 +43,9 @@
"chai": "^3.5.0",
"expose-loader": "^0.7.1",
"form-data": "^1.0.0-rc3",
"gulp": "^3.9.1",
"idb-plus-blob-store": "^1.1.2",
"libp2p-ipfs-browser": "^0.2.0",
"lodash": "^4.11.2",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
Expand Down Expand Up @@ -72,12 +74,12 @@
"ipfs-unixfs-engine": "^0.6.1",
"joi": "^8.0.5",
"libp2p-ipfs": "^0.3.3",
"libp2p-swarm": "^0.12.5",
"libp2p-swarm": "^0.12.11",
"lodash.get": "^4.2.1",
"lodash.set": "^4.1.0",
"multiaddr": "^1.4.1",
"path-exists": "^3.0.0",
"peer-book": "0.1.0",
"peer-book": "^0.1.1",
"peer-id": "^0.6.6",
"peer-info": "^0.6.2",
"readable-stream": "1.1.13",
Expand All @@ -88,13 +90,12 @@
"webpack": {
"resolve": {
"alias": {
"node-forge": "../../../node_modules/peer-id/vendor/forge.bundle.js"
"node-forge": "../../../node_modules/peer-id/vendor/forge.bundle.js",
"libp2p-ipfs": "libp2p-ipfs-browser"
}
},
"externals": {
"fs": "{}",
"ipfs-data-importing": "{ import: {} }",
"libp2p-ipfs": "{}",
"mkdirp": "{}"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/ipfs/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function id (self) {
callback(null, {
ID: self._peerInfo.id.toB58String(),
PublicKey: self._peerInfo.id.pubKey.toString('base64'),
Addresses: self._peerInfo.multiaddrs.map((ma) => { return ma.toString() }),
Addresses: self._peerInfo.multiaddrs.map((ma) => { return ma.toString() }).sort(),
AgentVersion: 'js-ipfs',
ProtocolVersion: '9000'
})
Expand Down
3 changes: 1 addition & 2 deletions src/core/ipfs/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ module.exports = function libp2p (self) {
const id = peerId.createFromB58String(idStr[1])
const peer = new PeerInfo(id)

ma = ma.toString().replace(/\/ipfs\/(.*)/, '') // FIXME remove this when multiaddr supports ipfs

peer.multiaddr.add(multiaddr(ma))

self._peerInfoBook.put(peer)

self._libp2pNode.swarm.dial(peer, (err) => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli-tests/test-bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('bitswap', function () {
let ipfs

before((done) => {
createTempNode(8, (err, _ipfs) => {
createTempNode(4, (err, _ipfs) => {
expect(err).to.not.exist
ipfs = _ipfs
ipfs.goOnline(done)
Expand Down
39 changes: 17 additions & 22 deletions test/cli-tests/test-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ describe('id', () => {
it('get the id', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'], {env})
.run((err, stdout, exitcode) => {
var expected = [ "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',",
expect(
stdout
).to.be.eql([
"{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',",
" PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=',",
" Addresses: [ '/ip4/0.0.0.0/tcp/0'],",
' Addresses: ',
" [ '/ip4/127.0.0.1/tcp/9990/websockets',",
" '/ip4/127.0.0.1/tcp/9999' ],",
" AgentVersion: 'js-ipfs',",
" ProtocolVersion: '9000' }" ]
" ProtocolVersion: '9000' }"
])

expect(stdout[0]).to.equal(expected[0])
expect(stdout[1]).to.equal(expected[1])
// expect(stdout[2]).to.equal(expected[2])
expect(stdout[3]).to.equal(expected[3])
expect(stdout[4]).to.equal(expected[4])
expect(stdout[5]).to.equal(expected[5])
expect(stdout[6]).to.equal(expected[6])
expect(stdout[7]).to.equal(expected[7])
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
Expand Down Expand Up @@ -57,21 +55,18 @@ describe('id', () => {
it('get the id', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'], {env})
.run((err, stdout, exitcode) => {
var expected = [
expect(
stdout
).to.be.eql([
"{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',",
" PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=',",
" Addresses: [ '/ip4/0.0.0.0/tcp/0' ],",
' Addresses: ',
" [ '/ip4/127.0.0.1/tcp/9990/websockets',",
" '/ip4/127.0.0.1/tcp/9999' ],",
" AgentVersion: 'js-ipfs',",
" ProtocolVersion: '9000' }" ]
" ProtocolVersion: '9000' }"
])

expect(stdout[0]).to.equal(expected[0])
expect(stdout[1]).to.equal(expected[1])
// expect(stdout[2]).to.equal(expected[2])
expect(stdout[3]).to.equal(expected[3])
expect(stdout[4]).to.equal(expected[4])
expect(stdout[5]).to.equal(expected[5])
expect(stdout[6]).to.equal(expected[6])
expect(stdout[7]).to.equal(expected[7])
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
Expand Down
2 changes: 1 addition & 1 deletion test/cli-tests/test-swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('swarm', function () {
var ipfsAddr

before((done) => {
createTempNode(9, (err, _ipfs) => {
createTempNode(2, (err, _ipfs) => {
expect(err).to.not.exist
ipfs = _ipfs
ipfs.goOnline((err) => {
Expand Down
Loading

0 comments on commit 6022b46

Please sign in to comment.