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 874e4ac fix: send SDP answer if ICE gathering is taking long to complete new bac1ba7 refactor: simplify `getClientOffer` new 71817a0 refactor: use `icegatheringstatechange` instead of `onicecandidate` new 132213e refactor: remove global var usage new 2a102fb refactor: better encapsulation for `ProxyPair` new c38fa4e refactor: mark some methods and props as private new bf59d5c refactor: a bit of syntaxic sugar new 833efca refactor: reorder lines new 9f7d1e8 refactor: improve logging messages new 79dd047 refactor remove an outdated comment new 85615e0 refactor: simplify `pollBroker` new be8a122 refactor: rename `beginWebRTC` -> `beginServingClients` new 1e132b7 refactor: format, add comments new 2730067 refactor: fewer `this` usages new 57d6ce5 refactor: remove `dbg()` from onMessage new ce18541 feat: add logging of connection stats
The 15 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: README.md | 2 +- broker.js | 30 +++++++------- init-badge.js | 2 +- init-node.js | 2 +- init-testing.js | 2 +- init-webext.js | 2 +- proxypair.js | 104 +++++++++++++++++++++++++++++++++++-------------- snowflake.js | 56 ++++++++++---------------- spec/proxypair.spec.js | 16 ++++---- spec/snowflake.spec.js | 40 ++++++++++++------- 10 files changed, 151 insertions(+), 105 deletions(-)
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 bac1ba798cca956cbcf913e277a00151d6fb315b Author: WofWca wofwca@protonmail.com AuthorDate: Fri Nov 4 12:19:14 2022 +0400
refactor: simplify `getClientOffer` --- broker.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/broker.js b/broker.js index 761efcf..f9be89f 100644 --- a/broker.js +++ b/broker.js @@ -51,22 +51,21 @@ class Broker { if (xhr.DONE !== xhr.readyState) { return; } - switch (xhr.status) { - case Broker.CODE.OK: { - const response = JSON.parse(xhr.responseText); - if (response.Status == Broker.STATUS.MATCH) { - return fulfill(response); // Should contain offer. - } else if (response.Status == Broker.STATUS.TIMEOUT) { - return reject(Broker.MESSAGE.TIMEOUT); - } else { - log('Broker ERROR: Unexpected ' + response.Status); - return reject(Broker.MESSAGE.UNEXPECTED); - } + if (xhr.status !== Broker.CODE.OK) { + log('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText); + snowflake.ui.setStatus(' failure. Please refresh.'); + reject(Broker.MESSAGE.UNEXPECTED); + return; + } + const response = JSON.parse(xhr.responseText); + switch (response.Status) { + case Broker.STATUS.MATCH: fulfill(response); return; + case Broker.STATUS.TIMEOUT: reject(Broker.MESSAGE.TIMEOUT); return; + default: { + log('Broker ERROR: Unexpected ' + response.Status); + reject(Broker.MESSAGE.UNEXPECTED); + return; } - default: - log('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText); - snowflake.ui.setStatus(' failure. Please refresh.'); - return reject(Broker.MESSAGE.UNEXPECTED); } }; this._xhr = xhr; // Used by spec to fake async Broker interaction
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 71817a00c405604c2d81051ee1bc95aa1f118fcc Author: WofWca wofwca@protonmail.com AuthorDate: Fri Nov 4 13:55:12 2022 +0400
refactor: use `icegatheringstatechange` instead of `onicecandidate` --- proxypair.js | 7 +++---- spec/proxypair.spec.js | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/proxypair.js b/proxypair.js index f0adba6..4b7c115 100644 --- a/proxypair.js +++ b/proxypair.js @@ -69,12 +69,11 @@ class ProxyPair { const onceSendAnswer = () => { snowflake.broker.sendAnswer(this.id, this.pc.localDescription);
- this.pc.onicecandidate = null; + this.pc.onicegatheringstatechange = null; clearTimeout(this.answerTimeoutId); }; - this.pc.onicecandidate = (evt) => { - // Browser sends a null candidate once the ICE gathering completes. - if (null === evt.candidate && this.pc.connectionState !== 'closed') { + this.pc.onicegatheringstatechange = () => { + if (this.pc.iceGatheringState === 'complete' && this.pc.connectionState !== 'closed') { dbg('Finished gathering ICE candidates.'); onceSendAnswer(); } diff --git a/spec/proxypair.spec.js b/spec/proxypair.spec.js index 8e0b330..6cf71f2 100644 --- a/spec/proxypair.spec.js +++ b/spec/proxypair.spec.js @@ -84,9 +84,8 @@ describe('ProxyPair', function() { type: 'offer', sdp: 'foo' }); - pp.pc.onicecandidate({ - candidate: null - }); + pp.pc.iceGatheringState = 'complete'; + pp.pc.onicegatheringstatechange(); expect(snowflake.broker.sendAnswer).toHaveBeenCalled(); });
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 132213e24855fc65b1255828e39fde5fb5f44b54 Author: WofWca wofwca@protonmail.com AuthorDate: Fri Nov 4 14:47:25 2022 +0400
refactor: remove global var usage --- proxypair.js | 5 +++-- snowflake.js | 7 ++++++- spec/proxypair.spec.js | 11 +++++++---- 3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 4b7c115..493d9e3 100644 --- a/proxypair.js +++ b/proxypair.js @@ -50,9 +50,10 @@ class ProxyPair {
/** * @param {RTCSessionDescription} offer + * @param {(answer: RTCSessionDescription) => void} sendAnswer * @returns {boolean} `true` on success, `false` on fail. */ - receiveWebRTCOffer(offer) { + receiveWebRTCOffer(offer, sendAnswer) { if ('offer' !== offer.type) { log('Invalid SDP received -- was not an offer.'); return false; @@ -67,7 +68,7 @@ class ProxyPair {
// Send the answer when ready. const onceSendAnswer = () => { - snowflake.broker.sendAnswer(this.id, this.pc.localDescription); + sendAnswer(this.pc.localDescription);
this.pc.onicegatheringstatechange = null; clearTimeout(this.answerTimeoutId); diff --git a/snowflake.js b/snowflake.js index abb4c11..7342856 100644 --- a/snowflake.js +++ b/snowflake.js @@ -154,7 +154,12 @@ class Snowflake { const offer = JSON.parse(desc); dbg('Received:\n\n' + offer.sdp + '\n'); const sdp = new RTCSessionDescription(offer); - if (pair.receiveWebRTCOffer(sdp)) { + if ( + pair.receiveWebRTCOffer( + sdp, + answer => this.broker.sendAnswer(pair.id, answer) + ) + ) { this.sendAnswer(pair); return true; } else { diff --git a/spec/proxypair.spec.js b/spec/proxypair.spec.js index 6cf71f2..3b8bc0a 100644 --- a/spec/proxypair.spec.js +++ b/spec/proxypair.spec.js @@ -80,10 +80,13 @@ describe('ProxyPair', function() {
it('responds with a WebRTC answer correctly', function() { spyOn(snowflake.broker, 'sendAnswer'); - pp.receiveWebRTCOffer({ - type: 'offer', - sdp: 'foo' - }); + pp.receiveWebRTCOffer( + { + type: 'offer', + sdp: 'foo' + }, + answer => snowflake.broker.sendAnswer(pp.id, answer), + ); pp.pc.iceGatheringState = 'complete'; pp.pc.onicegatheringstatechange(); expect(snowflake.broker.sendAnswer).toHaveBeenCalled();
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 2a102fb50d221069024079fe9dcea451ce448b7c Author: WofWca wofwca@protonmail.com AuthorDate: Fri Nov 4 16:27:38 2022 +0400
refactor: better encapsulation for `ProxyPair` --- proxypair.js | 10 ++++++++++ snowflake.js | 32 +++++--------------------------- spec/snowflake.spec.js | 38 ++++++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 493d9e3..ecce907 100644 --- a/proxypair.js +++ b/proxypair.js @@ -66,6 +66,16 @@ class ProxyPair { } dbg('SDP ' + offer.type + ' successfully received.');
+ this.pc.createAnswer() + .then((sdp) => { + dbg('webrtc: Answer ready.'); + return this.pc.setLocalDescription(sdp); + }) + .catch(() => { + this.close(); + dbg('webrtc: Failed to create or set Answer'); + }); + // Send the answer when ready. const onceSendAnswer = () => { sendAnswer(this.pc.localDescription); diff --git a/snowflake.js b/snowflake.js index 7342856..0fd2acc 100644 --- a/snowflake.js +++ b/snowflake.js @@ -154,39 +154,17 @@ class Snowflake { const offer = JSON.parse(desc); dbg('Received:\n\n' + offer.sdp + '\n'); const sdp = new RTCSessionDescription(offer); - if ( - pair.receiveWebRTCOffer( - sdp, - answer => this.broker.sendAnswer(pair.id, answer) - ) - ) { - this.sendAnswer(pair); - return true; - } else { - return false; - } + const result = pair.receiveWebRTCOffer( + sdp, + answer => this.broker.sendAnswer(pair.id, answer) + ); + return result; } catch (e) { log('ERROR: Unable to receive Offer: ' + e); return false; } }
- /** - * @param {ProxyPair} pair - */ - sendAnswer(pair) { - /** @param {RTCLocalSessionDescriptionInit} sdp */ - const next = function (sdp) { - dbg('webrtc: Answer ready.'); - pair.pc.setLocalDescription(sdp).catch(fail); - }; - const fail = function () { - pair.close(); - dbg('webrtc: Failed to create or set Answer'); - }; - pair.pc.createAnswer().then(next).catch(fail); - } - /** * @returns {ProxyPair} */ diff --git a/spec/snowflake.spec.js b/spec/snowflake.spec.js index 812430d..54ecb02 100644 --- a/spec/snowflake.spec.js +++ b/spec/snowflake.spec.js @@ -9,6 +9,12 @@ class RTCPeerConnection { setRemoteDescription() { return true; } + createAnswer() { + return Promise.resolve('foo'); + } + setLocalDescription() { + return Promise.resolve(); + } send() {} }
@@ -38,6 +44,7 @@ class FakeBroker { } setNATType(natType) { } + sendAnswer() {} }
describe('Snowflake', function() { @@ -68,27 +75,34 @@ describe('Snowflake', function() { });
it('receives SDP offer and sends answer', function() { - var pair, s; - s = new Snowflake(config, ui, new FakeBroker()); + var broker, pair, s; + broker = new FakeBroker(); + s = new Snowflake(config, ui, broker); pair = { - receiveWebRTCOffer: function() {} + id: 'foo', + receiveWebRTCOffer: function(_offer, sendAnswer) { + sendAnswer('bar'); + return true; + } }; - spyOn(pair, 'receiveWebRTCOffer').and.returnValue(true); - spyOn(s, 'sendAnswer'); + spyOn(broker, 'sendAnswer'); s.receiveOffer(pair, '{"type":"offer","sdp":"foo"}'); - expect(s.sendAnswer).toHaveBeenCalled(); + expect(broker.sendAnswer).toHaveBeenCalled(); });
it('does not send answer when receiving invalid offer', function() { - var pair, s; - s = new Snowflake(config, ui, new FakeBroker()); + var broker, pair, s; + broker = new FakeBroker(); + s = new Snowflake(config, ui, broker); pair = { - receiveWebRTCOffer: function() {} + id: 'foo', + receiveWebRTCOffer: function(_offer, sendAnswer) { + return false; + } }; - spyOn(pair, 'receiveWebRTCOffer').and.returnValue(false); - spyOn(s, 'sendAnswer'); + spyOn(broker, 'sendAnswer'); s.receiveOffer(pair, '{"type":"not a good offer","sdp":"foo"}'); - expect(s.sendAnswer).not.toHaveBeenCalled(); + expect(broker.sendAnswer).not.toHaveBeenCalled(); });
it('can make a proxypair', function() {
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 c38fa4e2c81ea340dc3438b77d0d9486ff3091a0 Author: WofWca wofwca@protonmail.com AuthorDate: Fri Nov 4 16:49:30 2022 +0400
refactor: mark some methods and props as private --- proxypair.js | 16 ++++++++++++++-- snowflake.js | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/proxypair.js b/proxypair.js index ecce907..2532a2e 100644 --- a/proxypair.js +++ b/proxypair.js @@ -38,12 +38,14 @@ class ProxyPair {
/** Prepare a WebRTC PeerConnection and await for an SDP offer. */ begin() { + /** @private */ this.pc = new RTCPeerConnection(this.pcConfig); // OnDataChannel triggered remotely from the client when connection succeeds. this.pc.ondatachannel = (dc) => { const channel = dc.channel; dbg('Data Channel established...'); this.prepareDataChannel(channel); + /** @private */ this.client = channel; }; } @@ -113,6 +115,7 @@ class ProxyPair { /** * Given a WebRTC DataChannel, prepare callbacks. * @param {RTCDataChannel} channel + * @private */ prepareDataChannel(channel) { // if we don't receive any keep-alive messages from the client, close the @@ -155,7 +158,10 @@ class ProxyPair { channel.onmessage = this.onClientToRelayMessage; }
- /** Assumes WebRTC datachannel is connected. */ + /** + * Assumes WebRTC datachannel is connected. + * @private + */ connectRelay() { dbg('Connecting to relay...'); // Get a remote IP address from the PeerConnection, if possible. Add it to @@ -203,6 +209,7 @@ class ProxyPair { /** * WebRTC --> websocket * @param {MessageEvent} msg + * @private */ onClientToRelayMessage(msg) { dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes'); @@ -215,6 +222,7 @@ class ProxyPair { /** * websocket --> WebRTC * @param {MessageEvent} event + * @private */ onRelayToClientMessage(event) { dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes'); @@ -222,6 +230,7 @@ class ProxyPair { this.flush(); }
+ /** @private */ onError(event) { const ws = event.target; log(ws.label + ' error.'); @@ -245,7 +254,10 @@ class ProxyPair { this.onCleanup(); }
- /** Send as much data in both directions as the rate limit currently allows. */ + /** + * Send as much data in both directions as the rate limit currently allows. + * @private + */ flush() { let busy = true; while (busy && !this.rateLimit.isLimited()) { diff --git a/snowflake.js b/snowflake.js index 0fd2acc..9af003e 100644 --- a/snowflake.js +++ b/snowflake.js @@ -62,6 +62,7 @@ class Snowflake { /** * Regularly poll Broker for clients to serve until this snowflake is * serving at capacity, at which point stop polling. + * @private */ pollBroker() { // Poll broker for clients. @@ -133,6 +134,7 @@ class Snowflake { * @param {string} desc * @param {string | undefined} relayURL * @returns {boolean} `true` on success, `false` on fail. + * @private */ receiveOffer(pair, desc, relayURL) { try { @@ -167,6 +169,7 @@ class Snowflake {
/** * @returns {ProxyPair} + * @private */ makeProxyPair() { const pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config); @@ -199,6 +202,7 @@ class Snowflake { * @param {string} pattern * @param {string} str typically a domain name to be checked * @return {boolean} + * @private */ checkRelayPattern(pattern, str) { if (typeof pattern !== "string") {
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 bf59d5c781e28eb756b850ffccdecb02b987ce4a Author: WofWca wofwca@protonmail.com AuthorDate: Sat Nov 5 17:53:05 2022 +0400
refactor: a bit of syntaxic sugar --- proxypair.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 2532a2e..27e6bcc 100644 --- a/proxypair.js +++ b/proxypair.js @@ -41,8 +41,7 @@ class ProxyPair { /** @private */ this.pc = new RTCPeerConnection(this.pcConfig); // OnDataChannel triggered remotely from the client when connection succeeds. - this.pc.ondatachannel = (dc) => { - const channel = dc.channel; + this.pc.ondatachannel = ({ channel }) => { dbg('Data Channel established...'); this.prepareDataChannel(channel); /** @private */
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 833efcac57f3d3fd4dd5c22cc60777bae0ee5917 Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 12:41:27 2022 +0400
refactor: reorder lines --- proxypair.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 27e6bcc..bd128c8 100644 --- a/proxypair.js +++ b/proxypair.js @@ -117,23 +117,22 @@ class ProxyPair { * @private */ prepareDataChannel(channel) { - // if we don't receive any keep-alive messages from the client, close the - // connection - const onStaleTimeout = () => { - console.log("Closing stale connection."); - this.flush(); - this.close(); - }; - this.refreshStaleTimeout = () => { - clearTimeout(this.messageTimer); - this.messageTimer = setTimeout(onStaleTimeout, this.config.messageTimeout); - }; - channel.onopen = () => { log('WebRTC DataChannel opened!'); snowflake.ui.increaseClients(); this.counted = true;
+ // if we don't receive any keep-alive messages from the client, close the + // connection + const onStaleTimeout = () => { + console.log("Closing stale connection."); + this.flush(); + this.close(); + }; + this.refreshStaleTimeout = () => { + clearTimeout(this.messageTimer); + this.messageTimer = setTimeout(onStaleTimeout, this.config.messageTimeout); + }; this.refreshStaleTimeout();
// This is the point when the WebRTC datachannel is done, so the next step
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 9f7d1e8e0deb5384c02bba4614721b946b8e49fa Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 13:21:55 2022 +0400
refactor: improve logging messages --- snowflake.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/snowflake.js b/snowflake.js index 9af003e..4431a99 100644 --- a/snowflake.js +++ b/snowflake.js @@ -67,7 +67,7 @@ class Snowflake { pollBroker() { // Poll broker for clients. if (this.proxyPairs.length >= this.config.maxNumClients) { - log('At client capacity.'); + dbg('Polling skipped: at client capacity.'); return; } const pair = this.makeProxyPair();
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 79dd0473e70e4b81de6a5dad46b0aa2b0c8c53c2 Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 13:42:13 2022 +0400
refactor remove an outdated comment --- snowflake.js | 1 - 1 file changed, 1 deletion(-)
diff --git a/snowflake.js b/snowflake.js index 4431a99..573b933 100644 --- a/snowflake.js +++ b/snowflake.js @@ -72,7 +72,6 @@ class Snowflake { } const pair = this.makeProxyPair(); log('Polling broker..'); - // Do nothing until a new proxyPair is available. let msg = 'Polling for client ... '; if (this.retries > 0) { msg += '[retries: ' + this.retries + ']';
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 85615e0ec6696ac5c0c519380e19b8c0b398f865 Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 13:48:43 2022 +0400
refactor: simplify `pollBroker` --- snowflake.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/snowflake.js b/snowflake.js index 573b933..775fded 100644 --- a/snowflake.js +++ b/snowflake.js @@ -53,23 +53,21 @@ class Snowflake { * process. `pollBroker` automatically arranges signalling. */ beginWebRTC() { - this.pollBroker(); + if (this.proxyPairs.length < this.config.maxNumClients) { + this.pollBroker(); + } else { + dbg('Polling skipped: at client capacity.'); + } this.pollTimeoutId = setTimeout((() => { this.beginWebRTC(); }), this.pollInterval); }
/** - * Regularly poll Broker for clients to serve until this snowflake is - * serving at capacity, at which point stop polling. + * Try to get a client from the broker and start serving it upon success. * @private */ pollBroker() { - // Poll broker for clients. - if (this.proxyPairs.length >= this.config.maxNumClients) { - dbg('Polling skipped: at client capacity.'); - return; - } const pair = this.makeProxyPair(); log('Polling broker..'); let msg = 'Polling for client ... ';
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 be8a122f07c99c5189067a3c06e61e3d9f9a0709 Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 13:52:39 2022 +0400
refactor: rename `beginWebRTC` -> `beginServingClients`
And reword the docstring --- README.md | 2 +- init-badge.js | 2 +- init-node.js | 2 +- init-testing.js | 2 +- init-webext.js | 2 +- snowflake.js | 7 +++---- spec/snowflake.spec.js | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md index 96fde7b..418e0c6 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ var broker = new Broker(config.brokerUrl); var snowflake = new Snowflake(config, ui, broker);
snowflake.setRelayAddr(config.relayAddr); -snowflake.beginWebRTC(); +snowflake.beginServingClients(); ```
This minimal setup is pretty much what's currently in `init-node.js`. diff --git a/init-badge.js b/init-badge.js index a4305a2..0c4c00f 100644 --- a/init-badge.js +++ b/init-badge.js @@ -181,7 +181,7 @@ var dbg('Contacting Broker at ' + broker.url); log('Starting snowflake'); snowflake.setRelayAddr(config.relayAddr); - snowflake.beginWebRTC(); + snowflake.beginServingClients(); }, () => { ui.missingFeature('popupBridgeUnreachable'); diff --git a/init-node.js b/init-node.js index e5c2e32..66c0fa4 100644 --- a/init-node.js +++ b/init-node.js @@ -24,4 +24,4 @@ dbg('Contacting Broker at ' + broker.url);
snowflake.setRelayAddr(config.relayAddr);
-snowflake.beginWebRTC(); +snowflake.beginServingClients(); diff --git a/init-testing.js b/init-testing.js index 637c961..235f2b3 100644 --- a/init-testing.js +++ b/init-testing.js @@ -118,7 +118,7 @@ var // Otherwise, begin setting up WebRTC and acting as a proxy. dbg('Contacting Broker at ' + broker.url); snowflake.setRelayAddr(config.relayAddr); - return snowflake.beginWebRTC(); + return snowflake.beginServingClients(); };
// Notification of closing tab with active proxy. diff --git a/init-webext.js b/init-webext.js index 3bbdfde..daa8e9a 100644 --- a/init-webext.js +++ b/init-webext.js @@ -281,7 +281,7 @@ var dbg('Contacting Broker at ' + broker.url); log('Starting snowflake'); snowflake.setRelayAddr(config.relayAddr); - snowflake.beginWebRTC(); + snowflake.beginServingClients(); };
window.onunload = function() { diff --git a/snowflake.js b/snowflake.js index 775fded..ae0a974 100644 --- a/snowflake.js +++ b/snowflake.js @@ -49,17 +49,16 @@ class Snowflake { }
/** - * Initialize WebRTC PeerConnection, which requires beginning the signalling - * process. `pollBroker` automatically arranges signalling. + * Start asking the broker for clients and serving them. */ - beginWebRTC() { + beginServingClients() { if (this.proxyPairs.length < this.config.maxNumClients) { this.pollBroker(); } else { dbg('Polling skipped: at client capacity.'); } this.pollTimeoutId = setTimeout((() => { - this.beginWebRTC(); + this.beginServingClients(); }), this.pollInterval); }
diff --git a/spec/snowflake.spec.js b/spec/snowflake.spec.js index 54ecb02..bac49d0 100644 --- a/spec/snowflake.spec.js +++ b/spec/snowflake.spec.js @@ -69,7 +69,7 @@ describe('Snowflake', function() { var s; s = new Snowflake(config, ui, new FakeBroker()); spyOn(s.broker, 'getClientOffer').and.callThrough(); - s.beginWebRTC(); + s.beginServingClients(); expect(s.retries).toBe(1); expect(s.broker.getClientOffer).toHaveBeenCalled(); });
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 1e132b7acd830f63351e58fc107f106589d1b0bd Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 14:31:57 2022 +0400
refactor: format, add comments --- broker.js | 1 + snowflake.js | 3 +++ 2 files changed, 4 insertions(+)
diff --git a/broker.js b/broker.js index f9be89f..291a0ed 100644 --- a/broker.js +++ b/broker.js @@ -42,6 +42,7 @@ class Broker { * Registers this Snowflake with the broker using an HTTP POST request, and * waits for a response containing some client offer that the Broker chooses * for this proxy.. + * Rejects on timeout or on error. * TODO: Actually support multiple clients. */ getClientOffer(id, numClientsConnected) { diff --git a/snowflake.js b/snowflake.js index ae0a974..c62ee62 100644 --- a/snowflake.js +++ b/snowflake.js @@ -69,14 +69,17 @@ class Snowflake { pollBroker() { const pair = this.makeProxyPair(); log('Polling broker..'); + let msg = 'Polling for client ... '; if (this.retries > 0) { msg += '[retries: ' + this.retries + ']'; } this.ui.setStatus(msg); + //update NAT type console.log("NAT type: " + this.ui.natType); this.broker.setNATType(this.ui.natType); + const recv = this.broker.getClientOffer(pair.id, this.proxyPairs.length); recv.then((resp) => { const clientNAT = resp.NAT;
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 27300671c2866dbeb5c32a249d9aa8cca528f55a Author: WofWca wofwca@protonmail.com AuthorDate: Sun Nov 6 15:38:59 2022 +0400
refactor: fewer `this` usages --- proxypair.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/proxypair.js b/proxypair.js index bd128c8..15d6ea7 100644 --- a/proxypair.js +++ b/proxypair.js @@ -179,13 +179,13 @@ class ProxyPair { (this.relayURL === undefined) ? WS.makeWebsocket(this.relayAddr, params) : WS.makeWebsocketFromURL(this.relayURL, params); - this.relay.label = 'websocket-relay'; - this.relay.onopen = () => { + relay.label = 'websocket-relay'; + relay.onopen = () => { clearTimeout(this.connectToRelayTimeoutId); log(relay.label + ' connected!'); snowflake.ui.setStatus('connected'); }; - this.relay.onclose = () => { + relay.onclose = () => { log(relay.label + ' closed.'); snowflake.ui.setStatus('disconnected.'); if (this.counted) { @@ -195,8 +195,8 @@ class ProxyPair { this.flush(); this.close(); }; - this.relay.onerror = this.onError; - this.relay.onmessage = this.onRelayToClientMessage; + relay.onerror = this.onError; + relay.onmessage = this.onRelayToClientMessage; // TODO: Better websocket timeout handling. this.connectToRelayTimeoutId = setTimeout((() => { log(relay.label + ' timed out connecting.');
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 57d6ce54e8de45850c8a1a9ca64d030db5d2a685 Author: WofWca wofwca@protonmail.com AuthorDate: Mon Nov 7 18:32:15 2022 +0400
refactor: remove `dbg()` from onMessage
There's too many of such messages. Messages can be viewed on the "Network" tab of devtools as well --- proxypair.js | 2 -- 1 file changed, 2 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 15d6ea7..ecbaf88 100644 --- a/proxypair.js +++ b/proxypair.js @@ -210,7 +210,6 @@ class ProxyPair { * @private */ onClientToRelayMessage(msg) { - dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes'); this.c2rSchedule.push(msg.data); this.flush();
@@ -223,7 +222,6 @@ class ProxyPair { * @private */ onRelayToClientMessage(event) { - dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes'); this.r2cSchedule.push(event.data); this.flush(); }
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 ce185410d3e79163a8b1f028278b8af1328312cf Author: WofWca wofwca@protonmail.com AuthorDate: Mon Nov 7 20:48:01 2022 +0400
feat: add logging of connection stats --- proxypair.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/proxypair.js b/proxypair.js index ecbaf88..f3df964 100644 --- a/proxypair.js +++ b/proxypair.js @@ -1,4 +1,4 @@ -/* global snowflake, log, dbg, Util, Parse, WS */ +/* global snowflake, log, dbg, debug, Util, Parse, WS */
/** Represents a single: @@ -235,6 +235,32 @@ class ProxyPair {
/** Close both WebRTC and websocket. */ close() { + if (debug) { + this.pc.getStats().then(report => { + let transportStats; + for (const stat of report.values()) { + // Also consider 'data-channel'. + if (stat.type === 'transport') { + transportStats = stat; + break; + } + } + if (!transportStats) { + return; + } + function bytesToMBytesStr(numBytes) { + return (numBytes / 1024 / 1024).toFixed(3); + } + log( + `Connection closed. Traffic (up|down):` + + ` ${bytesToMBytesStr(transportStats.bytesReceived)} MB|` + + `${bytesToMBytesStr(transportStats.bytesSent)} MB` + + `, packets: ${transportStats.packetsReceived}|` + + `${transportStats.packetsSent}` + ); + }); + } + clearTimeout(this.connectToRelayTimeoutId); clearTimeout(this.messageTimer); clearTimeout(this.answerTimeoutId);
tor-commits@lists.torproject.org