[tor-commits] [snowflake-webext/main] Report the number of clients to the broker

meskio at torproject.org meskio at torproject.org
Wed Jul 21 09:30:14 UTC 2021


commit 5e68294638a1b90862f6f2404a378817fde33fa0
Author: meskio <meskio at torproject.org>
Date:   Mon Jun 28 12:28:09 2021 +0200

    Report the number of clients to the broker
    
    Client number is rounded down to 8. Currently the webextension doesn't
    support more than one client, and the client counter is actually never
    updated internally. So this code effectively always returns 0.
    
    Related to snowflake#40048
---
 broker.js    | 11 +++++++++--
 snowflake.js |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/broker.js b/broker.js
index 9d8b8b6..84eaed2 100644
--- a/broker.js
+++ b/broker.js
@@ -40,7 +40,7 @@ class Broker {
   // waits for a response containing some client offer that the Broker chooses
   // for this proxy..
   // TODO: Actually support multiple clients.
-  getClientOffer(id) {
+  getClientOffer(id, numClientsConnected) {
     return new Promise((fulfill, reject) => {
       var xhr;
       xhr = new XMLHttpRequest();
@@ -66,7 +66,14 @@ class Broker {
         }
       };
       this._xhr = xhr; // Used by spec to fake async Broker interaction
-      var data = {"Version": "1.2", "Sid": id, "Type": this.config.proxyType, "NAT": this.natType};
+      const clients = Math.floor(numClientsConnected / 8) * 8;
+      var data = {
+        Version: "1.2",
+        Sid: id,
+        Type: this.config.proxyType,
+        NAT: this.natType,
+        Clients: clients,
+      };
       return this._postRequest(xhr, 'proxy', JSON.stringify(data));
     });
   }
diff --git a/snowflake.js b/snowflake.js
index 7d4edb9..49c1253 100644
--- a/snowflake.js
+++ b/snowflake.js
@@ -71,7 +71,7 @@ class Snowflake {
     //update NAT type
     console.log("NAT type: "+ this.ui.natType);
     this.broker.setNATType(this.ui.natType);
-    recv = this.broker.getClientOffer(pair.id);
+    recv = this.broker.getClientOffer(pair.id, this.proxyPairs.length);
     recv.then((resp) => {
       var clientNAT = resp.NAT;
       if (!this.receiveOffer(pair, resp.Offer)) {





More information about the tor-commits mailing list