holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.06k stars 85 forks source link

P2P topic (vs server/client) - how to? #95

Closed KrishnaPG closed 2 years ago

KrishnaPG commented 2 years ago

Wondering how to create a "well-known" topic that any node can join and start publishing their messages (as a true P2P swarm)?

The API currently seems to be "server / client" oriented, as in, someone should have started the topic before others can join and participate.

 swarm1.join(topic, { server: true, client: false })

It is not clear

  1. what happens if the server is not started and
  2. can the clients publish messages on the topic for all other peers to receive (or only server allowed)?

This seems to be a problem for scenarios where every node wants to join a "well-known" topic and starts publishing messages for all other peers to listen. i.e. every node is equal in that:

  1. the topic is accessible to all nodes equally and
  2. anyone can publish messages for all others interested in that topic and
  3. bringing down one or few nodes will not bring down the topic or swarm (since there is no "server" for the topic).

What is the mechanism for achieving the above, where by any node can just join one "well-known" topic and start publishing messages in a true p2p swarm mode?

Nuhvi commented 2 years ago

Wait for the answer from the team, but here is my understanding:

It is a little confusing, but those are alternative naming for the old announce/ lookup.

Any node that sets server: true can be found by other nodes, that are setting client: true

If you want the nodes in your app to both to listen and publish to all other nodes, then just set them all to server: true, client: true If some nodes need to publish only and are not interested in listening to others, set it to server: true, client: false If some nodes need to download updates only, but never publish anything, set it to sever: false, client: true

No need to wait for any special node to run as a server first.

KrishnaPG commented 2 years ago

Thank you @Nazeh It is helpful

If you want the nodes in your app to both to listen and publish to all other nodes, then just set them all to server: true, client: true

Hope someone from the Hyperswarm team could confirm it.

mafintosh commented 2 years ago

Yep! What @Nazeh said. Open for better names, and in most cases you just want to use the default (both true)

KrishnaPG commented 2 years ago

Thank you @mafintosh

IMO, the announce/ lookup made more sense than server / client (it is very difficult to break out of the server-client mode of thinking when the options use those names)

mafintosh commented 2 years ago

👍 might change it back (backwards compat obvs)

mafintosh commented 2 years ago

other candidates: passive / active

KrishnaPG commented 2 years ago

+1 for announce / lookup (semantically more relative to p2p swarm than passive / active)