This repository was 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
Bitswap Quest #195
Merged
Merged
Bitswap Quest #195
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
588018c
start integration of bitswap
dignifiedquire b52e7f1
Implement http commands
dignifiedquire 2882034
bitswap: implement cli basics
dignifiedquire 9d849ee
test(core): add bitswap tests
dignifiedquire 8239b78
test: core tests for bitswap and 3 peers
dignifiedquire cad1265
test(core:bitswap): add file test
dignifiedquire 6d82408
test: increase goOffline delay
dignifiedquire 9763f86
fix(http:object): proper handling of empty args
dignifiedquire 6022b46
feat: integrate libp2p-ipfs-browser
dignifiedquire c9bf67b
no more caching of init files
dignifiedquire ff71738
refactor: replace async with light weight modules
dignifiedquire 45544b6
test: remove .only
dignifiedquire 69c8211
chore: make travis be able to build native addons
dignifiedquire e804947
test: fix remaining tests
dignifiedquire ea70e0b
code review fixes
dignifiedquire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() | ||
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(cb) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)