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

ambient peer discovery in the browser #1865

Closed
tabcat opened this issue Jul 3, 2023 · 7 comments
Closed

ambient peer discovery in the browser #1865

tabcat opened this issue Jul 3, 2023 · 7 comments
Assignees
Labels
need/triage Needs initial labeling and prioritization

Comments

@tabcat
Copy link
Contributor

tabcat commented Jul 3, 2023

  • Version: libp2p@0.45.9
  • Platform: Linux joemama 5.19.0-45-generic # 46~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 7 15:06:04 UTC 20 x86_64 x86_64 x86_64 GNU/Linux
  • Browser: Brave (Chromium)
  • Subsystem: Relay, Pubsub

Severity: High

Description:

Clients are not discovering each other passively. After connecting them manually and subscribing to the same pubsub topic; peers become pubsub peers but never add each other to the topic mesh.

Steps to reproduce the error:

https://github.com/tabcat/libp2p-pubsub

@tabcat tabcat added the need/triage Needs initial labeling and prioritization label Jul 3, 2023
@maschad maschad self-assigned this Jul 3, 2023
@tabcat
Copy link
Contributor Author

tabcat commented Jul 4, 2023

Getting an error when calling pubsub.publish

Uncaught TypeError: Cannot read properties of undefined (reading 'Message')
    at buildRawMessage (buildRawMessage.ts:43:1)
    at GossipSub.publish (index.ts:2050:1)
    at <anonymous>:1:30

Looks like RPC is undefined.

https://github.com/ChainSafe/js-libp2p-gossipsub/blob/89c82f6c06ee29e0b7c84ef4165ba38ff672394c/src/utils/buildRawMessage.ts#L40

Probably due to bundler?

@tabcat
Copy link
Contributor Author

tabcat commented Jul 4, 2023

Most of the pubsub mesh issue was due to the bundler resolving .cjs files. Related: facebook/create-react-app#12700

However the passive peer discovery is still not working for the circuit-relay topology. Also seeing one side of pubsub not seeing the remote subscriber.

@tabcat tabcat changed the title peer discovery and pubsub in the browser ambient peer discovery in the browser Jul 4, 2023
@bradwbradw
Copy link
Contributor

bradwbradw commented Jul 5, 2023

I was trying to get browser peers to discover eachother for a really long time during the last hackFS, never was successful. Seeing this issue pop up makes me feel less like I was shooting myself in the foot, so thank you.

I forked your repro and added some simple GUI: https://github.com/bradwbradw/libp2p-pubsub

There's two instances of libP2P, both available in window as libp2p1 and libp2p2

You can see, for each instance: the self peer ID, the peer store, and a list of peers that have been discovered

My system:
MacOS Monterey 12.6.7
Firefox
NodeJS v19.9.0

Also unable to see the peers discover eachother via the relay node.
Screen Shot 2023-07-05 at 2 05 24 PM

I would expect to see two peers in the peer store and in the discovered peers list. But only seeing itself.

Also want to point out, there is some kind of race condition whereby starting and stopping the relay server / refreshing the browser window using different timings causes a crash, but it's pretty hard to reproduce reliably:

Screen Shot 2023-07-05 at 2 01 28 PM

When it is reproduced, refreshing the browser consistently shows the crash. Restarting the relay server can fix it.

(note: I had a larger post before but found that most of the notes I made were just to do with how libp2p was being integrated into React. In the current state react is happy with no linting warnings, and it's behaving quite consistently, and React.StrictMode is off. I did get it to discover the other peer at one point while thrashing about in the code but I haven't been able to get that state back.)

@tabcat
Copy link
Contributor Author

tabcat commented Jul 18, 2023

Working fine for me now, must have been doing something wrong.

@tabcat tabcat closed this as completed Jul 18, 2023
@maschad
Copy link
Member

maschad commented Jul 18, 2023

Thanks for following up @tabcat :)

@bradwbradw I took a look at your peer discovery config and I noted that you're using gossipsub but with no configuration, to avoid going into the complexities of gossipsub, have you tried seeing if you are able to discover peers using a bootstrap node and then connect that way? You can take a look at this example as a starting point, but I think the issue @tabcat raised is unrelated to what you are trying to solve.

If you are still having problems after trying that, feel free to open an new issue using our issue template

@bradwbradw
Copy link
Contributor

@tabcat are you able to share what you were doing wrong or what you discovered?

Thanks @maschad I will take another look and open a new issue if need be

@tabcat
Copy link
Contributor Author

tabcat commented Jul 29, 2023

@bradwbradw turning on debug logs for circuit-relay helped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
Archived in project
Development

No branches or pull requests

3 participants