Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -65,8 +65,8 @@
"dirty-chai": "^1.2.2",
"eslint-plugin-react": "^6.10.3",
"gulp": "^3.9.1",
"hapi": "^16.1.0",
"interface-ipfs-core": "~0.26.2",
"hapi": "^16.1.1",
"interface-ipfs-core": "~0.27.0",
"ipfsd-ctl": "~0.20.0",
"pre-commit": "^1.2.2",
"socket.io": "^1.7.3",
Expand Down Expand Up @@ -127,4 +127,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
123 changes: 91 additions & 32 deletions src/api/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 = {}
}
Expand All @@ -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/findpeer',
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.andTransform({
path: 'dht/query',
args: peerId,
qs: opts
}, streamToValue, callback)
})
}
}
12 changes: 8 additions & 4 deletions src/stream-to-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -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