Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm.leave(topic) doesn't drop existing peer connections on a topic #50

Open
m4gpi opened this issue Jan 10, 2020 · 2 comments
Open

swarm.leave(topic) doesn't drop existing peer connections on a topic #50

m4gpi opened this issue Jan 10, 2020 · 2 comments

Comments

@m4gpi
Copy link

m4gpi commented Jan 10, 2020

I'm attempting to use a single hyperswarm instance for multiple connections on different topics and want to be able to drop and re-start connections in a granular fashion so I can schedule replication.

@KrishnaPG mentioned a similar question in a previous issue, so forgive me if I've missed the obvious answer there:

Can the swarm.join be called repeatedly multiple times to join different topics, or should different swarm object be created once for each topic? Will duplicate connections to same peer be automatically removed in both cases?

Is it possible for me to use hyperswarm in such a manner at the moment? It seems I can create multiple open connections, but I'm unable to drop a connection once its been opened, which is the behaviour I'd expect after calling swarm.leave(topic). At the moment, when I call swarm.leave(topic) it appears not to drop existing peer connections. Do I need to manually force disconnecting / cancel auto-reconnect with each peer as you mentioned, doing something like...

swarm.on('connection', (socket, details) => {
  details.backoff()
  socket.destroy()
  return
})

my code: https://ledger-git.dyne.org/CoBox/cobox-group-base/src/commit/e6fc3e4ab8668c151cc155d9c43b46485ca3293a/index.js#L79

Thanks!

@mafintosh
Copy link
Contributor

The swarm internally doesn’t know which incoming connections map to which topic, so unfortunately it’s up for the user to close existing ones when you leave a topic.

Leave stops announcing to the dht and stops connecting to people found on the corresponding topic

@m4gpi
Copy link
Author

m4gpi commented Jan 10, 2020

Great okay, so I should just be able to close the stream and it'll drop the peer connection. Thanks!

nestarz pushed a commit to humusities/inhabit that referenced this issue May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants