-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bitswap Quest #195
Bitswap Quest #195
Changes from 14 commits
588018c
b52e7f1
2882034
9d849ee
8239b78
cad1265
6d82408
9763f86
6022b46
c9bf67b
ff71738
45544b6
69c8211
e804947
ea70e0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
const gulp = require('gulp') | ||
const parallel = require('run-parallel') | ||
const series = require('run-series') | ||
const createTempNode = require('./test/utils/temp-node') | ||
const API = require('./src/http-api') | ||
|
||
let nodes = [] | ||
|
||
function startNode (num, done) { | ||
createTempNode(num, (err, node) => { | ||
if (err) throw err | ||
|
||
const api = new API(node.repo.path()) | ||
nodes.push(api) | ||
api.start(done) | ||
}) | ||
} | ||
|
||
gulp.task('libnode:start', (done) => { | ||
nodes = [] | ||
parallel([ | ||
(cb) => startNode(7, cb), | ||
(cb) => startNode(8, cb), | ||
(cb) => startNode(9, cb) | ||
], done) | ||
}) | ||
|
||
gulp.task('libnode:stop', (done) => { | ||
series(nodes.map((node) => (cb) => { | ||
setTimeout(() => node.stop(cb), 500) | ||
}), done) | ||
}) | ||
|
||
gulp.task('test:browser:before', ['libnode:start']) | ||
gulp.task('test:node:before', ['libnode:start']) | ||
gulp.task('test:browser:after', ['libnode:stop']) | ||
gulp.task('test:node:after', ['libnode:stop']) | ||
|
||
require('aegir/gulp')(gulp) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
const utils = require('../../utils') | ||
|
||
module.exports = Command.extend({ | ||
desc: 'Show some diagnostic information on the bitswap agent.', | ||
|
||
options: { | ||
}, | ||
|
||
run: () => { | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
ipfs.bitswap.stat((err, stats) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
stats.Wantlist = stats.Wantlist || [] | ||
stats.Peers = stats.Peers || [] | ||
|
||
console.log(` | ||
bitswap status | ||
blocks received: ${stats.BlocksReceived} | ||
dup blocks received: ${stats.DupBlksReceived} | ||
dup data received: ${stats.DupDataReceived}B | ||
wantlist [${stats.Wantlist.length} keys] | ||
${stats.Wantlist.join('\n ')} | ||
partners [${stats.Peers.length}] | ||
${stats.Peers.join('\n ')}`) | ||
}) | ||
}) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
const utils = require('../../utils') | ||
|
||
module.exports = Command.extend({ | ||
desc: 'Remove a given block from your wantlist.', | ||
|
||
options: { | ||
key: { | ||
required: true | ||
} | ||
}, | ||
|
||
run: (key) => { | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
// TODO: implement | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's throw a error here saying that it is not implemented yet |
||
}) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
const utils = require('../../utils') | ||
|
||
module.exports = Command.extend({ | ||
desc: 'Print out all blocks currently on the bitswap wantlist for the local peer.', | ||
|
||
options: { | ||
}, | ||
|
||
run: () => { | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
ipfs.bitswap.wantlist((err, res) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
res.Keys.forEach((k) => console.log(k)) | ||
}) | ||
}) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict' | ||
|
||
const bs58 = require('bs58') | ||
|
||
const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR | ||
|
||
function formatWantlist (list) { | ||
return Array.from(list).map((el) => { | ||
return bs58.encode(new Buffer(el[0], 'hex')) | ||
}) | ||
} | ||
|
||
module.exports = function bitswap (self) { | ||
return { | ||
wantlist: () => { | ||
if (!self.isOnline()) { | ||
throw OFFLINE_ERROR | ||
} | ||
|
||
const list = self._bitswap.getWantlist() | ||
return formatWantlist(list) | ||
}, | ||
stat: () => { | ||
if (!self.isOnline()) { | ||
throw OFFLINE_ERROR | ||
} | ||
|
||
const stats = self._bitswap.stat() | ||
stats.wantlist = formatWantlist(stats.wantlist) | ||
stats.peers = stats.peers.map((id) => id.toB58String()) | ||
|
||
return stats | ||
}, | ||
unwant: (key) => { | ||
if (!self.isOnline()) { | ||
throw OFFLINE_ERROR | ||
} | ||
|
||
// TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
const debug = require('debug') | ||
const log = debug('core:offline') | ||
|
||
module.exports = function goOffline (self) { | ||
return (cb) => { | ||
self._blockS.goOffline() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't blockS also stop bitswap? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it just removes bitswap from the blockservice |
||
self._bitswap.stop() | ||
self.libp2p.stop((err) => { | ||
if (err) { | ||
log('Error trying to go offline', err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no return, no throw or cb(err)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
cb() | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that travis can build native modules (node 4 and greater require a c++ compiler for those) Details here: https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, which are the native modules that we have introduced with bitswap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None that we really need, travis was just complaining and I wanted to fix that (those native modules are mostly used through aegir)