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

Awesome IPLD Endeavour #398

Merged
merged 4 commits into from
Oct 28, 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
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"coverage-publish": "aegir-coverage publish"
},
"dependencies": {
"async": "^2.0.1",
"babel-runtime": "^6.11.6",
"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.0.5",
"ipfs-block": "^0.3.0",
"ipfs-merkle-dag": "^0.7.1",
"glob": "^7.1.1",
"ipfs-block": "^0.4.0",
"ipld-dag-pb": "^0.1.3",
"is-ipfs": "^0.2.0",
"isstream": "^0.1.2",
"multiaddr": "^2.0.2",
Expand All @@ -34,7 +34,7 @@
"peer-id": "^0.7.0",
"peer-info": "^0.7.1",
"promisify-es6": "^1.0.1",
"qs": "^6.2.1",
"qs": "^6.3.0",
"streamifier": "^0.1.1",
"tar-stream": "^1.5.2",
"wreck": "^10.0.0"
Expand All @@ -47,17 +47,17 @@
"url": "https://github.com/ipfs/js-ipfs-api"
},
"devDependencies": {
"aegir": "^8.0.0",
"aegir": "^8.1.2",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"hapi": "^15.0.2",
"interface-ipfs-core": "^0.15.0",
"hapi": "^15.2.0",
"interface-ipfs-core": "^0.16.1",
"ipfsd-ctl": "^0.16.0",
"pre-commit": "^1.1.3",
"socket.io": "^1.4.8",
"socket.io-client": "^1.4.8",
"socket.io": "^1.5.1",
"socket.io-client": "^1.5.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is socket.io actually used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the spawning of nodes when the requests come from the browser (IPFS Factory)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay, thanks

"stream-equal": "^0.1.8",
"stream-http": "^2.3.1"
"stream-http": "^2.4.0"
},
"pre-commit": [
"lint",
Expand Down Expand Up @@ -103,4 +103,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
25 changes: 15 additions & 10 deletions src/add-to-dagnode-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@ const map = require('async/map')
const getDagNode = require('./get-dagnode')

// transform { Hash: '...' } objects into { path: 'string', node: DAGNode }
module.exports = function (err, res, send, done) {
module.exports = (err, res, send, done) => {
if (err) {
return done(err)
}

map(res, function map (entry, next) {
getDagNode(send, entry.Hash, function (err, node) {
map(res, (entry, next) => {
getDagNode(send, entry.Hash, (err, node) => {
if (err) {
return next(err)
}
var obj = {
path: entry.Name,
hash: entry.Hash,
size: node.size()
}
next(null, obj)
node.size((err, size) => {
if (err) {
return next(err)
}
const obj = {
path: entry.Name,
hash: entry.Hash,
size: size
}
next(null, obj)
})
})
}, function (err, res) {
}, (err, res) => {
done(err, res)
})
}
20 changes: 19 additions & 1 deletion src/api/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
const promisify = require('promisify-es6')
const bl = require('bl')
const Block = require('ipfs-block')
const multihash = require('multihashes')
const CID = require('cids')

module.exports = (send) => {
return {
get: promisify((args, opts, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (args && CID.isCID(args)) {
args = multihash.toB58String(args.multihash)
}
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

return send({
path: 'block/get',
args: args,
Expand All @@ -32,6 +39,11 @@ module.exports = (send) => {
})
}),
stat: promisify((args, opts, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (args && CID.isCID(args)) {
args = multihash.toB58String(args.multihash)
}

if (typeof (opts) === 'function') {
callback = opts
opts = {}
Expand All @@ -50,7 +62,13 @@ module.exports = (send) => {
})
})
}),
put: promisify((block, callback) => {
put: promisify((block, cid, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (typeof cid === 'function') {
callback = cid
cid = {}
}

if (Array.isArray(block)) {
const err = new Error('block.put() only accepts 1 file')
return callback(err)
Expand Down
49 changes: 36 additions & 13 deletions src/api/object.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const DAGNode = require('ipfs-merkle-dag').DAGNode
const DAGLink = require('ipfs-merkle-dag').DAGLink
const dagPB = require('ipld-dag-pb')
const DAGNode = dagPB.DAGNode
const DAGLink = dagPB.DAGLink
const promisify = require('promisify-es6')
const bs58 = require('bs58')
const bl = require('bl')
Expand Down Expand Up @@ -93,21 +94,37 @@ module.exports = (send) => {
obj = JSON.parse(obj.toString())
}
}

let node

if (obj.multihash) {
node = obj
} else if (options.enc === 'protobuf') {
node = new DAGNode()
node.unMarshal(obj)
dagPB.util.deserialize(obj, (err, _node) => {
if (err) {
return callback(err)
}
node = _node
next()
})
return
} else {
node = new DAGNode(obj.Data, obj.Links)
}

if (node.toJSON().Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
next()

function next () {
node.toJSON((err, nodeJSON) => {
if (err) {
return callback(err)
}
if (nodeJSON.Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}

callback(null, node)
})
}

callback(null, node)
})
}),
data: promisify((multihash, options, callback) => {
Expand Down Expand Up @@ -200,13 +217,19 @@ module.exports = (send) => {
if (err) {
return callback(err)
}

const node = new DAGNode()
node.toJSON((err, nodeJSON) => {
if (err) {
return callback(err)
}

if (node.toJSON().Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}
if (nodeJSON.Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}

callback(null, node)
callback(null, node)
})
})
}),
patch: {
Expand Down
2 changes: 1 addition & 1 deletion src/get-dagnode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const DAGNode = require('ipfs-merkle-dag').DAGNode
const DAGNode = require('ipld-dag-pb').DAGNode
const bl = require('bl')
const parallel = require('async/parallel')

Expand Down