Implement WebRTC-Direct for Node.js - Enable direct peer connections without relay #814
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
webRTCDirect()transport alongside existingwebRTC()transport in libp2p configurationudp/0/webrtc-direct)WebRTC-Direct Features Enabled:
Example
The implementation now generates WebRTC-Direct multiaddrs like:
These addresses enable direct connections between peers without requiring relay infrastructure, with the
certhashcomponent allowing trust of self-signed certificates.Testing
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.orgnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)bt2.archive.orgnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)opentracker.i2p.rocksnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)retracker.lanta-net.runode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)stun.cloudflare.comnode (vitest 1)(dns block)stun.l.google.comnode (vitest 1)(dns block)stun.services.mozilla.comnode (vitest 1)(dns block)tracker.files.fmnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)tracker.gbitt.infonode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)tracker.openbittorrent.comnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)tracker.opentrackr.orgnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)node (vitest 1)(dns block)tracker.tamersunion.orgnode (vitest 1)(dns block)node --import=extensionless/register dist/verity.js -w 1984 -t(dns block)tracker.torrent.eu.orgnode --import=extensionless/register dist/verity.js -w 1984 -t(dns block)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.