perf: trickle ICE (don't wait for ICE gathering to complete before sending an offer/answer)
...and keep sending new ICE candidates after.
I'm not a big expert on WebRTC but from what I've read (UPD: and experienced), it can take a while for ICE gathering to complete, but a connection can be established before it does complete. Here it says:
Each peer sends candidates in the order they're discovered, and keeps sending candidates until it runs out of suggestions, even if media has already started streaming.
In JS there is addIceCandidate
and onicecandidate
(and canTrickleIce
). In the Go version, there is pc.OnICECandidate
.
I suspect that this waiting may be the reason why connections time out sometimes (#30498). Also there is "How come some Snowflake bootstrap attempts are so slow?" in the wiki.
I believe this will require updates to the broker API. Maybe for each proxy/client pair broker needs to make a WebSocket pair that will forward the ICE candidates between them. Or maybe a conventional HTTP request would suffice, as we already have IDs (e.g. see the /answer
request). Or can they be exchanged through the P2P connection itself?
Code:
- https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/blob/2c008d6589e37e77f01a364ab414d6a95218de36/client/lib/webrtc.go#L241-242
- https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/blob/97dea533da7b6b3b2b1dfbffe7dca3a8350fab0b/proxy/lib/snowflake.go#L403-406
Some more resources about WebRTC: