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

Commit

Permalink
feat: implement bitswap wantlist peer ID param and bitswap unwant (#761)
Browse files Browse the repository at this point in the history
* fix(bitswap.unwant) Parse CID from arg

* feat(bitswap.wantlist) add peer parameter

* chore: simplify CID parsing for wantlist and unwant

* chore: update interface-ipfs-core dependency

* chore: upgrades interface-ipfs-core dependency

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
  • Loading branch information
wraithgar authored and alanshaw committed Jun 18, 2018
1 parent 7fb2e07 commit 73a153e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 74 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"eslint-plugin-react": "^7.9.1",
"go-ipfs-dep": "~0.4.15",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.67.0",
"interface-ipfs-core": "~0.68.1",
"ipfsd-ctl": "~0.37.3",
"pull-stream": "^3.6.8",
"socket.io": "^2.1.1",
Expand Down
12 changes: 10 additions & 2 deletions src/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
'use strict'

const promisify = require('promisify-es6')
const CID = require('cids')

module.exports = (send) => {
return promisify((args, opts, callback) => {
return promisify((cid, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

try {
cid = new CID(cid)
} catch (err) {
return callback(err)
}

send({
path: 'bitswap/unwant',
args: args,
args: cid.toBaseEncodedString(),
qs: opts
}, callback)
})
Expand Down
23 changes: 21 additions & 2 deletions src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
'use strict'

const promisify = require('promisify-es6')
const CID = require('cids')

module.exports = (send) => {
return promisify((callback) => {
return promisify((peerId, opts, callback) => {
if (typeof (peerId) === 'function') {
callback = peerId
opts = {}
peerId = null
} else if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

if (peerId) {
try {
opts.peer = new CID(peerId).toBaseEncodedString()
} catch (err) {
return callback(err)
}
}

send({
path: 'bitswap/wantlist'
path: 'bitswap/wantlist',
qs: opts
}, callback)
})
}
69 changes: 0 additions & 69 deletions test/bitswap.spec.js

This file was deleted.

32 changes: 32 additions & 0 deletions test/interface/bitswap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env mocha */

'use strict'

const test = require('interface-ipfs-core')
const parallel = require('async/parallel')

const IPFSApi = require('../../src')
const f = require('../utils/factory')

const nodes = []
const common = {
setup: function (callback) {
callback(null, {
spawnNode: (cb) => {
f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, IPFSApi(_ipfsd.apiAddr))
})
}
})
},
teardown: function (callback) {
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
}
}

test.bitswap(common)

0 comments on commit 73a153e

Please sign in to comment.