This is an automated email from the git hooks/post-receive script.
cohosh pushed a change to branch main in repository pluggable-transports/snowflake-webext.
from 995a427 Add Microsoft Edge px-Edge_logo new 840ab41 Factor WS.makeWebsocketURL out of WS.makeWebsocket. new 1684bac Add a test for WS.makeWebsocketURL. new dcc24df Make WS.makeWebsocketURL properly attach params. new 9e14a21 Simplify WS.makeWebsocket to take just a client_ip. new 438abed Use "WebSocket" capitalization in WS interfaces. new 8587222 Remove an obsolete comment.
The 6 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
Summary of changes: init-badge.js | 2 +- init-webext.js | 2 +- proxypair.js | 12 ++---------- spec/websocket.spec.js | 25 +++++++++++++++++++++++++ websocket.js | 36 +++++++++++++++++++++++------------- 5 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 spec/websocket.spec.js
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.
commit 840ab4189531d2edf4705d757d286b32c26b046c Author: David Fifield david@bamsoftware.com AuthorDate: Wed Mar 29 11:39:37 2023 -0600
Factor WS.makeWebsocketURL out of WS.makeWebsocket.
To permit testing without accessing the network. --- websocket.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/websocket.js b/websocket.js index 4b56756..b49bd2f 100644 --- a/websocket.js +++ b/websocket.js @@ -5,19 +5,28 @@ Only websocket-specific stuff. // eslint-disable-next-line no-unused-vars class WS { /** - * Creates a websocket connection from a URL and params to override + * Creates a websocket URL from a base URL and params to override * @param {URL|string} url * @param {URLSearchParams|string[][]} params - * @return {WebSocket} + * @return {URL} */ - static makeWebsocket(url, params) { + static makeWebsocketURL(url, params) { let parsedURL = new URL(url); let urlpa = new URLSearchParams(params); urlpa.forEach(function (value, key) { parsedURL.searchParams.set(key, value); }); + return new URL(url); + }
- let ws = new WebSocket(url); + /** + * Creates a websocket connection from a URL and params to override + * @param {URL|string} url + * @param {URLSearchParams|string[][]} params + * @return {WebSocket} + */ + static makeWebsocket(url, params) { + let ws = new WebSocket(WS.makeWebsocketURL(url, params)); /* 'User agents can use this as a hint for how to handle incoming binary data: if the attribute is set to 'blob', it is safe to spool it to disk, and if it
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.
commit 1684bacfadf210a641c2c012c355c484e52e8d3d Author: David Fifield david@bamsoftware.com AuthorDate: Wed Mar 29 11:45:34 2023 -0600
Add a test for WS.makeWebsocketURL. --- spec/websocket.spec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/spec/websocket.spec.js b/spec/websocket.spec.js new file mode 100644 index 0000000..a3c19c1 --- /dev/null +++ b/spec/websocket.spec.js @@ -0,0 +1,25 @@ +describe('makeWebsocketURL', function() { + it('attaches params', function() { + // With empty parameters, should leave input unchanged. + expect(WS.makeWebsocketURL('wss://example.com/path', []).toString()) + .toBe('wss://example.com/path'); + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', []).toString()) + .toBe('wss://example.com/path?client_ip=192.0.2.99'); + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', []).toString()) + .toBe('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99'); + + // Should add new parameters. + expect(WS.makeWebsocketURL('wss://example.com/path', [['client_ip', '192.0.2.1']]).toString()) + .toBe('wss://example.com/path?client_ip=192.0.2.1'); + + // Should retain any other existing parameters. + expect(WS.makeWebsocketURL('wss://example.com/path?foo=bar', [['client_ip', '192.0.2.1']]).toString()) + .toBe('wss://example.com/path?foo=bar&client_ip=192.0.2.1'); + + // Should overwrite any existing parameters of the same name. + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', [['client_ip', '192.0.2.1']]).toString()) + .toBe('wss://example.com/path?client_ip=192.0.2.1'); + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', [['client_ip', '192.0.2.1']]).toString()) + .toBe('wss://example.com/path?client_ip=192.0.2.1'); + }); +});
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.
commit dcc24dfdf28c2359032e253ac2216ecede20ec16 Author: David Fifield david@bamsoftware.com AuthorDate: Wed Mar 29 11:55:17 2023 -0600
Make WS.makeWebsocketURL properly attach params.
Fixes #82. --- websocket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/websocket.js b/websocket.js index b49bd2f..f04a505 100644 --- a/websocket.js +++ b/websocket.js @@ -16,7 +16,7 @@ class WS { urlpa.forEach(function (value, key) { parsedURL.searchParams.set(key, value); }); - return new URL(url); + return parsedURL; }
/**
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.
commit 9e14a21cf48f936edaaf6403773f3963ae405602 Author: David Fifield david@bamsoftware.com AuthorDate: Wed Mar 29 12:03:32 2023 -0600
Simplify WS.makeWebsocket to take just a client_ip.
Rather than a full array of key–value pairs. --- proxypair.js | 8 ++------ spec/websocket.spec.js | 24 ++++++++++++------------ websocket.js | 29 +++++++++++++++-------------- 3 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/proxypair.js b/proxypair.js index b4dc3c9..bea1fc0 100644 --- a/proxypair.js +++ b/proxypair.js @@ -164,12 +164,8 @@ 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 peer_ip = Parse.ipFromSDP(remoteDescription.sdp); - const params = []; - if (peer_ip != null) { - params.push(["client_ip", peer_ip]); - } - const relay = this.relay = WS.makeWebsocket(this.relayURL, params); + const clientIP = Parse.ipFromSDP(remoteDescription.sdp); + const relay = this.relay = WS.makeWebsocket(this.relayURL, clientIP); relay.label = 'websocket-relay'; relay.onopen = () => { clearTimeout(this.connectToRelayTimeoutId); diff --git a/spec/websocket.spec.js b/spec/websocket.spec.js index a3c19c1..81722da 100644 --- a/spec/websocket.spec.js +++ b/spec/websocket.spec.js @@ -1,25 +1,25 @@ describe('makeWebsocketURL', function() { - it('attaches params', function() { - // With empty parameters, should leave input unchanged. - expect(WS.makeWebsocketURL('wss://example.com/path', []).toString()) + it('attaches client_ip', function() { + // With no clientIP, should leave query parameters unchanged. + expect(WS.makeWebsocketURL('wss://example.com/path', null).toString()) .toBe('wss://example.com/path'); - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', []).toString()) + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', null).toString()) .toBe('wss://example.com/path?client_ip=192.0.2.99'); - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', []).toString()) + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', null).toString()) .toBe('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99');
- // Should add new parameters. - expect(WS.makeWebsocketURL('wss://example.com/path', [['client_ip', '192.0.2.1']]).toString()) + // Should add a client_ip query parameter. + expect(WS.makeWebsocketURL('wss://example.com/path', '192.0.2.1').toString()) .toBe('wss://example.com/path?client_ip=192.0.2.1');
- // Should retain any other existing parameters. - expect(WS.makeWebsocketURL('wss://example.com/path?foo=bar', [['client_ip', '192.0.2.1']]).toString()) + // Should retain any other existing query parameters. + expect(WS.makeWebsocketURL('wss://example.com/path?foo=bar', '192.0.2.1').toString()) .toBe('wss://example.com/path?foo=bar&client_ip=192.0.2.1');
- // Should overwrite any existing parameters of the same name. - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', [['client_ip', '192.0.2.1']]).toString()) + // Should overwrite any existing client_ip query parameters. + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', '192.0.2.1').toString()) .toBe('wss://example.com/path?client_ip=192.0.2.1'); - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', [['client_ip', '192.0.2.1']]).toString()) + expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', '192.0.2.1').toString()) .toBe('wss://example.com/path?client_ip=192.0.2.1'); }); }); diff --git a/websocket.js b/websocket.js index f04a505..1fbc68b 100644 --- a/websocket.js +++ b/websocket.js @@ -5,28 +5,29 @@ Only websocket-specific stuff. // eslint-disable-next-line no-unused-vars class WS { /** - * Creates a websocket URL from a base URL and params to override + * Creates a websocket URL from a base URL and an optional client IP address + * string. * @param {URL|string} url - * @param {URLSearchParams|string[][]} params + * @param {?string} clientIP * @return {URL} */ - static makeWebsocketURL(url, params) { - let parsedURL = new URL(url); - let urlpa = new URLSearchParams(params); - urlpa.forEach(function (value, key) { - parsedURL.searchParams.set(key, value); - }); - return parsedURL; + static makeWebsocketURL(url, clientIP) { + url = new URL(url); + if (clientIP != null) { + url.searchParams.set('client_ip', clientIP); + } + return url; }
/** - * Creates a websocket connection from a URL and params to override + * Creates a websocket connection from a URL and an optional client IP address + * string. * @param {URL|string} url - * @param {URLSearchParams|string[][]} params + * @param {?string} clientIP * @return {WebSocket} */ - static makeWebsocket(url, params) { - let ws = new WebSocket(WS.makeWebsocketURL(url, params)); + static makeWebsocket(url, clientIP) { + let ws = new WebSocket(WS.makeWebsocketURL(url, clientIP)); /* 'User agents can use this as a hint for how to handle incoming binary data: if the attribute is set to 'blob', it is safe to spool it to disk, and if it @@ -42,7 +43,7 @@ class WS { */ static probeWebsocket(addr) { return /** @type {Promise<void>} */(new Promise((resolve, reject) => { - const ws = WS.makeWebsocket(addr, []); + const ws = WS.makeWebsocket(addr, null); ws.onopen = () => { resolve(); ws.close();
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.
commit 438abed0b11852b8b1400ad7d0795ef229777d45 Author: David Fifield david@bamsoftware.com AuthorDate: Wed Mar 29 12:14:17 2023 -0600
Use "WebSocket" capitalization in WS interfaces. --- init-badge.js | 2 +- init-webext.js | 2 +- proxypair.js | 2 +- spec/websocket.spec.js | 16 ++++++++-------- websocket.js | 16 ++++++++-------- 5 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/init-badge.js b/init-badge.js index 4f57348..f2adf72 100644 --- a/init-badge.js +++ b/init-badge.js @@ -174,7 +174,7 @@ var };
tryProbe = function() { - WS.probeWebsocket(config.defaultRelayAddr) + WS.probeWebSocket(config.defaultRelayAddr) .then( () => { ui.turnOn(); diff --git a/init-webext.js b/init-webext.js index 4bbeff9..3c79440 100644 --- a/init-webext.js +++ b/init-webext.js @@ -69,7 +69,7 @@ class WebExtUI extends UI { }
tryProbe() { - WS.probeWebsocket(config.defaultRelayAddr) + WS.probeWebSocket(config.defaultRelayAddr) .then( () => { this.missingFeature = false; diff --git a/proxypair.js b/proxypair.js index bea1fc0..627607f 100644 --- a/proxypair.js +++ b/proxypair.js @@ -165,7 +165,7 @@ class ProxyPair { // 52.2.0. // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/remoteDes... const clientIP = Parse.ipFromSDP(remoteDescription.sdp); - const relay = this.relay = WS.makeWebsocket(this.relayURL, clientIP); + const relay = this.relay = WS.makeWebSocket(this.relayURL, clientIP); relay.label = 'websocket-relay'; relay.onopen = () => { clearTimeout(this.connectToRelayTimeoutId); diff --git a/spec/websocket.spec.js b/spec/websocket.spec.js index 81722da..6e118a8 100644 --- a/spec/websocket.spec.js +++ b/spec/websocket.spec.js @@ -1,25 +1,25 @@ -describe('makeWebsocketURL', function() { +describe('makeWebSocketURL', function() { it('attaches client_ip', function() { // With no clientIP, should leave query parameters unchanged. - expect(WS.makeWebsocketURL('wss://example.com/path', null).toString()) + expect(WS.makeWebSocketURL('wss://example.com/path', null).toString()) .toBe('wss://example.com/path'); - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', null).toString()) + expect(WS.makeWebSocketURL('wss://example.com/path?client_ip=192.0.2.99', null).toString()) .toBe('wss://example.com/path?client_ip=192.0.2.99'); - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', null).toString()) + expect(WS.makeWebSocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', null).toString()) .toBe('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99');
// Should add a client_ip query parameter. - expect(WS.makeWebsocketURL('wss://example.com/path', '192.0.2.1').toString()) + expect(WS.makeWebSocketURL('wss://example.com/path', '192.0.2.1').toString()) .toBe('wss://example.com/path?client_ip=192.0.2.1');
// Should retain any other existing query parameters. - expect(WS.makeWebsocketURL('wss://example.com/path?foo=bar', '192.0.2.1').toString()) + expect(WS.makeWebSocketURL('wss://example.com/path?foo=bar', '192.0.2.1').toString()) .toBe('wss://example.com/path?foo=bar&client_ip=192.0.2.1');
// Should overwrite any existing client_ip query parameters. - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.99', '192.0.2.1').toString()) + expect(WS.makeWebSocketURL('wss://example.com/path?client_ip=192.0.2.99', '192.0.2.1').toString()) .toBe('wss://example.com/path?client_ip=192.0.2.1'); - expect(WS.makeWebsocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', '192.0.2.1').toString()) + expect(WS.makeWebSocketURL('wss://example.com/path?client_ip=192.0.2.98&client_ip=192.0.2.99', '192.0.2.1').toString()) .toBe('wss://example.com/path?client_ip=192.0.2.1'); }); }); diff --git a/websocket.js b/websocket.js index 1fbc68b..014f849 100644 --- a/websocket.js +++ b/websocket.js @@ -1,17 +1,17 @@ /* -Only websocket-specific stuff. +Only WebSocket-specific stuff. */
// eslint-disable-next-line no-unused-vars class WS { /** - * Creates a websocket URL from a base URL and an optional client IP address + * Creates a WebSocket URL from a base URL and an optional client IP address * string. * @param {URL|string} url * @param {?string} clientIP * @return {URL} */ - static makeWebsocketURL(url, clientIP) { + static makeWebSocketURL(url, clientIP) { url = new URL(url); if (clientIP != null) { url.searchParams.set('client_ip', clientIP); @@ -20,14 +20,14 @@ class WS { }
/** - * Creates a websocket connection from a URL and an optional client IP address + * Creates a WebSocket connection from a URL and an optional client IP address * string. * @param {URL|string} url * @param {?string} clientIP * @return {WebSocket} */ - static makeWebsocket(url, clientIP) { - let ws = new WebSocket(WS.makeWebsocketURL(url, clientIP)); + static makeWebSocket(url, clientIP) { + let ws = new WebSocket(WS.makeWebSocketURL(url, clientIP)); /* 'User agents can use this as a hint for how to handle incoming binary data: if the attribute is set to 'blob', it is safe to spool it to disk, and if it @@ -41,9 +41,9 @@ class WS { /** * @param {URL | string} addr */ - static probeWebsocket(addr) { + static probeWebSocket(addr) { return /** @type {Promise<void>} */(new Promise((resolve, reject) => { - const ws = WS.makeWebsocket(addr, null); + const ws = WS.makeWebSocket(addr, null); ws.onopen = () => { resolve(); ws.close();
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.
commit 85872223eb9c21f52ae3b488c7cbc0246f9b4932 Author: David Fifield david@bamsoftware.com AuthorDate: Wed Mar 29 12:13:36 2023 -0600
Remove an obsolete comment.
About RTCPeerConnection.remoteDescription being experimental. --- proxypair.js | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 627607f..7957879 100644 --- a/proxypair.js +++ b/proxypair.js @@ -159,10 +159,6 @@ class ProxyPair { 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. - // MDN marks remoteDescription as "experimental". However the other two - // options, currentRemoteDescription and pendingRemoteDescription, which - // 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 clientIP = Parse.ipFromSDP(remoteDescription.sdp); const relay = this.relay = WS.makeWebSocket(this.relayURL, clientIP);
tor-commits@lists.torproject.org