-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
// NOTE: Floodsub CLI is not tested. Tests will not be run until | ||
// https://github.com/ipfs/js-ipfs-api/pull/377 | ||
// is merged | ||
module.exports = { | ||
command: 'floodsub', | ||
|
||
description: 'floodsub commands', | ||
|
||
builder (yargs) { | ||
return yargs | ||
.commandDir('floodsub') | ||
}, | ||
|
||
handler (argv) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict' | ||
|
||
const utils = require('../../utils') | ||
const debug = require('debug') | ||
const log = debug('cli:floodsub') | ||
log.error = debug('cli:floodsub:error') | ||
|
||
module.exports = { | ||
command: 'pub <topic> <message>', | ||
|
||
describe: 'Publish a message to a topic', | ||
|
||
builder: {}, | ||
|
||
handler (argv) { | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
ipfs.floodsub.pub(argv.topic, argv.message, (err) => { | ||
if (err) { | ||
throw err | ||
} | ||
}) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const utils = require('../../utils') | ||
const debug = require('debug') | ||
const log = debug('cli:floodsub') | ||
log.error = debug('cli:floodsub:error') | ||
|
||
module.exports = { | ||
command: 'sub <topic>', | ||
|
||
describe: 'Subscribe to a topic', | ||
|
||
builder: {}, | ||
|
||
handler (argv) { | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
ipfs.floodsub.sub(argv.topic, (err, stream) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
console.log(stream.toString()) | ||
}) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const HttpAPI = require('../../src/http-api') | ||
const createTempNode = require('../utils/temp-node') | ||
const repoPath = require('./index').repoPath | ||
const ipfs = require('../utils/ipfs-exec')(repoPath) | ||
|
||
// NOTE: Floodsub CLI tests will not be run until | ||
// https://github.com/ipfs/js-ipfs-api/pull/377 | ||
// is merged | ||
describe.skip('floodsub', function () { | ||
this.timeout(30 * 1000) | ||
let node | ||
|
||
const topic = 'nonscents' | ||
const message = new Buffer('Some non cents.') | ||
|
||
before((done) => { | ||
createTempNode(1, (err, _node) => { | ||
expect(err).to.not.exist | ||
node = _node | ||
node.goOnline((err) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
node.goOffline(done) | ||
}) | ||
|
||
describe('api running', () => { | ||
let httpAPI | ||
const called = true | ||
|
||
before((done) => { | ||
httpAPI = new HttpAPI(repoPath) | ||
httpAPI.start((err) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
httpAPI.stop((err) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
}) | ||
|
||
it('pub', () => { | ||
return ipfs('floodsub', 'pub', topic, message).then((out) => { | ||
expect(called).to.eql(true) | ||
}) | ||
}) | ||
|
||
it('sub', () => { | ||
return ipfs('floodsub', 'sub', topic).then((out) => { | ||
expect(out).to.have.length.above(0) | ||
}) | ||
}) | ||
}) | ||
}) |
3 comments
on commit 12ec5c3
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.
cc: @diasdavid
These commits are the initial implementation of floodsub into js-ipfs
core :) I would love to get a code review here to start tightening things up!
I was building against this unmerged api change, so there are a few test placeholders in my code for the CLI and js-ipfs-api
tests.
Here are the relevant commits—sorry I can't squash them due to syncing with the upstream (let me know if you have any suggestions to clean this up...)
Most recent listed first...
- commit 12ec5c3ca504f3710fc001274977d85774a6ab96
- commit d3c4f021ff0b723fcea66dc3d0037da61fcb2048
- commit 641fe1cf7978c4463e7bb954c81a618d99a9558c
Questions:
-
I ended up not adding an explicit
floodsub.start
method that we could call from the core'sgoOnline
function. The wayfloodsub
connects to peers was causing issues with ports in use and the like. In order to avoid pubsub-specific-implementation-issues affecting the core (which I do not think they should), I initializeFloodSub
from within the module itself. Are you ok with this? Any thoughts? -
In the
floodsub.sub
call, what should I do with theoptions.discover
param? (I saw it passed in the API call I was building against)
-- Where it manifests in my code
-- Where I saw this in the request
Thanks a ton David! The feedback and ideas are greatly appreciated!
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.
Hey Hey @gavinmcdermott :D Off to a great start I see :)
It would be great if this communication happened within a PR to js-ipfs, it helps to keep track of things and give review.
Have you went through the design thinking process of handling unsubscribes? Namely: ipfs#580 (comment)
I ended up not adding an explicit floodsub.start method that we could call from the core's goOnline function. The way floodsub connects to peers was causing issues with ports in use and the like. In order to avoid pubsub-specific-implementation-issues affecting the core (which I do not think they should), I initialize FloodSub from within the module itself. Are you ok with this? Any thoughts?
Sounds good for now, although we will want something that offers a more fine grained control. Related discussion: ipfs#556
In the floodsub.sub call, what should I do with the options.discover param? (I saw it passed in the API call I was building against)
-- Where it manifests in my code
-- Where I saw this in the request
Unfortunately nothing right now, we don't have the DHT.
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.
@diasdavid: Thank you for the comments.
It would be great if this communication happened within a PR to js-ipfs
My goal is to open this PR later today :)
Have you went through the design thinking process of handling unsubscribes?
Yes. unsubscribe
is happening this morning.
Sounds good for now, although we will want something that offers a more fine grained control.
I had a sense of this....I'll add back in the start
method that can be called to initialize FloodSub.
Thanks again for the feedback; it cultivates a great community, D!
not much really, we don't have the DHT right now