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

floodsub api #377

Closed
wants to merge 1 commit into from
Closed

floodsub api #377

wants to merge 1 commit into from

Conversation

victorb
Copy link
Contributor

@victorb victorb commented Sep 13, 2016

First iteration on the publish/subscribe that is being introduced in go-ipfs

Missing things

  • Readme information about IPFS_EXEC having to be pointed to go-ipfs running with pub/sub when running tests no necessary if we get go-ipfs-npm to use new binary instead
  • Information about how to use it
  • go-ipfs-npm having access to the pubsub, so it'll be downloaded when running
  • Add --discover flag
  • Rebase once reviewing is done
  • Rebase from master again

}

var rs = new Stream()
rs.readable = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use through2 instead, that way you can pipe the respons into your transform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, we've decided to keep using Stream for now, and maybe investigate using through2 in the future instead.

@haadcode
Copy link
Contributor

Looking good @victorbjelkholm! Couple of small notes to simplify the code.

Would you want to expand the tests to include a test for peerA to peerB to make sure two peers are talking? This doesn't really fall under unit tests but imo would be good to get into a habit of writing simple integration tests, too. That way our test suites can spot when deps break. Not needed for this PR to be merged imo, but would be nice addition.

rs.cancel = () => {
request.abort()
activeSubscriptions = removeSubscription(activeSubscriptions, topic)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now defined twice

Copy link
Contributor Author

@victorb victorb Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my thinking is that if you're canceling the subscription before you got one message, we need to cancel the subscription and update the list of subscriptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but the outer definition is enough, you are only duplicating the same code in the inner one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course. Thanks

@victorb
Copy link
Contributor Author

victorb commented Sep 13, 2016

@haadcode

Thanks for reviewing!

Would you want to expand the tests to include a test for peerA to peerB to make sure two peers are talking?

Test for pub/sub between nodes added 👍

@victorb
Copy link
Contributor Author

victorb commented Sep 14, 2016

@haadcode @dignifiedquire @diasdavid finished all outstanding tasks, only thing missing is a rebase.

Can you confirm everything looks good?

ipfsApi.pubsub.subscribe('my-topic', (err, subscription) => {
if (err) {
console.log('Something went wrong setting up the subscription')
throw err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 2 space indents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, got no linting for .md files ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet :P

@dignifiedquire
Copy link
Contributor

If CI is happy, I am happy

return Object.assign({}, message, {
from: bs58.encode(message.from),
data: Base64.decode(message.data),
seqno: Base64.decode(message.seqno)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whyrusleeping you are base64 encoding all the messages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, it is just when it comes through the http-api

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base64 encoding happens on buffers in json

@victorb
Copy link
Contributor Author

victorb commented Sep 14, 2016

@dignifiedquire @diasdavid Tests passes in CircleCI, Travis? Not so much... Everything is passing in local as well, so not sure what's going on. If you could please take a look, I would be forever grateful:

  1) .log .log.tail:

     Uncaught AssertionError: expected undefined to exist

      at test/interface-ipfs-core/log.spec.js:34:23

      at src/api/log.js:9:590

      at src/request-api.js:9:2732

      at options.beforeRedirect.finish (node_modules/wreck/lib/index.js:229:20)

      at wrapped (node_modules/hoek/lib/index.js:871:20)

      at ClientRequest.options.beforeRedirect.onResponse (node_modules/wreck/lib/index.js:180:20)

      at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:433:21)

      at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)

      at Socket.socketOnData (_http_client.js:322:20)

      at readableAddChunk (_stream_readable.js:153:18)

      at Socket.Readable.push (_stream_readable.js:111:10)

      at TCP.onread (net.js:536:20)

https://travis-ci.org/ipfs/js-ipfs-api/jobs/159910037

@victorb victorb force-pushed the feat-pubsub branch 2 times, most recently from 59f8d9f to 6e51424 Compare September 15, 2016 07:54
This commit adds publish/subscribe methods to js-ipfs-api. These
changes requires special version of go-ipfs currently, with pub/sub
activated.
@victorb
Copy link
Contributor Author

victorb commented Sep 15, 2016

For future reference: travis is trash. I'm working from a branch in my repo and in a PR to this repo. I accidently pushed to upstream repo once, deleted the branch shortly after, and now Travis is trying to use the upstream branch instead of from my fork. So the Travis status here is from js-ipfs-api/feat-pubsub but this PR is actually from VictorBjelkholm/feat-pubsub. Just to keep in mind

@victorb
Copy link
Contributor Author

victorb commented Sep 15, 2016

@diasdavid @dignifiedquire Finally, everything is passing and CR comments have been addressed.

@dignifiedquire
Copy link
Contributor

@victorbjelkholm do we want to merge this into master or into a separate branch? Given that usually master corresponds with what's available in a go-ipfs release I would suggest to put it into a pubsub branch and release it under a tag, rather than an official release.

@victorb
Copy link
Contributor Author

victorb commented Sep 15, 2016

@dignifiedquire good question. I think separate branch is good enough, and then release it under a tag, as you suggested.

Question is, how do we keep it up to date with master? Manual merges?

The branch already live in ipfs/js-ipfs-api under the name feat-pubsub, maybe we can just close this and make a release from there?

@dignifiedquire
Copy link
Contributor

The branch already live in ipfs/js-ipfs-api under the name feat-pubsub, maybe we can just close this and make a release from there?

Sounds good to me.

Lets wait for @diasdavid to wake up and ask him if he has any objections

@daviddias
Copy link
Contributor

daviddias commented Sep 15, 2016

Let's do branch (feat/floodsub) only and keep that branch in this repo.

I still need review the code, but I can do it under the new branch, will CR once I get to integrate floodsub it in js-ipfs and think through the API as a whole for both lands (already had some discussions with @whyrusleeping on how to make sure we don't make the API very HTTP biased, as the HTTP should be invisible). This probably won't happen until after DEVCON.

@victorb
Copy link
Contributor Author

victorb commented Sep 17, 2016

@diasdavid Sounds good, I'll leave this PR as-is for now then.

@daviddias daviddias changed the title Publish/Subscribe floodsub api Oct 17, 2016
@daviddias
Copy link
Contributor

can we namespace the api under floodsub? I'm worried that we might have to make a breaking API change in the future when we get tree forming, if we use pubsub from the start.

@victorb
Copy link
Contributor Author

victorb commented Oct 17, 2016

@diasdavid

can we namespace the api under floodsub?

Might be confusing if we mix (comparing to go-ipfs where it's under pubsub rather than floodsub). What you think?

@daviddias
Copy link
Contributor

@victorbjelkholm true (I'm still trying to convince @whyrusleeping to namespace it under floodsub too :D)

@victorb
Copy link
Contributor Author

victorb commented Oct 17, 2016

@diasdavid ah, haha, I see... Well, if you want me to move, I'll do that, I would agree that it could make it easier for the future.

@dignifiedquire
Copy link
Contributor

I have a rebased branch on my machine which I will push tomorrow.

@haadcode
Copy link
Contributor

I'm refactoring this as the implementation here was always considered temp. The work happens here: https://github.com/haadcode/js-ipfs-api/blob/fix/pubsub/src/api/pubsub.js.

There's still a lot to be done, but got it up to a fairly good point yesterday. I added a really nice test to make sure messages flow nicely: https://github.com/haadcode/js-ipfs-api/blob/fix/pubsub/test/ipfs-api/pubsub.spec.js#L157.

Will keep you updated.

@daviddias
Copy link
Contributor

@haadcode Is this the PR that I should be looking at and testing against the tests at interface-ipfs-core?

@daviddias
Copy link
Contributor

@haadcode should we close this PR in favor of one coming from https://github.com/haadcode/js-ipfs-api ? //cc @victorbjelkholm

@haadcode
Copy link
Contributor

haadcode commented Dec 6, 2016

Yeah, we can close this.

@daviddias daviddias closed this Dec 6, 2016
@daviddias daviddias removed the ready label Dec 6, 2016
@daviddias
Copy link
Contributor

Follow #470

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants