Protocol Specification

WebRTC Protocol & DataChannel Specification

In-depth technical analysis of SCTP DataChannels, STUN NAT traversal, chunk sizing, and transport encryption.

WebRTC Protocol Stack

ShareOnline relies on the WebRTC data channel protocol stack standardized across IETF and W3C:

  • Transport Layer: UDP (User Datagram Protocol) ensures low-latency, packetized delivery across heterogeneous network paths.
  • Security Layer: DTLS (Datagram Transport Layer Security) encapsulates the UDP stream, providing TLS-grade authentication and encryption.
  • Reliability Layer: SCTP (Stream Control Transmission Protocol) provides reliable, ordered data stream multiplexing over the encrypted DTLS channel.
  • Application Layer: RTCDataChannel exposes binary JavaScript interfaces for streaming raw ArrayBuffer payloads.

STUN & ICE NAT Traversal

To penetrate symmetric and cone NAT routers, ShareOnline gathers ICE candidates via public STUN servers:

  • stun:stun.l.google.com:19302
  • stun:stun1.l.google.com:19302
  • stun:stun2.l.google.com:19302

STUN servers reflect back the client's public IP address and port without ever touching or routing the file content. Once candidate pairs are evaluated, WebRTC establishes a direct UDP hole-punched connection between peers.

Optimal Chunk Sizing (32 KB)

While WebRTC DataChannels allow arbitrary message sizes, browsers enforce maximum message size limits (typically 64 KB or 256 KB) depending on the browser version and OS network stack.

ShareOnline standardizes on 32,768 bytes (32 KB) per chunk:

  • Fits well within standard SCTP MTU thresholds across all desktop and mobile implementations.
  • Minimizes memory allocation fragmentation in JavaScript runtimes.
  • Provides high granularity for progress bars and transfer speed calculations.

Backpressure & Flow Control Mechanism

When transmitting large files over fast local networks, the sender JavaScript thread can easily generate chunks faster than the underlying network socket can serialize them. Unchecked, this causes dataChannel.send() to buffer megabytes in browser memory, eventually dropping packets or crashing the tab.

ShareOnline implements strict backpressure control:

  • Sets dataChannel.bufferedAmountLowThreshold = 262,144 (256 KB).
  • Polls dataChannel.bufferedAmount before dispatching each chunk.
  • If the buffer exceeds 512 KB, chunk dispatch pauses until the browser dispatches the bufferedamountlow event.