This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
The following commit(s) were added to refs/heads/main by this push: new 1eb496c perf: don't wait for WebRTC to establish before connecting to server 1eb496c is described below
commit 1eb496c37455b0df465ddf767292da1506abec3b Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 20:11:10 2022 +0400
perf: don't wait for WebRTC to establish before connecting to server
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowf... --- proxypair.js | 13 +++++-------- spec/proxypair.spec.js | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/proxypair.js b/proxypair.js index db37045..07670fb 100644 --- a/proxypair.js +++ b/proxypair.js @@ -105,6 +105,8 @@ class ProxyPair { }, this.config.answerTimeout); }
+ this.connectRelay(offer); + return true; }
@@ -131,10 +133,6 @@ class ProxyPair { this.messageTimer = setTimeout(onStaleTimeout, this.config.messageTimeout); }; this.refreshStaleTimeout(); - - // This is the point when the WebRTC datachannel is done, so the next step - // is to establish websocket to the server. - this.connectRelay(); }; channel.onclose = () => { log('WebRTC DataChannel closed.'); @@ -154,10 +152,10 @@ class ProxyPair { }
/** - * Assumes WebRTC datachannel is connected. + * @param {RTCSessionDescription} remoteDescription * @private */ - connectRelay() { + connectRelay(remoteDescription) { dbg('Connecting to relay...'); // Get a remote IP address from the PeerConnection, if possible. Add it to // the WebSocket URL's query string if available. @@ -166,8 +164,7 @@ class ProxyPair { // are not marked experimental, were undefined when I tried them in Firefox // 52.2.0. // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/remoteDes... - const desc = this.pc.remoteDescription; - const peer_ip = Parse.ipFromSDP(desc!= null ? desc.sdp : undefined); + const peer_ip = Parse.ipFromSDP(remoteDescription.sdp); const params = []; if (peer_ip != null) { params.push(["client_ip", peer_ip]); diff --git a/spec/proxypair.spec.js b/spec/proxypair.spec.js index c624dbf..0c2dff4 100644 --- a/spec/proxypair.spec.js +++ b/spec/proxypair.spec.js @@ -104,15 +104,24 @@ describe('ProxyPair', function() { expect(pp.client.onmessage).not.toBeNull(); });
- it('connects to the relay once datachannel opens', function() { + it('connects to the relay once a client offer is received', function() { spyOn(pp, 'connectRelay'); pp.active = true; - pp.client.onopen(); + pp.receiveWebRTCOffer( + { + type: 'offer', + sdp: 'foo' + }, + () => {}, + ) expect(pp.connectRelay).toHaveBeenCalled(); });
it('connects to a relay', function() { - pp.connectRelay(); + pp.connectRelay({ + type: 'offer', + sdp: 'foo' + }); expect(pp.relay.onopen).not.toBeNull(); expect(pp.relay.onclose).not.toBeNull(); expect(pp.relay.onerror).not.toBeNull(); @@ -123,6 +132,13 @@ describe('ProxyPair', function() {
it('proxies data from client to relay', function() { var msg; + pp.receiveWebRTCOffer( + { + type: 'offer', + sdp: 'foo' + }, + () => {}, + ); pp.pc.ondatachannel({ channel: { bufferedAmount: 0, @@ -130,6 +146,7 @@ describe('ProxyPair', function() { send: function(data) {} } }); + pp.client.onopen(); spyOn(pp.client, 'send'); spyOn(pp.relay, 'send'); msg = new MessageEvent("message", {
tor-commits@lists.torproject.org