mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Set binaryType="arraybuffer" for RTCDataChannel, just as with WebSocket.
The binaryType can be "arraybuffer" or "blob", and "blob" is the default. The code is only aware of "arraybuffer": I discovered a problem while running snowflake.html in debug mode; this code fails: if DEBUG # Go sends only raw bytes... if '[object ArrayBuffer]' == recv.toString() bytes = new Uint8Array recv line = String.fromCharCode.apply(null, bytes) line = line.trim() log 'WebRTC --> websocket data: ' + line with the error: TypeError: line.trim is not a function[Learn More] snowflake.js:497:16 because recv is of type Blob, not ArrayBuffer. Despite the unexpected type, the code seemed to work as expected when not in debug mode. Though the two types provide different interfaces, they are both valid to pass on to WebSocket.send. The only other thing we did with it was try to read the .length member for rate-limiting purposes: @rateLimit.update chunk.length but .length is incorrect for either type: Blob uses .size and ArrayBuffer uses .byteLength. It worked anyway, because DummyRateLimit.update doesn't actually look at its argument. We were already setting binaryType="arraybuffer" for WebSocket connections.
This commit is contained in:
parent
a554439370
commit
aa668bdc92
1 changed files with 1 additions and 0 deletions
|
@ -88,6 +88,7 @@ class ProxyPair
|
|||
# TODO: Change this for multiplexing.
|
||||
snowflake.reset()
|
||||
channel.onerror = -> log 'Data channel error!'
|
||||
channel.binaryType = "arraybuffer"
|
||||
channel.onmessage = @onClientToRelayMessage
|
||||
|
||||
# Assumes WebRTC datachannel is connected.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue