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

Discovery mechanisms example: Pubsub-Peer-Discovery not discovering peers. #1229

Closed
sneaker1 opened this issue May 26, 2022 · 3 comments · Fixed by #1365
Closed

Discovery mechanisms example: Pubsub-Peer-Discovery not discovering peers. #1229

sneaker1 opened this issue May 26, 2022 · 3 comments · Fixed by #1365
Assignees
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@sneaker1
Copy link
Contributor

In the discovery mechanism example Part 3 Pubsub based Peer Discovery is a problem.

https://github.com/libp2p/js-libp2p/tree/master/examples/discovery-mechanisms#3-pubsub-based-peer-discovery

If i run the 3.js i can not discover other peers.
Here is my output:

> node 3.js
libp2p relay starting with id: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Node 0 starting with id: 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg
Node 1 starting with id: 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWSiExtrTywWfj3xoFFqSPV7kJqwkBQaxJuwB4m9BEntQg discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3
Peer 12D3KooWDgxwvf5p6BCmyYL3Srzff9FhPWLGJeq7w97d4nsERfFm discovered: 12D3KooWNZcrYfNvQ5kkbMZnPJVwQ28R4LkdH34pJsDuUFMWpXg3

As you can see only the bootstrap peer-id is discovered.
The peer-ids of node 0 and node 1 are not discovered.

According to the example the output should be like this. (Node 0 and Node 1 are discovered)

> node 3.js
libp2p relay starting with id: QmW6FqVV6RsyoGC5zaeFGW9gSWA3LcBRVZrjkKMruh38Bo
Node 0 starting with id: QmezqDTmEjZ5BfMgVqjSpLY19mVVLTQ9bE9mRpZwtGxL8N
Node 1 starting with id: QmYWeom2odTkm79DzB68NHULqVHDaNDqHhoyqLdcV1fqdv
Peer QmezqDTmEjZ5BfMgVqjSpLY19mVVLTQ9bE9mRpZwtGxL8N discovered: QmW6FqVV6RsyoGC5zaeFGW9gSWA3LcBRVZrjkKMruh38Bo
Peer QmYWeom2odTkm79DzB68NHULqVHDaNDqHhoyqLdcV1fqdv discovered: QmW6FqVV6RsyoGC5zaeFGW9gSWA3LcBRVZrjkKMruh38Bo
Peer QmYWeom2odTkm79DzB68NHULqVHDaNDqHhoyqLdcV1fqdv discovered: QmezqDTmEjZ5BfMgVqjSpLY19mVVLTQ9bE9mRpZwtGxL8N
Peer QmezqDTmEjZ5BfMgVqjSpLY19mVVLTQ9bE9mRpZwtGxL8N discovered: QmYWeom2odTkm79DzB68NHULqVHDaNDqHhoyqLdcV1fqdv

I assume the example has worked before. So maybe there is a problem in the current versions of libp2p.

I am running the most recent versions. Here are the dependencies from my package.json:

"dependencies": {
  "@chainsafe/libp2p-noise": "^6.2.0",
  "@libp2p/bootstrap": "^1.0.6",
  "@libp2p/floodsub": "^1.0.7",
  "@libp2p/mplex": "^1.1.0",
  "@libp2p/pubsub-peer-discovery": "^5.0.4",
  "@libp2p/tcp": "^1.0.11",
  "libp2p": "^0.37.1"
}
@sneaker1 sneaker1 added the need/triage Needs initial labeling and prioritization label May 26, 2022
@sethhrbek
Copy link

sethhrbek commented Jun 10, 2022

I believe the issue is in the @libp2p/pubsub-peer-discovery package ---- the broadcast function is publishing a message in a different format than onMessage is expecting to receive.

In versions prior to 5 (<= 4), broadcast was broadcasting via:
publish(topic, encodedPeer)

As of version 5 it is doing:

pubsub.dispatchEvent(new CustomEvent('message', {
  detail: encodedPeer
}))

In v5, onMessage has signature:
_onMessage (event: CustomEvent<Message>)

And Message interface is:

export interface Message {
  from: PeerId
  topic: string
  data: Uint8Array
  sequenceNumber?: bigint
  signature?: Uint8Array
  key?: Uint8Array
}

@mpetrunic
Copy link
Member

@sneaker1 We think it's fixed in the latest libp2p version, can you try using latest version?

@mpetrunic mpetrunic added need/author-input Needs input from the original author and removed need/triage Needs initial labeling and prioritization labels Aug 30, 2022
@zargarzadehm
Copy link

@sneaker1 We think it's fixed in the latest libp2p version, can you try using latest version?

I tested that but exist this problem yet :((

➜  discovery-mechanisms git:(master) ✗ node 3.js
libp2p relay starting with id: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Node 0 starting with id: 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi
Node 1 starting with id: 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWMVc4etyuv1A15Dx6dmdNEeTDYY2vmRZuutXGQZ23x1Gi discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR
Peer 12D3KooWETSnb9tsdE9SkJ2BLY7JveFD9YLRiXUq7m6X1eGjk8NS discovered: 12D3KooWQ6RS7HuSsfwpuYeskzjhTpg4Q61Rstw5MCmEQcwAaLAR

I am running the most recent versions. Here are the dependencies from my package.json:

  "dependencies": {
    "@chainsafe/libp2p-noise": "^8.0.1",
    "@libp2p/bootstrap": "^2.0.0",
    "@libp2p/floodsub": "^3.0.5",
    "@libp2p/mplex": "^5.0.0",
    "@libp2p/pubsub-peer-discovery": "^6.0.1",
    "@libp2p/tcp": "^3.0.4",
    "execa": "^6.1.0",
    "libp2p": "0.38.0",
    "p-defer": "^4.0.0",
    "uint8arrays": "^3.1.0"
  }

@mpetrunic mpetrunic added kind/bug A bug in existing code (including security flaws) and removed need/author-input Needs input from the original author labels Aug 31, 2022
@mpetrunic mpetrunic self-assigned this Aug 31, 2022
achingbrain pushed a commit that referenced this issue Sep 5, 2022
Co-authored-by: achingbrain <[email protected]>- fixed tests that were passing even though the example isn't working
- added timeouts to avoid infinite wait

Fixes #1229
@tinytb tinytb moved this to Done in js-libp2p Oct 11, 2022
@tinytb tinytb added this to js-libp2p Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants