This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from ipfs/feat/bitswap
Bitswap Quest
- Loading branch information
Showing
39 changed files
with
832 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ')}`) | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
throw new Error('Not implemented yet') | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
module.exports = function goOffline (self) { | ||
return (cb) => { | ||
self._blockS.goOffline() | ||
self._bitswap.stop() | ||
self.libp2p.stop(cb) | ||
} | ||
} |
Oops, something went wrong.