mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Update proxy config to take proxy type
This allows badge and standalone proxies to tell the broker what proxy type they are.
This commit is contained in:
parent
7277bb37cd
commit
8ab81fc6cd
7 changed files with 30 additions and 13 deletions
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue