How do I configure two nodes to subscribe to the same topic on initial connection

So here’s what I want to do:

  1. Connect Two nodes so that they can talk to each other - Which i can probably achieve by doing ipfs.swarm.connect()
  2. Make the requested node to also subscribe to the same topic that the requesting node is subscribed to. - This is the thing i don’t understand how I could achieve in the initial handshake
    One way I thought of doing this was to make all nodes listen on a common topic where they exchange topic names - but obviously this isn’t safe.
    Other was to manually enter the topic name on each node but this isn’t efficient.
    Is there any other way that i could accomplish this?

So you’re asking how can two systems talk to each other without knowing about each other first? Why is it not efficient for them to know about each other? Unless you’re trying to build a DAO (Decentralized Autonomous Organization) or a Blockchain, I think I’m confused by what your question is. Maybe give more details, reasons, goals.

I’m just trying to build a chat application.
So, let’s say we have two nodes A and B. Now node A wants to send messages to node B so I would do swarm.connect(multiaddr) to connect to node B from node A. Now in order for them to send and receive messages to each other they would have to be subscribed to the same topic and let’s say node A creates a random topic which is unique which B has to subscribe to so that both can talk to each other. So would there any way that I can send this unique topic name to node B when I initially connect.
Found this on YouTube: https://youtu.be/NZb6ybkAYWs. In this the user has to manually enter the topics that they want to subscribe to. I want to be able to send the topic name to node B programmatically so that the subscription can be done without node B having to worry about it

If I were building a chat app, I wouldn’t even worry about “swarms”. Swarms isn’t required for PubSub is it? Maybe all you need is PubSub. Afaik you can just have a single pub sub BUS (i.e. one PubSub name) over which all your traffic runs. Just make each instance of the app listen to this one PubSub name, and make each instance broadcast all events over that same bus. That one app bus would be the way every instance can know about every other instance, and maybe just let the ‘topic name’ be a property INSIDE the payloads you’re sending around?

Okay, I’m not sure if I understood that correctly, but what you’re saying is, make every node subscribe to a common topic(X) and then exchange topic names over the topic X. If this is what you meant by a “common bus” then won’t this allow other nodes to access topic names that weren’t meant for them and if so how can I get the public key associated with this node so that I could encrypt it when I send, and how would I decrypt it ?

I was just saying you really don’t need more than one topic for a group of peers to communicate, but afaik PubSub is still experimental too so I’ve never used it.

Okay, Thanks!!! Also I didn’t have a proper understanding of pubsub and swarm so did a lot of reading on that.

1 Like