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

feat: Bitswap wantlist peerid #761

Merged
merged 5 commits into from
Jun 18, 2018
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
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)