Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

chat doesn't broadcast to all peers #35

Open
tanhuiya opened this issue Dec 24, 2018 · 2 comments
Open

chat doesn't broadcast to all peers #35

tanhuiya opened this issue Dec 24, 2018 · 2 comments

Comments

@tanhuiya
Copy link

steps :

  • run go run chat.go in first window
  • run go run chat.go -d /ip4/127.0.0.1/tcp/64717/p2p/QmefMVVk1tZzfYshYVUFpnwNswtqgXrD6geWo3PFUzQX1Q in second window.
  • run go run chat.go -d /ip4/127.0.0.1/tcp/64717/p2p/QmefMVVk1tZzfYshYVUFpnwNswtqgXrD6geWo3PFUzQX1Q in third window.

Then ,when I type any message such as

> aaa
> bbb

Only the second window receive aaa
the third window receive bbb
so, how can they receive all messages ?

@anacrolix anacrolix changed the title cann't chat each other. chat doesn't broadcast to all peers Dec 30, 2018
@anacrolix
Copy link
Contributor

I can confirm this behaviour. It doesn't appear that broadcasting to all connected peers is a documented behaviour. It could be if the receiver tracked all received streams, and duplicated messages amongst all peers.

@JackBekket
Copy link

Ok, look, first of all, you should know that Stream interface is a bidirectional link between two nodes, it's not a multichannel.

Also, you should know, that as far as example have only one stream variable instead of global mapping of streams - it will be owerwritten each time you have a new connection. If you want to communicate with multiple devices - you should have a stream mapping (or array) and append any new stream connection to it.

Then, if you want to implement multicast as your own, you should probably map each stream to some 'topic', and when you want to multicast message to every peer in topic list - you should send message to all streams on that topic.

However, instead of creating this mapping and creating multicast mechanism of your own, you can use PubSub mechanism, which has been created for those purposes.

You can find PubSub here: https://github.com/libp2p/go-libp2p-pubsub

P.S I would appreciate if someone will add PubSub example to this repo.

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

No branches or pull requests

3 participants