-
Notifications
You must be signed in to change notification settings - Fork 496
Description
So, the best part of circuit-relay, is the fact that it allows to connect nodes where neither can listen for incoming connections.
Unfortunately, running a circuit-relay HOP node is expensive, and by default HOP is turned off.
tl;dr: I hacked js-libp2p-circuit into negotiating WebRTC signals using newly relayed connections, and establish a direct connection between unconnected peers using a helping 3rd party.
Such connection scheme is more considerate of "relay" nodes, because they only need to relay the signaling data, and not the entire connection.
Another plus, is that now browsers should be able to connect to one another directly.
I uploaded the modded js-libp2p-circuit repo and a demo to github:
You can view the diff to the original circuit-relay module in this PR: guysv/js-libp2p-webrtc-poc#1
To run the demo:
npm install
(note: I included a custom package-lock.json in the demo repo so that js-libp2p-switch will use my modded circuit module, if you feel extra paranoid, regenerate the package-lock.json and fill inguysv/js-libp2p-webrtc-poc#webrtc-poc
- run the hop node
DEBUG=libp2p:circuit:* node src/hop.js
- run listener node
DEBUG=libp2p:circuit:* node src/listener.js
- run dialer node
DEBUG=libp2p:circuit:* node src/dialer.js
- look for those logs I added, which indicate that WebRTC connection was established with listener node
# dialer node
libp2p:circuit:dialer Writing signal to circuit connection +21ms
libp2p:circuit:dialer Writing signal to circuit connection +1ms
libp2p:circuit:dialer Read signal from circuit connection +46ms
libp2p:circuit:dialer Connected! +21ms
# listener node
libp2p:circuit:stop Read signal from circuit connection +0ms
libp2p:circuit:stop Read signal from circuit connection +3ms
libp2p:circuit:stop Writing signal to circuit connection +11ms
libp2p:circuit:stop Writing signal to circuit connection +2ms
libp2p:circuit:stop Connected! +22ms
The connection is not really usable, but those logs indicate that a WebRTC channel was established, good enough for POC :)
Anyhow, That was a cool experiment. I wrote this issue to hear what you guys think about it. I tried to find material about WebRTC in Libp2p but the only modules I found were webrtc-star, which is a centralized solution, and webrtc-direct, which doesn't really offer interesting features that websockets lack. I think this could be a cool addition to the stack!