Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 15, 2025

This PR implements WebRTC-Direct functionality for libp2p in Node.js environments, enabling direct peer-to-peer connections without requiring circuit relay servers. This addresses a critical connectivity requirement for web nodes hosted on HTTPS to connect to others without signed certificates.

Background

The existing implementation only supported standard WebRTC connections that require circuit relay servers for the initial handshake. This created a dependency on third-party relay infrastructure and prevented direct connections between HTTPS web nodes and peers with self-signed certificates.

WebRTC-Direct solves this by using SDP munging to skip the handshake step entirely, encoding connection information directly in the multiaddr including a certificate hash (certhash) that allows connections to peers with self-signed certificates.

Implementation Details

Key Changes:

  • Added webRTCDirect() transport alongside existing webRTC() transport in libp2p configuration
  • Configured automatic WebRTC-Direct listen addresses using dynamic port allocation (udp/0/webrtc-direct)
  • Updated address preference logic to prioritize WebRTC-Direct over circuit relay connections
  • Added comprehensive STUN server configuration for NAT traversal

WebRTC-Direct Features Enabled:

  • Direct peer-to-peer connections without relay servers
  • Self-signed certificate support via certificate hash in multiaddrs
  • HTTPS web nodes can connect to others without signed certificates
  • Automatic port assignment and multiaddr generation
  • Mixed transport support (WebSocket + WebRTC + WebRTC-Direct)

Example

The implementation now generates WebRTC-Direct multiaddrs like:

/ip4/127.0.0.1/udp/41875/webrtc-direct/certhash/uEiBsOHV20DXT1efGwm8BSgUC1RH2ufweXgjSeS9CX84Cyg/p2p/12D3KooW...

These addresses enable direct connections between peers without requiring relay infrastructure, with the certhash component allowing trust of self-signed certificates.

Testing

  • Added comprehensive test suite covering WebRTC-Direct configuration, connectivity, and end-to-end connections
  • All existing tests continue to pass (4103+ tests)
  • Successfully established direct WebRTC-Direct peer connections in test environment
  • Support node and web server start successfully with WebRTC-Direct enabled

This implementation provides maximum connectivity for Verity nodes, enabling web applications on HTTPS to connect directly to the network without relay dependencies.

Fixes #813.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • bt1.archive.org
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • bt2.archive.org
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • opentracker.i2p.rocks
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • retracker.lanta-net.ru
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • stun.cloudflare.com
    • Triggering command: node (vitest 1) (dns block)
  • stun.l.google.com
    • Triggering command: node (vitest 1) (dns block)
  • stun.services.mozilla.com
    • Triggering command: node (vitest 1) (dns block)
  • tracker.files.fm
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • tracker.gbitt.info
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • tracker.openbittorrent.com
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • tracker.opentrackr.org
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
    • Triggering command: node (vitest 1) (dns block)
  • tracker.tamersunion.org
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
  • tracker.torrent.eu.org
    • Triggering command: node --import=extensionless/register dist/verity.js -w 1984 -t (dns block)
    • Triggering command: node (vitest 1) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Implement WebRTC-Direct for nodejs Implement WebRTC-Direct for Node.js - Enable direct peer connections without relay Aug 15, 2025
Copilot AI requested a review from EliasOenal August 15, 2025 03:25
@EliasOenal EliasOenal marked this pull request as ready for review August 15, 2025 03:27
@EliasOenal EliasOenal merged commit e3b2467 into main Aug 15, 2025
1 check passed
victorhahncastell pushed a commit that referenced this pull request Aug 15, 2025
Enable direct peer connections without relay

Co-authored-by: EliasOenal <[email protected]>

Merge pull request #814 from EliasOenal/copilot/fix-813
victorhahncastell pushed a commit that referenced this pull request Aug 16, 2025
Enable direct peer connections without relay

Co-authored-by: EliasOenal <[email protected]>

Merge pull request #814 from EliasOenal/copilot/fix-813
@EliasOenal EliasOenal deleted the copilot/fix-813 branch August 16, 2025 17:46
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.

Implement WebRTC-Direct for nodejs

2 participants