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

No peer connections if joining after swarm initialization #67

Open
freddi301 opened this issue Oct 9, 2020 · 2 comments
Open

No peer connections if joining after swarm initialization #67

freddi301 opened this issue Oct 9, 2020 · 2 comments

Comments

@freddi301
Copy link

freddi301 commented Oct 9, 2020

testing on the same machine, and 2 machines over LAN

two nodes connect as expected

// pc a
const swarm = hyperswarm()
swarm.join(hash, {lookup:true, announce: true})
swarm.on("connection", () => { console.log("yuppie") })
// pc b
const swarm = hyperswarm()
swarm.join(hash, {lookup:true, announce: true})
swarm.on("connection", () => { console.log("yuppie") })

two nodes does not connect

// pc a
const swarm = hyperswarm()
setTimeout(() => swarm.join(hash, {lookup:true, announce: true}), 5000)
swarm.on("connection", () => { console.log("never happens") })
// pc b
const swarm = hyperswarm()
setTimeout(() => swarm.join(hash, {lookup:true, announce: true}), 10000)
swarm.on("connection", () => { console.log("never happens") })

workaround (the nodes connect)

// pc a
const swarm = hyperswarm()
swarm.network.bind()
setTimeout(() => swarm.join(hash, {lookup:true, announce: true}), 5000)
swarm.on("connection", () => { console.log("yuppie") })
// pc b
const swarm = hyperswarm()
swarm.network.bind()
setTimeout(() => swarm.join(hash, {lookup:true, announce: true}), 10000)
swarm.on("connection", () => { console.log("yuppie") })

Maybe i am missing something in the docs?
Maybe it has something to do with how discovery cycle works?

@mafintosh
Copy link
Contributor

When you say “working” what do you mean exactly? Can you provide a full gist of a non working example? That’ll make it easier to help

@freddi301
Copy link
Author

freddi301 commented Oct 10, 2020

repo https://github.com/freddi301/p2p-network-tools/tree/master/desktop
If i join a common topic right after initializing the swarm, the two nodes do connect.
If i join a common topic some time after initializing swarm the two nodes do not connect.
If i call swarm.network.bind() right after swarm initialization and join a common topic some time after, the two nodes do connect.
I updated the description

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