Skip to content

Async Crypto Endeavour #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ build
node_modules

dist
lib
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: false
language: node_js
node_js:
- 4
- 5
- 6
- stable

# Make sure we have new NPM.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
[![Build Status](https://travis-ci.org/ipfs/js-ipfs-repo.svg)](https://travis-ci.org/ipfs/js-ipfs-repo) [![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-repo.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-repo)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipfs-repo/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs-repo?branch=master) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](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/ipfs-js-repo.svg)](https://saucelabs.com/u/ipfs-js-repo)

> Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript

Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
"name": "ipfs-repo",
"version": "0.10.0",
"description": "IPFS Repo implementation",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"scripts": {
"test": "aegir-test",
"test:node": "aegir-test node",
"test:browser": "aegir-test browser",
"build": "aegir-build",
"coverage": "aegir-coverage",
"lint": "aegir-lint",
"release": "aegir-release",
"release-minor": "aegir-release --type minor",
"release-major": "aegir-release --type major",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
},
"repository": {
Expand All @@ -28,30 +27,31 @@
"test"
],
"homepage": "https://github.com/ipfs/js-ipfs-repo",
"engines": {
"node": ">=4.0.0"
},
"devDependencies": {
"aegir": "^8.0.0",
"aegir": "^9.0.1",
"buffer-loader": "^0.0.1",
"chai": "^3.5.0",
"fs-pull-blob-store": "^0.4.1",
"idb-pull-blob-store": "^0.4.0",
"idb-pull-blob-store": "^0.5.1",
"interface-pull-blob-store": "^0.6.0",
"lodash": "^4.15.0",
"lodash": "^4.16.6",
"multihashes": "^0.2.2",
"ncp": "^2.0.0",
"pre-commit": "^1.1.3",
"rimraf": "^2.5.4"
},
"dependencies": {
"babel-runtime": "^6.11.6",
"async": "^2.1.2",
"base32.js": "^0.1.0",
"ipfs-block": "^0.4.0",
"ipfs-block": "^0.5.0",
"lock": "^0.1.3",
"multihashes": "^0.2.2",
"pull-defer": "^0.2.2",
"pull-stream": "^3.4.5",
"pull-write": "^1.1.0",
"run-parallel": "^1.1.6",
"run-series": "^1.1.4",
"pull-stream": "^3.5.0",
"pull-write": "^1.1.1",
"safe-buffer": "^5.0.1"
},
"license": "MIT",
Expand All @@ -67,4 +67,4 @@
"nginnever <[email protected]>",
"npmcdn-to-unpkg-bot <[email protected]>"
]
}
}
2 changes: 1 addition & 1 deletion src/stores/blockstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const Block = require('ipfs-block')
const Lock = require('lock')
const base32 = require('base32.js')
const path = require('path')
const parallel = require('run-parallel')
const pull = require('pull-stream')
const pullWrite = require('pull-write')
const pullDefer = require('pull-defer/source')
const parallel = require('async/parallel')

const PREFIX_LENGTH = 5
const EXTENSION = 'data'
Expand Down
2 changes: 1 addition & 1 deletion src/stores/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const pull = require('pull-stream')
const series = require('run-series')
const series = require('async/series')

exports = module.exports

Expand Down
2 changes: 1 addition & 1 deletion src/stores/locks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const pull = require('pull-stream')
const series = require('run-series')
const series = require('async/series')

exports = module.exports

Expand Down
2 changes: 1 addition & 1 deletion src/stores/version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const pull = require('pull-stream')
const series = require('run-series')
const series = require('async/series')
const toBuffer = require('safe-buffer').Buffer.from

exports = module.exports
Expand Down
82 changes: 56 additions & 26 deletions test/blockstore-test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const Block = require('ipfs-block')
const mh = require('multihashes')
const pull = require('pull-stream')
const parallel = require('run-parallel')
const parallel = require('async/parallel')
const waterfall = require('async/waterfall')
const _ = require('lodash')

module.exports = (repo) => {
describe('blockstore', () => {
const helloKey = 'CIQLS/CIQLSTJHXGJU2PQIUUXFFV62PWV7VREE57RXUU4A52IIR55M4LX432I.data'

const blockCollection = _.range(100).map((i) => new Block(new Buffer(`hello-${i}-${Math.random()}`)))
const b = new Block('hello world')
let bKey

before((done) => {
b.key((err, key) => {
if (err) {
return done(err)
}
bKey = key
done()
})
})

describe('.putStream', () => {
it('simple', (done) => {
const b = new Block('hello world')
pull(
pull.values([
{ data: b.data, key: b.key() }
{ data: b.data, key: bKey }
]),
repo.blockstore.putStream(),
pull.collect((err, meta) => {
Expand All @@ -31,8 +43,6 @@ module.exports = (repo) => {
})

it('multi write (locks)', (done) => {
const b = new Block('hello world')

let i = 0
const finish = (err, meta) => {
expect(err).to.not.exist
Expand All @@ -44,15 +54,15 @@ module.exports = (repo) => {

pull(
pull.values([
{ data: b.data, key: b.key() }
{ data: b.data, key: bKey }
]),
repo.blockstore.putStream(),
pull.collect(finish)
)

pull(
pull.values([
{ data: b.data, key: b.key() }
{ data: b.data, key: bKey }
]),
repo.blockstore.putStream(),
pull.collect(finish)
Expand All @@ -63,8 +73,13 @@ module.exports = (repo) => {
parallel(_.range(50).map(() => (cb) => {
pull(
pull.values(blockCollection),
pull.map((b) => {
return { data: b.data, key: b.key() }
pull.asyncMap((b, cb) => {
b.key((err, key) => {
if (err) {
return cb(err)
}
cb(null, {data: b.data, key: key})
})
}),
repo.blockstore.putStream(),
pull.collect((err, meta) => {
Expand All @@ -90,15 +105,15 @@ module.exports = (repo) => {

describe('.getStream', () => {
it('simple', (done) => {
const b = new Block('hello world')

pull(
repo.blockstore.getStream(b.key()),
repo.blockstore.getStream(bKey),
pull.collect((err, data) => {
expect(err).to.not.exist
expect(data[0].key()).to.be.eql(b.key())

done()
data[0].key((err, key) => {
expect(err).to.not.exist
expect(key).to.be.eql(bKey)
done()
})
})
)
})
Expand All @@ -107,12 +122,20 @@ module.exports = (repo) => {
parallel(_.range(20 * 100).map((i) => (cb) => {
const j = i % blockCollection.length
pull(
repo.blockstore.getStream(blockCollection[j].key()),
pull.values([blockCollection[j]]),
pull.asyncMap((b, cb) => b.key(cb)),
pull.map((key) => repo.blockstore.getStream(key)),
pull.flatten(),
pull.collect((err, meta) => {
expect(err).to.not.exist
expect(meta[0].key())
.to.be.eql(blockCollection[j].key())
cb()
parallel([
(cb) => meta[0].key(cb),
(cb) => blockCollection[j].key(cb)
], (err, res) => {
expect(err).to.not.exist
expect(res[0]).to.be.eql(res[1])
cb()
})
})
)
}), done)
Expand All @@ -132,8 +155,10 @@ module.exports = (repo) => {
describe('.has', () => {
it('existing block', (done) => {
const b = new Block('hello world')

repo.blockstore.has(b.key(), (err, exists) => {
waterfall([
(cb) => b.key(cb),
(key, cb) => repo.blockstore.has(key, cb)
], (err, exists) => {
expect(err).to.not.exist
expect(exists).to.equal(true)
done()
Expand All @@ -143,7 +168,10 @@ module.exports = (repo) => {
it('non existent block', (done) => {
const b = new Block('wooot')

repo.blockstore.has(b.key(), (err, exists) => {
waterfall([
(cb) => b.key(cb),
(key, cb) => repo.blockstore.has(key, cb)
], (err, exists) => {
expect(err).to.not.exist
expect(exists).to.equal(false)
done()
Expand All @@ -154,11 +182,13 @@ module.exports = (repo) => {
describe('.delete', () => {
it('simple', (done) => {
const b = new Block('hello world')

repo.blockstore.delete(b.key(), (err) => {
b.key((err, key) => {
expect(err).to.not.exist

repo.blockstore.has(b.key(), (err, exists) => {
waterfall([
(cb) => repo.blockstore.delete(key, cb),
(cb) => repo.blockstore.has(key, cb)
], (err, exists) => {
expect(err).to.not.exist
expect(exists).to.equal(false)
done()
Expand Down
2 changes: 1 addition & 1 deletion test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict'

const series = require('run-series')
const series = require('async/series')
const Store = require('idb-pull-blob-store')
const _ = require('lodash')
const pull = require('pull-stream')
Expand Down
2 changes: 1 addition & 1 deletion test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

const expect = require('chai').expect
const series = require('run-series')
const series = require('async/series')

const Repo = require('../src/index')

Expand Down