libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.io
Other
2.3k stars 440 forks source link

feat: WebRTC-Direct support for Node.js #2583

Open achingbrain opened 3 months ago

achingbrain commented 3 months ago

Supports listening and dialing WebRTC Direct multiaddrs in Node.js.

Depends on:

Closes:

Change checklist

xicilion commented 3 months ago

I read the code a bit, in this implementation when Peer B listens, it first listens for incoming stun packets using dgram, extracts the ufrag, and then establishes a connection with Peer A from another port. This works fine in a direct network connection. But if Peer A is behind NAT, this type of connection will fail because the NAT detects incoming packets from another port, which was not accessed from inside before.

achingbrain commented 3 months ago

I haven't got to the point of testing NAT traversal yet, still a lot of PRs to land in the deps.

I was wondering if each RTCPeerConnection could negotiate it's own NAT traversal via STUN/TURN but it would probably be less resource intensive to have UDPMUX on a single port, I agree.

xicilion commented 3 months ago

I was wondering if each RTCPeerConnection could negotiate it's own NAT traversal via STUN/TURN.

From the logic of the code, even though multiple RTCPeerConnections share a single UDP socket in UDPMUX mode, each of them manages their own status separately and there is no difference compared to regular RTCPeerConnections. This means that the negotiation process for them is also no different from regular RTCPeerConnections.