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

Async Crypto Endeavour #390

Merged
merged 14 commits into from
Nov 7, 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
24 changes: 8 additions & 16 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
'use strict'

const path = require('path')

module.exports = {
webpack: {
resolve: {
alias: {
'node-forge': path.resolve(
path.dirname(require.resolve('libp2p-crypto')),
'../vendor/forge.bundle.js'
)
}
},
externals: {
fs: '{}',
mkdirp: '{}'
}
karma: {
files: [{
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
watched: false,
served: true,
included: false
}]
}
}
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ node_modules
*.log
test/setup/tmp-disposable-nodes-addrs.json
dist
lib
coverage
28 changes: 20 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
sudo: false
language: node_js
node_js:
- 4
- 5
- "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:
- npm install -g npm

script:
- npm run lint
- npm run test:node
- npm run 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ ipfs-api
[![Dependency Status](https://david-dm.org/ipfs/js-ipfs-api.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-api)
[![Travis CI](https://travis-ci.org/ipfs/js-ipfs-api.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs-api)
[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-api.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-api)
![](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/js-ipfs-api.svg)](https://saucelabs.com/u/ipfs-js-api)

> **Note: If you see CI red, that is due a failing test when adding nested directories in the browser, all the other features work as expect, if this is something you also need, please consider helping us identifying the solution for it, join the discussion at: https://github.com/ipfs/js-ipfs-api/issues/339**

> A client library for the IPFS HTTP API, implemented in JavaScript. This client library implements the [interface-ipfs-core](https://github.com/ipfs/interface-ipfs-core) enabling applications to change between a embebed js-ipfs node and any remote IPFS node without having to change the code. In addition, this client library implements a set of utility functions.

Expand Down Expand Up @@ -99,6 +105,8 @@ If are using this module in a browser with something like browserify, then you w

```bash
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"http://example.com\"]"
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials "[\"true\"]"
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"POST\", \"GET\"]"
```

## Usage
Expand Down
48 changes: 26 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,66 @@
"name": "ipfs-api",
"version": "11.0.1",
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"browser": {
"glob": false,
"fs": false,
"stream": "readable-stream"
},
"scripts": {
"test": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp test:node",
"test:node": "PHANTOM=off gulp test:node",
"test:browser": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp test:browser",
"test": "gulp test",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"lint": "aegir-lint",
"build": "gulp build",
"release": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp release",
"release-minor": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp release --type minor",
"release-major": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp release --type major",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
"coverage": "gulp coverage",
"coverage-publish": "aegir-coverage publish"
},
"dependencies": {
"async": "^2.1.2",
"babel-runtime": "^6.18.0",
"bl": "^1.1.2",
"bs58": "^3.0.0",
"detect-node": "^2.0.3",
"flatmap": "0.0.3",
"glob": "^7.1.1",
"ipfs-block": "^0.4.0",
"ipld-dag-pb": "^0.1.3",
"is-ipfs": "^0.2.0",
"ipfs-block": "^0.5.0",
"ipld-dag-pb": "^0.8.0",
"is-ipfs": "^0.2.1",
"isstream": "^0.1.2",
"multiaddr": "^2.0.2",
"multiaddr": "^2.0.3",
"multipart-stream": "^2.0.1",
"ndjson": "^1.4.3",
"peer-id": "^0.7.0",
"peer-info": "^0.7.1",
"promisify-es6": "^1.0.1",
"once": "^1.4.0",
"peer-id": "^0.8.0",
"peer-info": "^0.8.0",
"promisify-es6": "^1.0.2",
"qs": "^6.3.0",
"readable-stream": "^1.1.14",
"streamifier": "^0.1.1",
"tar-stream": "^1.5.2",
"wreck": "^10.0.0"
},
"engines": {
"node": ">=4.2.2"
"node": ">=4.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ipfs/js-ipfs-api"
},
"devDependencies": {
"aegir": "^8.1.2",
"aegir": "^9.1.0",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"hapi": "^15.2.0",
"interface-ipfs-core": "^0.16.1",
"interface-ipfs-core": "^0.18.0",
"ipfsd-ctl": "^0.17.0",
"pre-commit": "^1.1.3",
"socket.io": "^1.5.1",
"socket.io-client": "^1.5.1",
"stream-equal": "^0.1.8",
"stream-http": "^2.4.0"
"stream-equal": "^0.1.9"
},
"pre-commit": [
"lint",
Expand Down Expand Up @@ -103,4 +107,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
28 changes: 12 additions & 16 deletions src/add-to-dagnode-transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const map = require('async/map')
const waterfall = require('async/waterfall')

const getDagNode = require('./get-dagnode')

// transform { Hash: '...' } objects into { path: 'string', node: DAGNode }
Expand All @@ -9,24 +11,18 @@ module.exports = (err, res, send, done) => {
return done(err)
}

map(res, (entry, next) => {
getDagNode(send, entry.Hash, (err, node) => {
map(res, (entry, next) => waterfall([
(cb) => getDagNode(send, entry.Hash, cb),
(node, cb) => node.size((err, size) => {
if (err) {
return next(err)
return cb(err)
}
node.size((err, size) => {
if (err) {
return next(err)
}
const obj = {
path: entry.Name,
hash: entry.Hash,
size: size
}
next(null, obj)

cb(null, {
path: entry.Name,
hash: entry.Hash,
size: size
})
})
}, (err, res) => {
done(err, res)
})
], next), done)
}
48 changes: 27 additions & 21 deletions test/factory/daemon-spawner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

// const defaultConfig = require('./default-config.json')
const ipfsd = require('ipfsd-ctl')
const series = require('run-series')
const series = require('async/series')
const eachSeries = require('async/eachSeries')
const once = require('once')

module.exports = Factory

Expand All @@ -11,7 +13,7 @@ function Factory () {
return new Factory()
}

const nodes = []
let nodes = []

this.spawnNode = (repoPath, config, callback) => {
if (typeof repoPath === 'function') {
Expand Down Expand Up @@ -44,11 +46,18 @@ function Factory () {
})
}

this.dismantle = function (callback) {
series(
nodes.map((node) => {
return node.stopDaemon
}), callback)
this.dismantle = (callback) => {
eachSeries(nodes, (node, cb) => {
cb = once(cb)
node.stopDaemon(cb)
}, (err) => {
if (err) {
return callback(err)
}
nodes = []

callback()
})
}
}

Expand All @@ -62,22 +71,19 @@ function spawnEphemeralNode (callback) {
// doesn't work as expected
series([
(cb) => {
node.setConfig('Bootstrap', null, cb)
},
(cb) => {
node.setConfig('Discovery', '{}', cb)
},
(cb) => {
const headers = {
HTTPHeaders: {
'Access-Control-Allow-Origin': ['*']
}
const configValues = {
Bootstrap: [],
Discovery: {},
'HTTPHeaders.Access-Control-Allow-Origin': ['*'],
'HTTPHeaders.Access-Control-Allow-Credentials': 'true',
'HTTPHeaders.Access-Control-Allow-Methods': ['PUT', 'POST', 'GET']
}
node.setConfig('API', JSON.stringify(headers), cb)

eachSeries(Object.keys(configValues), (configKey, cb) => {
node.setConfig(`API.${configKey}`, JSON.stringify(configValues[configKey]), cb)
}, cb)
},
(cb) => {
node.startDaemon(cb)
}
(cb) => node.startDaemon(cb)
], (err) => {
if (err) {
return callback(err)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions test/interface-ipfs-core/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

const expect = require('chai').expect
const isNode = require('detect-node')
const path = require('path')
const test = require('interface-ipfs-core')
const fs = require('fs')
const loadFixture = require('aegir/fixtures')

const FactoryClient = require('../factory/factory-client')
const testfile = fs.readFileSync(path.join(__dirname, '/../data/testfile.txt'))

let testfile
if (isNode) {
testfile = loadFixture(__dirname, '../fixtures/testfile.txt')
} else {
testfile = loadFixture(__dirname, 'fixtures/testfile.txt')
}

// add, cat, get and ls tests from interface-ipfs-core
let fc
Expand Down
9 changes: 6 additions & 3 deletions test/interface-ipfs-core/get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ const concat = require('concat-stream')
const through = require('through2')
const streamEqual = require('stream-equal')
const path = require('path')
const loadFixture = require('aegir/fixtures')
const FactoryClient = require('../factory/factory-client')

const testfile = fs.readFileSync(path.join(__dirname, '/../data/testfile.txt'))

let testfile
let testfileBig
let tfbPath
if (isNode) {
tfbPath = path.join(__dirname, '/../data/15mb.random')
tfbPath = path.join(__dirname, '../fixtures/15mb.random')
testfileBig = fs.createReadStream(tfbPath, { bufferSize: 128 })
testfile = loadFixture(__dirname, '../fixtures/testfile.txt')
} else {
testfile = loadFixture(__dirname, 'fixtures/testfile.txt')
}

describe('.get', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/interface-ipfs-core/ls.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ describe('ls', function () {
(cb) => fc.spawnNode(cb),
(node, cb) => {
ipfs = node
const filesPath = path.join(__dirname, '../data/test-folder')
const filesPath = path.join(__dirname, '../fixtures/test-folder')
ipfs.util.addFromFs(filesPath, { recursive: true }, cb)
},
(hashes, cb) => {
folder = hashes[hashes.length - 1].hash
expect(folder).to.be.eql('QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6')
expect(folder).to.be.eql('QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
cb()
}
], done)
Expand All @@ -45,7 +45,7 @@ describe('ls', function () {

expect(res).to.have.a.property('Objects')
expect(res.Objects[0]).to.have.a.property('Links')
expect(res.Objects[0]).to.have.property('Hash', 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6')
expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
done()
})
})
Expand All @@ -72,7 +72,7 @@ describe('ls', function () {
.then((res) => {
expect(res).to.have.a.property('Objects')
expect(res.Objects[0]).to.have.a.property('Links')
expect(res.Objects[0]).to.have.property('Hash', 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6')
expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
})
})

Expand Down
Loading