libp2p / libp2p/js-libp2p

`peer:discovery` maddrs are missing the `/p2p/{PEER_ID}/` part for circuit relay maddrs

Open
#3,239 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted need/analysis
Dominant language
TypeScript
Stars
2.6k
Forks
546
Avg merge
8h 18m
Merged PRs (30d)
16

Description

Problem

The browser WebRTC guide uses @libp2p/pubsub-peer-discovery to discover peers. While the module correctly emits the peer event with maddrs of discovered webrtc peers (source), js-libp2p emits a peer:discovery event, however it's missing the /p2p/PEER_ID component that is present in the original peer event.

I've worked around this as follows:

  libp2p.addEventListener('peer:discovery', async (evt) => {
    console.log(
      `Discovered new peer (${evt.detail.id.toString()}). Dialling...`,
      evt.detail.multiaddrs.map((ma) => ma.toString()),
    )
    try {
      const maddrs = evt.detail.multiaddrs.map((ma) => ma.encapsulate(`/p2p/${evt.detail.id.toString()}`))
      await libp2p.dial(maddrs) // dial the new peer
      console.log(`Successfully dialed peer (${evt.detail.id.toString()})`)
    } catch (err) {
      console.error(`Failed to dial peer (${evt.detail.id.toString()}):`, err)
    }
  })

The problem is that if you just dial the maddrs in the event the dial will fail for webrtc maddrs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the peer-discovery source linked in the issue, especially the code emitting the peer event, and trace how js-libp2p produces the peer:discovery event. Reproduce the WebRTC circuit-relay case from the browser WebRTC guide and compare the emitted multiaddrs with the original peer event. Done means dialing the event's maddrs succeeds without the consumer manually appending the peer ID.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.