From 78d8f257671e2019e7bf3bc1bc2667e36f8d7f79 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 13 Apr 2017 17:45:43 +0100 Subject: [PATCH 1/4] chore: update deps, test latest interface-ipfs-core --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index dc2bfde36..855ae18e7 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ "coverage-publish": "aegir-coverage publish" }, "dependencies": { - "async": "^2.2.0", + "async": "^2.3.0", "bs58": "^4.0.0", - "cids": "~0.4.2", + "cids": "~0.5.0", "concat-stream": "^1.6.0", "detect-node": "^2.0.3", "flatmap": "0.0.3", @@ -41,15 +41,15 @@ "multipart-stream": "^2.0.1", "ndjson": "^1.5.0", "once": "^1.4.0", - "peer-id": "~0.8.6", - "peer-info": "~0.9.0", + "peer-id": "~0.8.7", + "peer-info": "~0.9.2", "promisify-es6": "^1.0.2", "pump": "^1.0.2", "qs": "^6.4.0", - "readable-stream": "1.1.14", - "stream-http": "^2.6.3", + "stream-http": "^2.7.0", "streamifier": "^0.1.1", - "tar-stream": "^1.5.2" + "tar-stream": "^1.5.2", + "readable-stream": "1.1.14" }, "engines": { "node": ">=4.0.0", @@ -65,7 +65,7 @@ "dirty-chai": "^1.2.2", "eslint-plugin-react": "^6.10.3", "gulp": "^3.9.1", - "hapi": "^16.1.0", + "hapi": "^16.1.1", "interface-ipfs-core": "~0.26.2", "ipfsd-ctl": "~0.20.0", "pre-commit": "^1.2.2", @@ -127,4 +127,4 @@ "url": "https://github.com/ipfs/js-ipfs-api/issues" }, "homepage": "https://github.com/ipfs/js-ipfs-api" -} \ No newline at end of file +} From 7ca52c01536433914b06cb768f57ab5ba15b6731 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 14 Apr 2017 15:41:12 +0100 Subject: [PATCH 2/4] feat: add remaining dht methods --- src/api/dht.js | 123 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 32 deletions(-) diff --git a/src/api/dht.js b/src/api/dht.js index dd78e7e0e..a30d5e609 100644 --- a/src/api/dht.js +++ b/src/api/dht.js @@ -5,45 +5,20 @@ const streamToValue = require('../stream-to-value') module.exports = (send) => { return { - findprovs: promisify((args, opts, callback) => { - if (typeof opts === 'function' && - !callback) { - callback = opts - opts = {} - } - - // opts is the real callback -- - // 'callback' is being injected by promisify - if (typeof opts === 'function' && - typeof callback === 'function') { - callback = opts - opts = {} - } - - const request = { - path: 'dht/findprovs', - args: args, - qs: opts - } - - send.andTransform(request, streamToValue, callback) - }), get: promisify((key, opts, callback) => { - if (typeof opts === 'function' && - !callback) { + if (typeof opts === 'function' && !callback) { callback = opts opts = {} } // opts is the real callback -- // 'callback' is being injected by promisify - if (typeof opts === 'function' && - typeof callback === 'function') { + if (typeof opts === 'function' && typeof callback === 'function') { callback = opts opts = {} } - const handleResult = (done, err, res) => { + function handleResult (done, err, res) { if (err) { return done(err) } @@ -73,17 +48,16 @@ module.exports = (send) => { qs: opts }, handleResult.bind(null, callback)) }), + put: promisify((key, value, opts, callback) => { - if (typeof opts === 'function' && - !callback) { + if (typeof opts === 'function' && !callback) { callback = opts opts = {} } // opts is the real callback -- // 'callback' is being injected by promisify - if (typeof opts === 'function' && - typeof callback === 'function') { + if (typeof opts === 'function' && typeof callback === 'function') { callback = opts opts = {} } @@ -93,6 +67,91 @@ module.exports = (send) => { args: [key, value], qs: opts }, callback) + }), + + findprovs: promisify((cid, opts, callback) => { + if (typeof opts === 'function' && !callback) { + callback = opts + opts = {} + } + + // opts is the real callback -- + // 'callback' is being injected by promisify + if (typeof opts === 'function' && typeof callback === 'function') { + callback = opts + opts = {} + } + + send.andTransform({ + path: 'dht/findprovs', + args: cid, + qs: opts + }, streamToValue, callback) + }), + + findpeer: promisify((peerId, opts, callback) => { + if (typeof opts === 'function' && !callback) { + callback = opts + opts = {} + } + + // opts is the real callback -- + // 'callback' is being injected by promisify + if (typeof opts === 'function' && typeof callback === 'function') { + callback = opts + opts = {} + } + + send.andTransform({ + path: 'dht/findpeers', + args: peerId, + qs: opts + }, streamToValue, callback) + }), + + provide: promisify((cids, opts, callback) => { + if (typeof opts === 'function' && !callback) { + callback = opts + opts = {} + } + + // opts is the real callback -- + // 'callback' is being injected by promisify + if (typeof opts === 'function' && typeof callback === 'function') { + callback = opts + opts = {} + } + + if (!Array.isArray(cids)) { + cids = [cids] + } + + send({ + path: 'dht/provide', + args: cids, + qs: opts + }, callback) + }), + + // find closest peerId to given peerId + query: promisify((peerId, opts, callback) => { + if (typeof opts === 'function' && !callback) { + callback = opts + opts = {} + } + + // opts is the real callback -- + // 'callback' is being injected by promisify + if (typeof opts === 'function' && typeof callback === 'function') { + callback = opts + opts = {} + } + + send({ + path: 'dht/query', + args: peerId, + qs: opts + }, callback) }) } } From 80e286c2bad16185cc74cd866ac1bb1b2731bc90 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 14 Apr 2017 16:16:15 +0100 Subject: [PATCH 3/4] pass remaining tests --- src/api/dht.js | 6 +++--- src/stream-to-value.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/api/dht.js b/src/api/dht.js index a30d5e609..3f2ef6f4e 100644 --- a/src/api/dht.js +++ b/src/api/dht.js @@ -103,7 +103,7 @@ module.exports = (send) => { } send.andTransform({ - path: 'dht/findpeers', + path: 'dht/findpeer', args: peerId, qs: opts }, streamToValue, callback) @@ -147,11 +147,11 @@ module.exports = (send) => { opts = {} } - send({ + send.andTransform({ path: 'dht/query', args: peerId, qs: opts - }, callback) + }, streamToValue, callback) }) } } diff --git a/src/stream-to-value.js b/src/stream-to-value.js index 6cf0c1ec5..69213f776 100644 --- a/src/stream-to-value.js +++ b/src/stream-to-value.js @@ -7,10 +7,14 @@ const concat = require('concat-stream') Concatenate a stream to a single value. */ function streamToValue (res, callback) { - const done = (data) => callback(null, data) - pump(res, concat(done), (err) => { - if (err) callback(err) - }) + pump( + res, + concat((data) => callback(null, data)), + (err) => { + if (err) { + callback(err) + } + }) } module.exports = streamToValue From 366175563e0611ae0b23a02e5ca0ee032892eef7 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 14 Apr 2017 16:37:37 +0100 Subject: [PATCH 4/4] chore: update deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 855ae18e7..9f9241ee5 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "eslint-plugin-react": "^6.10.3", "gulp": "^3.9.1", "hapi": "^16.1.1", - "interface-ipfs-core": "~0.26.2", + "interface-ipfs-core": "~0.27.0", "ipfsd-ctl": "~0.20.0", "pre-commit": "^1.2.2", "socket.io": "^1.7.3",