Skip to content

Conversation

@achingbrain
Copy link
Member

Updates the example to include libp2p API changes shipped last year

Updates the example to include libp2p API changes shipped last year
@achingbrain achingbrain requested a review from 2color July 3, 2025 05:52
const libp2p = await createLibp2p({
transports: [
// Allow all WebSocket connections inclusing without TLS
webSockets({ filter: filters.all }),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is handled globally by the connection gater now.

achingbrain added a commit to achingbrain/libp2p-webrtc-guide that referenced this pull request Jul 3, 2025
Updates example to use the libp2p api shipped last year.

Refs libp2p/docs#403
Copy link
Contributor

@2color 2color left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@2color
Copy link
Contributor

2color commented Aug 11, 2025

With these changes, we also need to add an event listener to peer:discovery events and manually dial peers.

Something along the lines of:

  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)
    }
  })

Once libp2p/js-libp2p#3239 is resolved, we should just be able to dial evt.detail.multiaddrs without having to manually append the PeerID to the maddr.

@2color 2color merged commit 623096e into master Aug 11, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants