This is a question regarding a design decision I'm trying to make related to WebRTC's DataChannel functionality.
Lets say I want to build a browser app which allows peers to transfer files to each other. (request response style)
Assume peers send requests for files as single messages on a DataChannel and responses of file data are chunked into multiple DataChannel messages (to avoid monopolization of the SCTP association). Consider the simple case of just 2 peers.
The following design options come to mind:
- Create a single DataChannel between the peers during connection initialization and multiplex all data on it (both request messages and response chunks). Multiplexing logic will have to written in the application.
- Create two DataChannels (on same peer connection) between the peers, one for transporting requests and one for transporting response chunks. Here some sort of multiplexing needs to be implemented for the response data channel, as two files being sent concurrently from the same peer may experience interleaving of chunks and the application needs to know which chunk belongs to which file.
- Create one DataChannel during initialization. This is used to transport request messages. For transferring response file chunks new DataChannels are created on demand for every file i.e. when a peer receives a request for a file it creates a new DataChannel and sends the content chunks on that data channel, closing it after the transfer is complete. Here since files being sent concurrently will be sent on different data channels, there is no need to implement multiplexing logic at all in the application.
Since SCTP anyway multiplexes multiple streams over a single association, re-implementing multiplex logic at the application level doesn't seem right. For this reason the third option looks attractive to me. However I am worried about performance. In particular, what is the overhead associated with creating a DataChannel (on an RTCPeerConnection where offer/answer exchange, ICE checks and all that stuff is already done)? Can I assume a startup delay of 1 RTT? In general, is it a good idea to create DataChannels on-demand like this?
Looking forward to some constructive advice on this issue.
Thanks
Midhul