[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/snowflake-webext] 01/02: refactor: replace some `var` with `const`



This is an automated email from the git hooks/post-receive script.

meskio pushed a commit to branch main
in repository pluggable-transports/snowflake-webext.

commit c5e810efb96c72511cbcf4983a81b89d861741c4
Author: WofWca <wofwca@xxxxxxxxxxxxxx>
AuthorDate: Wed Jul 13 14:14:31 2022 +0300

    refactor: replace some `var` with `const`
    
    Follow-up to 31deee3
---
 broker.js    |  9 +++++----
 proxypair.js |  2 +-
 snowflake.js |  2 +-
 util.js      | 15 ++++++++-------
 websocket.js | 10 ++++------
 5 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/broker.js b/broker.js
index 2431630..36ca3f8 100644
--- a/broker.js
+++ b/broker.js
@@ -51,8 +51,8 @@ class Broker {
           return;
         }
         switch (xhr.status) {
-          case Broker.CODE.OK:
-            var response = JSON.parse(xhr.responseText);
+          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) {
@@ -61,6 +61,7 @@ class Broker {
               log('Broker ERROR: Unexpected ' + response.Status);
               return reject(Broker.MESSAGE.UNEXPECTED);
             }
+          }
           default:
             log('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText);
             snowflake.ui.setStatus(' failure. Please refresh.');
@@ -69,7 +70,7 @@ class Broker {
       };
       this._xhr = xhr; // Used by spec to fake async Broker interaction
       const clients = Math.floor(numClientsConnected / 8) * 8;
-      var data = {
+      const data = {
         Version: "1.3",
         Sid: id,
         Type: this.config.proxyType,
@@ -104,7 +105,7 @@ class Broker {
           break;
       }
     };
-    var data = {"Version": "1.0", "Sid": id, "Answer": JSON.stringify(answer)};
+    const data = {"Version": "1.0", "Sid": id, "Answer": JSON.stringify(answer)};
     this._postRequest(xhr, 'answer', JSON.stringify(data));
   }
 
diff --git a/proxypair.js b/proxypair.js
index 94d792a..a5b7823 100644
--- a/proxypair.js
+++ b/proxypair.js
@@ -111,7 +111,7 @@ class ProxyPair {
     if (peer_ip != null) {
       params.push(["client_ip", peer_ip]);
     }
-    var relay = this.relay =
+    const relay = this.relay =
       (this.relayURL === undefined) ?
         WS.makeWebsocket(this.relayAddr, params) :
         WS.makeWebsocketFromURL(this.relayURL, params);
diff --git a/snowflake.js b/snowflake.js
index bfa89c0..19d8992 100644
--- a/snowflake.js
+++ b/snowflake.js
@@ -76,7 +76,7 @@ class Snowflake {
     this.broker.setNATType(this.ui.natType);
     const recv = this.broker.getClientOffer(pair.id, this.proxyPairs.length);
     recv.then((resp) => {
-      var clientNAT = resp.NAT;
+      const clientNAT = resp.NAT;
       if (!this.receiveOffer(pair, resp.Offer, resp.RelayURL)) {
         pair.close();
         return;
diff --git a/util.js b/util.js
index 58d6512..73d67be 100644
--- a/util.js
+++ b/util.js
@@ -80,15 +80,16 @@ class Util {
           return;
         }
         switch (xhr.status) {
-          case 200:
-            var response = JSON.parse(xhr.responseText);
+          case 200: {
+            const response = JSON.parse(xhr.responseText);
             return fulfill(response.Answer); // Should contain offer.
+          }
           default:
             console.log('Probe ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText);
             return reject('Failed to get answer from probe service');
         }
       };
-      var data = {"Status": "client match", "Offer": JSON.stringify(offer)};
+      const data = {"Status": "client match", "Offer": JSON.stringify(offer)};
       try {
         xhr.open('POST', Config.PROBEURL);
       } catch (error) {
@@ -223,18 +224,18 @@ class Parse {
   /** Determine whether an IP address is a local, unspecified, or loopback address */
   static isRemoteIP(ip) {
     if (ip.includes(":")) {
-      var ip6 = ip.split(':');
+      const ip6 = ip.split(':');
       // Loopback address
-      var loopback = /^(?:0*:)*?:?0*1$/m;
+      const loopback = /^(?:0*:)*?:?0*1$/m;
       // Unspecified address
-      var unspecified = /^(?:0*:)*?:?0*$/m;
+      const unspecified = /^(?:0*:)*?:?0*$/m;
       // Local IPv6 addresses are defined in https://tools.ietf.org/html/rfc4193
       return !((loopback.exec(ip) != null) || (unspecified.exec(ip) != null) ||
         (parseInt(ip6[0],16)&0xfe00) == 0xfc00);
     }
 
     // Local IPv4 addresses are defined in https://tools.ietf.org/html/rfc1918
-    var ip4 = ip.split('.');
+    const ip4 = ip.split('.');
     return !(ip4[0] == 10 || ip4[0] == 127 || ip == "0.0.0.0" ||
       (ip4[0] == 172 && (ip4[1]&0xf0) == 16) ||
       (ip4[0] == 192 && ip4[1] == 168) ||
diff --git a/websocket.js b/websocket.js
index 7164577..4a27ef4 100644
--- a/websocket.js
+++ b/websocket.js
@@ -9,8 +9,7 @@ class WS {
    * are required. See RFC 3986, section 3.
    */
   static buildUrl(scheme, host, port, path, params) {
-    var parts;
-    parts = [];
+    const parts = [];
     parts.push(encodeURIComponent(scheme));
     parts.push('://');
     // If it contains a colon but no square brackets, treat it as IPv6.
@@ -42,10 +41,9 @@ class WS {
   }
 
   static makeWebsocket(addr, params) {
-    var url, ws, wsProtocol;
-    wsProtocol = this.WSS_ENABLED ? 'wss' : 'ws';
-    url = this.buildUrl(wsProtocol, addr.host, addr.port, '/', params);
-    ws = new WebSocket(url);
+    const wsProtocol = this.WSS_ENABLED ? 'wss' : 'ws';
+    const url = this.buildUrl(wsProtocol, addr.host, addr.port, '/', params);
+    const ws = new WebSocket(url);
     /*
     '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

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits