Can't discover peers with webrtc-star on js-libp2p@0.37.0

Hello,

since i have upgraded to js-libp2p@0.37.0 i can’t discover peers with webrtc-star.

As a signalling server i use the libp2p/js-libp2p-webrtc-star docker image (latest).

With previous libp2p version this setup used to work. I could discover all other nodes.

With the new version i don’t get any discover events from other nodes.
What i can do however is to successfully dial other nodes via the webrtc-star docker server.

await libp2p.node.dial("/dns4/webrtc-xxxxxxxx.de/tcp/443/wss/p2p-webrtc-star/p2p/QmTtFjYz56Pfzg88fgUp75JzskFmd7m5dbiTKbgA3imEVa");

So i think generally it is setup correctly.

Below is how my libp2p nodes are configured. Is there any configuration that I am missing?

import {createLibp2p} from "libp2p";
import {WebSockets} from "@libp2p/websockets";
import {Noise} from "@chainsafe/libp2p-noise";
import {Mplex} from "@libp2p/mplex";
import {KadDHT} from "@libp2p/kad-dht";
import {GossipSub} from "@chainsafe/libp2p-gossipsub";
import {WebRTCStar} from "@libp2p/webrtc-star";
import wrtc from "wrtc";

...

  var node = await createLibp2p( {
    peerId: id,
    transports: [
      new WebSockets(),
      new WebRTCStar({wrtc: wrtc})
    ],
    connectionEncryption: [new Noise()],
    streamMuxers: [new Mplex()],
    dht: new KadDHT(),
    pubsub: new GossipSub(),
    addresses: {
      listen: [
        "/dns4/webrtc-xxxxxxxx.de/tcp/443/wss/p2p-webrtc-star"
      ]
    },
  }) 

...

this.node.addEventListener("peer:discovery", (myevent) => {onDiscovery.onDiscovery(myevent)});
this.node.connectionManager.addEventListener("peer:connect", (myevent) => {onConnect.onConnect(myevent)});

And here are the versions from package.json

"libp2p": "^0.37.0",
"@libp2p/websockets": "^1.0.8",
"@chainsafe/libp2p-noise": "^6.1.1",
"@libp2p/mplex": "^1.0.5",
"@libp2p/kad-dht": "^1.0.12",
"@chainsafe/libp2p-gossipsub": "^1.0.0",
"@libp2p/webrtc-star": "^1.0.10",
"wrtc": "^0.4.7",

Regards Sneaker

1 Like

I managed to get it working - somehow

First i had to add a custom EventListener to catch the “peer” event from webrtc-star and then fire the onDiscoveryPeer function to get the regular “peer:discovery” event.

node.components.getTransportManager().transports.get("@libp2p/webrtc-star").discovery.addEventListener('peer', evt => {
      this.node.onDiscoveryPeer(evt);
  });

Additionally i had to start the discovery service of webrtc-star manually as it is not started by default.

await libp2p.node.components.getTransportManager().transports.get("@libp2p/webrtc-star").discovery.start();

But this can not be the way it is meant to work.
So is this a bug or is there a way to pass a configuration object to the libp2pInit. Maybe in peerDiscovery?

@sneaker were you able to find a better solution to this? I am having the same issue on js-libp2p@0.39.5 :confused:

Before the esm version, discovery & connections were happening using webrtc-star servers. But now it’s not happening.

You need to configure the peer discovery component of the WebRTCStar transport for it to work:

For libp2p@0.37.0-0.39.0 and @libp2p/webrtc-star@4.x.x:

import { WebRTCStar } from '@libp2p/webrtc-star'
import { createLibp2p } from 'libp2p'
//... other stuff

const webRTC = new WebRTCStar({ ... })

const node = await createLibp2p( {
  transports: [
    webRTC
  ],
  peerDiscovery: [
     webRTC.discovery
  ],
  //... other stuff
})

For libp2p@0.40.0 and @libp2p/webrtc-star@5.x.x:

import { webRTCStar } from '@libp2p/webrtc-star'
import { createLibp2p } from 'libp2p'
//... other stuff

const webRTC = webRTCStar({ ... })

const node = await createLibp2p( {
  transports: [
    webRTC.transport
  ],
  peerDiscovery: [
     webRTC.discovery
  ],
  //... other stuff
})

The README for v5 is hopefully a bit clearer.

1 Like

@achingbrain this is still not resolved :slight_smile: https://github.com/libp2p/js-libp2p/issues/1442