[tor-commits] [snowflake/master] Set binaryType="arraybuffer" for RTCDataChannel, just as with WebSocket.

dcf at torproject.org dcf at torproject.org
Thu Dec 20 04:44:49 UTC 2018


commit aa668bdc92ca76ead1e2816aebe8665377857bba
Author: David Fifield <david at bamsoftware.com>
Date:   Tue Dec 4 15:28:19 2018 -0700

    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.
---
 proxy/proxypair.coffee | 1 +
 1 file changed, 1 insertion(+)

diff --git a/proxy/proxypair.coffee b/proxy/proxypair.coffee
index 2adbc23..e3a7f46 100644
--- a/proxy/proxypair.coffee
+++ b/proxy/proxypair.coffee
@@ -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.





More information about the tor-commits mailing list