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

Peers won't discover neighbors topics subscriptions when relayed #27

Closed
d-roak opened this issue Jun 26, 2024 · 5 comments
Closed

Peers won't discover neighbors topics subscriptions when relayed #27

d-roak opened this issue Jun 26, 2024 · 5 comments
Labels
bug Something isn't working external contributors Open for external contributors

Comments

@d-roak
Copy link
Member

d-roak commented Jun 26, 2024

We are currently having an issue where peers are not aware of their neighbors topics when they use a relay. Everything works perfectly when both peers are in the same network (either localhost or LAN), we assume it would also work if both peers weren't behind NATs and had a direct connection (we didn't tested this).

Things we tested:

  • Both peers create a connection between them (circuit-relay multiaddress)
  • Both peers exchange the identify initial message and fetch the relevant meshsub in the available protocols

Things to check:

Things to test around:

@d-roak d-roak added bug Something isn't working external contributors Open for external contributors labels Jun 26, 2024
@achingbrain
Copy link

By default the Circuit Relay protocol only allows a small amount of data to be transferred over a relayed connection - if the limit is breached the relay will close the connection - this is to ensure relays can be run to help other nodes create direct connections but not be an open relay which is ripe for abuse.

By default there are only a few protocols that will run over relayed connections - Identify is one of them but Gossipsub is not.

Your peers should use the relay to establish a direct connection, over which Gossipsub should run as expected.

@d-roak
Copy link
Member Author

d-roak commented Jul 1, 2024

@achingbrain thanks for helping out! It seems that enabling runOnTransientConnection on both gossipsub configs and stream options fixed the issues of no communication at all.
With what u said, I am afraid we will still have limitations regarding the amount of data transmitted on those connections.

@achingbrain
Copy link

runOnTransientConnection should be left as the default value of false, otherwise you're likely to have your connection closed unexpectedly by the relay once the data/time limits are reached.

Since it works on a LAN and it works via a relay it sounds like the two nodes are failing to make a direct connection.

Have you configured any STUN servers?

If not can you please try updating the config of the two NATed nodes to something like:

const node = await createLibp2p({
  //... other config
  transports: [
    //... other transports
    webRTC({
      rtcConfiguration: {
        iceServers: [{
          urls: ['stun:stun.l.google.com:19302']
        }, {
          urls: ['stun:global.stun.twilio.com:3478']
        }]
      }
    })
  ]
})

There will be something like this as default config in the next release so it shouldn't be necessary forever.

@d-roak
Copy link
Member Author

d-roak commented Jul 3, 2024

Yep. The initial tests we made didn't have the STUN servers configured and the ones that followed had both STUN and relaying enabled, so the results were unclear.

Currently, it's working, we still need to debug some scenarios where there is a connection, the messaging is working, but the handler is failing (high probability is on our side).

We still found some edge cases where STUN is insufficient to make a direct connection (w/ VPNs in the mix). This is out-of-scope for now.

Thank you so much for taking the time to help out fixing our issues!

@d-roak d-roak closed this as completed Jul 3, 2024
@github-project-automation github-project-automation bot moved this from Triage to 🏆 Done in Project Management Jul 3, 2024
@achingbrain
Copy link

Great stuff, glad you got it sorted out.

There will be something like this as default config in the next release so it shouldn't be necessary forever.

This shipped in @libp2p/[email protected] yesterday so you shouldn't need to specify STUN servers manually any more.

Also if you like, please feel free to PR your logo into the js-libp2p README - https://github.com/libp2p/js-libp2p#used-by

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external contributors Open for external contributors
Projects
Archived in project
Development

No branches or pull requests

3 participants
@achingbrain @d-roak and others