nim-libp2p icon indicating copy to clipboard operation
nim-libp2p copied to clipboard

WebRTC transport support

Open Menduist opened this issue 2 years ago • 3 comments

Issue to track what's needed to support the WebRTC transport (aka libp2p-webrtc-direct)

Transport protocols

The WebRTC stack:

RTCPeerConnection DataChannel
SRTP SCTP
DTLS DTLS
UDP UDP

My understanding is that we only need DataChannel for the transport to work properly. UDP: already implemented in chronos DTLS: BearSSL doesn't implement it yet. Track progress here. After it's done (or maybe we can hack it together), chronos implementation should be relatively trivial (~300 LoC) SCTP over DTLS: need a user-space library (linux has a native implem of SCTP over IP or UDP, not over DTLS). Complexity: probably similar to Quic DataChannel: Should be pretty straightforward (~200 LoC)

Overall, probably >3 months of work.

Repo: https://github.com/status-im/nim-webrtc

Menduist avatar Mar 02 '22 13:03 Menduist

(aka libp2p-webrtc-direct)

Note that webrtc direct will likely not be promoted to the general libp2p WebRTC protocol, given that it requires a previous WebSocket connection to exchange the SDP.

The goal of the upcoming design (https://github.com/libp2p/specs/issues/220) is to not require a previous exchange.

Happy to expand on this in case you are planning on working on this any time soon.

mxinden avatar Mar 04 '22 12:03 mxinden

We dig a bit on the SCTP part with @Menduist lately, here what we found:

  • There's no native implementation for the SCTP in nim that we could use, https://github.com/metacontainer/sctp.nim is the only one we found, it's not maintained and use reactor instead of chronos as an asynchronous library. However, it imports a C library that looks promising.
  • The C implementation used by sctp.nim is https://github.com/sctplab/usrsctp, it's well maintained, it's importable, it looks usable for our purpose. Not much more to say. I'll check if it's easily feasible soon.
  • The other option is to implement our own version of SCTP, looking at the pion implementation in Go (~5500 LoC), it shouldn't be too long to code.

As for the full webrtc stack, only two were satisfying, the google one in C++ and the pion one in Go. I'm not sure if we can use those directly though.

lchenut avatar Aug 29 '22 14:08 lchenut

A quick overview of what was done since last update.

  • The SCTP is more or less done. I wrappped the https://github.com/sctplab/usrsctp library. It needs a more testing and tweaking but beside that, the wrapping is done. You can take a look at it here.
  • As for DTLS part, BearSSL still doesn't implement it. It might be a good idea to take a look at other implementations.
  • The DataChannel is the next thing I'll look at, assuming it doesn't need DTLS features to work

Some DataChannel relevant links:

  • the pion implementation https://github.com/pion/datachannel/blob/master/datachannel.go
  • An usrsctp example, I'm not 100% sure that it's a datachannel implementation but it might be interesting to take a look at it https://github.com/sctplab/usrsctp/blob/master/programs/rtcweb.c
  • And the RFC, obviously https://www.rfc-editor.org/rfc/rfc8831

lchenut avatar Dec 30 '22 14:12 lchenut