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

Commit 1d0d57e

Browse files
dignifiedquiredaviddias
authored andcommitted
Async Crypto Endeavour (#390)
1 parent d87cbc0 commit 1d0d57e

28 files changed

+190
-172
lines changed

.aegir.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
'use strict'
22

3-
const path = require('path')
4-
53
module.exports = {
6-
webpack: {
7-
resolve: {
8-
alias: {
9-
'node-forge': path.resolve(
10-
path.dirname(require.resolve('libp2p-crypto')),
11-
'../vendor/forge.bundle.js'
12-
)
13-
}
14-
},
15-
externals: {
16-
fs: '{}',
17-
mkdirp: '{}'
18-
}
4+
karma: {
5+
files: [{
6+
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
7+
watched: false,
8+
served: true,
9+
included: false
10+
}]
1911
}
20-
}
12+
}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22
*.log
33
test/setup/tmp-disposable-nodes-addrs.json
44
dist
5-
lib
65
coverage

.travis.yml

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

815
# Make sure we have new NPM.
916
before_install:
1017
- npm install -g npm
1118

1219
script:
1320
- npm run lint
14-
- npm run test:node
21+
- npm run test
1522
- npm run coverage
1623

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

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

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ ipfs-api
99
[![Dependency Status](https://david-dm.org/ipfs/js-ipfs-api.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-api)
1010
[![Travis CI](https://travis-ci.org/ipfs/js-ipfs-api.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs-api)
1111
[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-api.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-api)
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/js-ipfs-api.svg)](https://saucelabs.com/u/ipfs-js-api)
16+
17+
> **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**
1218
1319
> 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.
1420
@@ -99,6 +105,8 @@ If are using this module in a browser with something like browserify, then you w
99105

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

104112
## Usage

package.json

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,66 @@
22
"name": "ipfs-api",
33
"version": "11.0.1",
44
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
5-
"main": "lib/index.js",
6-
"jsnext:main": "src/index.js",
5+
"main": "src/index.js",
6+
"browser": {
7+
"glob": false,
8+
"fs": false,
9+
"stream": "readable-stream"
10+
},
711
"scripts": {
8-
"test": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp test:node",
9-
"test:node": "PHANTOM=off gulp test:node",
10-
"test:browser": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp test:browser",
12+
"test": "gulp test",
13+
"test:node": "gulp test:node",
14+
"test:browser": "gulp test:browser",
1115
"lint": "aegir-lint",
1216
"build": "gulp build",
13-
"release": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp release",
14-
"release-minor": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp release --type minor",
15-
"release-major": "PHANTOM=off node --max_old_space_size=8192 node_modules/.bin/gulp release --type major",
17+
"release": "gulp release",
18+
"release-minor": "gulp release --type minor",
19+
"release-major": "gulp release --type major",
1620
"coverage": "gulp coverage",
1721
"coverage-publish": "aegir-coverage publish"
1822
},
1923
"dependencies": {
2024
"async": "^2.1.2",
21-
"babel-runtime": "^6.18.0",
2225
"bl": "^1.1.2",
2326
"bs58": "^3.0.0",
2427
"detect-node": "^2.0.3",
2528
"flatmap": "0.0.3",
2629
"glob": "^7.1.1",
27-
"ipfs-block": "^0.4.0",
28-
"ipld-dag-pb": "^0.1.3",
29-
"is-ipfs": "^0.2.0",
30+
"ipfs-block": "^0.5.0",
31+
"ipld-dag-pb": "^0.8.0",
32+
"is-ipfs": "^0.2.1",
3033
"isstream": "^0.1.2",
31-
"multiaddr": "^2.0.2",
34+
"multiaddr": "^2.0.3",
3235
"multipart-stream": "^2.0.1",
3336
"ndjson": "^1.4.3",
34-
"peer-id": "^0.7.0",
35-
"peer-info": "^0.7.1",
36-
"promisify-es6": "^1.0.1",
37+
"once": "^1.4.0",
38+
"peer-id": "^0.8.0",
39+
"peer-info": "^0.8.0",
40+
"promisify-es6": "^1.0.2",
3741
"qs": "^6.3.0",
42+
"readable-stream": "^1.1.14",
3843
"streamifier": "^0.1.1",
3944
"tar-stream": "^1.5.2",
4045
"wreck": "^10.0.0"
4146
},
4247
"engines": {
43-
"node": ">=4.2.2"
48+
"node": ">=4.0.0"
4449
},
4550
"repository": {
4651
"type": "git",
4752
"url": "https://github.com/ipfs/js-ipfs-api"
4853
},
4954
"devDependencies": {
50-
"aegir": "^8.1.2",
55+
"aegir": "^9.1.0",
5156
"chai": "^3.5.0",
5257
"gulp": "^3.9.1",
5358
"hapi": "^15.2.0",
54-
"interface-ipfs-core": "^0.16.1",
59+
"interface-ipfs-core": "^0.18.0",
5560
"ipfsd-ctl": "^0.17.0",
5661
"pre-commit": "^1.1.3",
5762
"socket.io": "^1.5.1",
5863
"socket.io-client": "^1.5.1",
59-
"stream-equal": "^0.1.8",
60-
"stream-http": "^2.4.0"
64+
"stream-equal": "^0.1.9"
6165
},
6266
"pre-commit": [
6367
"lint",
@@ -103,4 +107,4 @@
103107
"url": "https://github.com/ipfs/js-ipfs-api/issues"
104108
},
105109
"homepage": "https://github.com/ipfs/js-ipfs-api"
106-
}
110+
}

src/add-to-dagnode-transform.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict'
22

33
const map = require('async/map')
4+
const waterfall = require('async/waterfall')
5+
46
const getDagNode = require('./get-dagnode')
57

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

12-
map(res, (entry, next) => {
13-
getDagNode(send, entry.Hash, (err, node) => {
14+
map(res, (entry, next) => waterfall([
15+
(cb) => getDagNode(send, entry.Hash, cb),
16+
(node, cb) => node.size((err, size) => {
1417
if (err) {
15-
return next(err)
18+
return cb(err)
1619
}
17-
node.size((err, size) => {
18-
if (err) {
19-
return next(err)
20-
}
21-
const obj = {
22-
path: entry.Name,
23-
hash: entry.Hash,
24-
size: size
25-
}
26-
next(null, obj)
20+
21+
cb(null, {
22+
path: entry.Name,
23+
hash: entry.Hash,
24+
size: size
2725
})
2826
})
29-
}, (err, res) => {
30-
done(err, res)
31-
})
27+
], next), done)
3228
}

test/factory/daemon-spawner.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// const defaultConfig = require('./default-config.json')
44
const ipfsd = require('ipfsd-ctl')
5-
const series = require('run-series')
5+
const series = require('async/series')
6+
const eachSeries = require('async/eachSeries')
7+
const once = require('once')
68

79
module.exports = Factory
810

@@ -11,7 +13,7 @@ function Factory () {
1113
return new Factory()
1214
}
1315

14-
const nodes = []
16+
let nodes = []
1517

1618
this.spawnNode = (repoPath, config, callback) => {
1719
if (typeof repoPath === 'function') {
@@ -44,11 +46,18 @@ function Factory () {
4446
})
4547
}
4648

47-
this.dismantle = function (callback) {
48-
series(
49-
nodes.map((node) => {
50-
return node.stopDaemon
51-
}), callback)
49+
this.dismantle = (callback) => {
50+
eachSeries(nodes, (node, cb) => {
51+
cb = once(cb)
52+
node.stopDaemon(cb)
53+
}, (err) => {
54+
if (err) {
55+
return callback(err)
56+
}
57+
nodes = []
58+
59+
callback()
60+
})
5261
}
5362
}
5463

@@ -62,22 +71,19 @@ function spawnEphemeralNode (callback) {
6271
// doesn't work as expected
6372
series([
6473
(cb) => {
65-
node.setConfig('Bootstrap', null, cb)
66-
},
67-
(cb) => {
68-
node.setConfig('Discovery', '{}', cb)
69-
},
70-
(cb) => {
71-
const headers = {
72-
HTTPHeaders: {
73-
'Access-Control-Allow-Origin': ['*']
74-
}
74+
const configValues = {
75+
Bootstrap: [],
76+
Discovery: {},
77+
'HTTPHeaders.Access-Control-Allow-Origin': ['*'],
78+
'HTTPHeaders.Access-Control-Allow-Credentials': 'true',
79+
'HTTPHeaders.Access-Control-Allow-Methods': ['PUT', 'POST', 'GET']
7580
}
76-
node.setConfig('API', JSON.stringify(headers), cb)
81+
82+
eachSeries(Object.keys(configValues), (configKey, cb) => {
83+
node.setConfig(`API.${configKey}`, JSON.stringify(configValues[configKey]), cb)
84+
}, cb)
7785
},
78-
(cb) => {
79-
node.startDaemon(cb)
80-
}
86+
(cb) => node.startDaemon(cb)
8187
], (err) => {
8288
if (err) {
8389
return callback(err)
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)