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

[tor-commits] [snowflake/master] Update proxy config to take proxy type



commit 8ab81fc6cdbd34083a567429b51375ca5512fd50
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Wed Nov 20 13:09:11 2019 -0500

    Update proxy config to take proxy type
    
    This allows badge and standalone proxies to tell the broker what proxy
    type they are.
---
 proxy/broker.js           |  7 ++++---
 proxy/config.js           |  2 ++
 proxy/init-badge.js       |  3 ++-
 proxy/init-node.js        |  2 +-
 proxy/init-testing.js     |  2 +-
 proxy/init-webext.js      |  3 ++-
 proxy/spec/broker.spec.js | 24 ++++++++++++++++++------
 7 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/proxy/broker.js b/proxy/broker.js
index 551110b..42293ae 100644
--- a/proxy/broker.js
+++ b/proxy/broker.js
@@ -14,11 +14,12 @@ class Broker {
   // ID so the Broker can keep track of each proxy's signalling channels.
   // On construction, this Broker object does not do anything until
   // |getClientOffer| is called.
-  constructor(url) {
+  constructor(config) {
     this.getClientOffer = this.getClientOffer.bind(this);
     this._postRequest = this._postRequest.bind(this);
 
-    this.url = url;
+    this.config = config
+    this.url = config.brokerUrl;
     this.clients = 0;
     if (0 === this.url.indexOf('localhost', 0)) {
       // Ensure url has the right protocol + trailing slash.
@@ -63,7 +64,7 @@ class Broker {
         }
       };
       this._xhr = xhr; // Used by spec to fake async Broker interaction
-      var data = {"Version": "1.0", "Sid": id}
+      var data = {"Version": "1.1", "Sid": id, "Type": this.config.proxyType}
       return this._postRequest(xhr, 'proxy', JSON.stringify(data));
     });
   }
diff --git a/proxy/config.js b/proxy/config.js
index 9564f82..2b698a6 100644
--- a/proxy/config.js
+++ b/proxy/config.js
@@ -24,6 +24,8 @@ Config.prototype.defaultBrokerPollInterval = 300.0 * 1000;
 
 Config.prototype.maxNumClients = 1;
 
+Config.prototype.proxyType = "";
+
 // TODO: Different ICE servers.
 Config.prototype.pcConfig = {
   iceServers: [
diff --git a/proxy/init-badge.js b/proxy/init-badge.js
index 2cc5b07..2e0a261 100644
--- a/proxy/init-badge.js
+++ b/proxy/init-badge.js
@@ -170,10 +170,11 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
     }
 
     config = new Config;
+    config.proxyType = "badge";
     if ('off' !== query.get('ratelimit')) {
       config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes);
     }
-    broker = new Broker(config.brokerUrl);
+    broker = new Broker(config);
     snowflake = new Snowflake(config, ui, broker);
     log('== snowflake proxy ==');
     update();
diff --git a/proxy/init-node.js b/proxy/init-node.js
index 789e6e3..73c25dc 100644
--- a/proxy/init-node.js
+++ b/proxy/init-node.js
@@ -8,7 +8,7 @@ var config = new Config;
 
 var ui = new UI();
 
-var broker = new Broker(config.brokerUrl);
+var broker = new Broker(config);
 
 var snowflake = new Snowflake(config, ui, broker);
 
diff --git a/proxy/init-testing.js b/proxy/init-testing.js
index 90026a9..f553f12 100644
--- a/proxy/init-testing.js
+++ b/proxy/init-testing.js
@@ -89,7 +89,7 @@ var snowflake, query, debug, ui, silenceNotifications, log, dbg, init;
     } else {
       ui = new UI();
     }
-    broker = new Broker(config.brokerUrl);
+    broker = new Broker(config);
     snowflake = new Snowflake(config, ui, broker);
     log('== snowflake proxy ==');
     if (Util.snowflakeIsDisabled(config.cookieName)) {
diff --git a/proxy/init-webext.js b/proxy/init-webext.js
index ad345fa..afa9aee 100644
--- a/proxy/init-webext.js
+++ b/proxy/init-webext.js
@@ -172,8 +172,9 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
 
   init = function() {
     config = new Config;
+    config.proxyType = "webext";
     ui = new WebExtUI();
-    broker = new Broker(config.brokerUrl);
+    broker = new Broker(config);
     snowflake = new Snowflake(config, ui, broker);
     log('== snowflake proxy ==');
     ui.initToggle();
diff --git a/proxy/spec/broker.spec.js b/proxy/spec/broker.spec.js
index 6ab9691..28a66c4 100644
--- a/proxy/spec/broker.spec.js
+++ b/proxy/spec/broker.spec.js
@@ -22,7 +22,9 @@ describe('Broker', function() {
 
   it('can be created', function() {
     var b;
-    b = new Broker('fake');
+    var config = new Config;
+    config.brokerUrl = 'fake';
+    b = new Broker(config);
     expect(b.url).toEqual('https://fake/');
     expect(b.id).not.toBeNull();
   });
@@ -31,7 +33,9 @@ describe('Broker', function() {
 
     it('polls and promises a client offer', function(done) {
       var b, poll;
-      b = new Broker('fake');
+      var config = new Config;
+      config.brokerUrl = 'fake';
+      b = new Broker(config);
       // fake successful request and response from broker.
       spyOn(b, '_postRequest').and.callFake(function() {
         b._xhr.readyState = b._xhr.DONE;
@@ -53,7 +57,9 @@ describe('Broker', function() {
 
     it('rejects if the broker timed-out', function(done) {
       var b, poll;
-      b = new Broker('fake');
+      var config = new Config;
+      config.brokerUrl = 'fake';
+      b = new Broker(config);
       // fake timed-out request from broker
       spyOn(b, '_postRequest').and.callFake(function() {
         b._xhr.readyState = b._xhr.DONE;
@@ -75,7 +81,9 @@ describe('Broker', function() {
 
     it('rejects on any other status', function(done) {
       var b, poll;
-      b = new Broker('fake');
+      var config = new Config;
+      config.brokerUrl = 'fake';
+      b = new Broker(config);
       // fake timed-out request from broker
       spyOn(b, '_postRequest').and.callFake(function() {
         b._xhr.readyState = b._xhr.DONE;
@@ -99,14 +107,18 @@ describe('Broker', function() {
   });
 
   it('responds to the broker with answer', function() {
-    var b = new Broker('fake');
+    var config = new Config;
+    config.brokerUrl = 'fake';
+    var b = new Broker(config);
     spyOn(b, '_postRequest');
     b.sendAnswer('fake id', 123);
     expect(b._postRequest).toHaveBeenCalledWith(jasmine.any(Object), 'answer', '{"Version":"1.0","Sid":"fake id","Answer":"123"}');
   });
 
   it('POST XMLHttpRequests to the broker', function() {
-    var b = new Broker('fake');
+    var config = new Config;
+    config.brokerUrl = 'fake';
+    var b = new Broker(config);
     b._xhr = new XMLHttpRequest();
     spyOn(b._xhr, 'open');
     spyOn(b._xhr, 'setRequestHeader');



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits