mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Moved function comments to their definitions
Increase readability of code a bit, the function descriptions were automatically placed in the constructor when we moved from coffeescript.
This commit is contained in:
parent
789285e0df
commit
64b66c855f
3 changed files with 17 additions and 23 deletions
|
@ -15,15 +15,9 @@ class Broker {
|
||||||
// On construction, this Broker object does not do anything until
|
// On construction, this Broker object does not do anything until
|
||||||
// |getClientOffer| is called.
|
// |getClientOffer| is called.
|
||||||
constructor(url) {
|
constructor(url) {
|
||||||
// Promises some client SDP Offer.
|
|
||||||
// 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..
|
|
||||||
// TODO: Actually support multiple clients.
|
|
||||||
this.getClientOffer = this.getClientOffer.bind(this);
|
this.getClientOffer = this.getClientOffer.bind(this);
|
||||||
// urlSuffix for the broker is different depending on what action
|
|
||||||
// is desired.
|
|
||||||
this._postRequest = this._postRequest.bind(this);
|
this._postRequest = this._postRequest.bind(this);
|
||||||
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.clients = 0;
|
this.clients = 0;
|
||||||
if (0 === this.url.indexOf('localhost', 0)) {
|
if (0 === this.url.indexOf('localhost', 0)) {
|
||||||
|
@ -38,6 +32,11 @@ class Broker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Promises some client SDP Offer.
|
||||||
|
// 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..
|
||||||
|
// TODO: Actually support multiple clients.
|
||||||
getClientOffer(id) {
|
getClientOffer(id) {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
var xhr;
|
var xhr;
|
||||||
|
@ -87,6 +86,8 @@ class Broker {
|
||||||
return this._postRequest(id, xhr, 'answer', JSON.stringify(answer));
|
return this._postRequest(id, xhr, 'answer', JSON.stringify(answer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// urlSuffix for the broker is different depending on what action
|
||||||
|
// is desired.
|
||||||
_postRequest(id, xhr, urlSuffix, payload) {
|
_postRequest(id, xhr, urlSuffix, payload) {
|
||||||
var err;
|
var err;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -17,17 +17,13 @@ class ProxyPair {
|
||||||
- @rateLimit specifies a rate limit on traffic
|
- @rateLimit specifies a rate limit on traffic
|
||||||
*/
|
*/
|
||||||
constructor(relayAddr, rateLimit, pcConfig) {
|
constructor(relayAddr, rateLimit, pcConfig) {
|
||||||
// Given a WebRTC DataChannel, prepare callbacks.
|
|
||||||
this.prepareDataChannel = this.prepareDataChannel.bind(this);
|
this.prepareDataChannel = this.prepareDataChannel.bind(this);
|
||||||
// Assumes WebRTC datachannel is connected.
|
|
||||||
this.connectRelay = this.connectRelay.bind(this);
|
this.connectRelay = this.connectRelay.bind(this);
|
||||||
// WebRTC --> websocket
|
|
||||||
this.onClientToRelayMessage = this.onClientToRelayMessage.bind(this);
|
this.onClientToRelayMessage = this.onClientToRelayMessage.bind(this);
|
||||||
// websocket --> WebRTC
|
|
||||||
this.onRelayToClientMessage = this.onRelayToClientMessage.bind(this);
|
this.onRelayToClientMessage = this.onRelayToClientMessage.bind(this);
|
||||||
this.onError = this.onError.bind(this);
|
this.onError = this.onError.bind(this);
|
||||||
// Send as much data in both directions as the rate limit currently allows.
|
|
||||||
this.flush = this.flush.bind(this);
|
this.flush = this.flush.bind(this);
|
||||||
|
|
||||||
this.relayAddr = relayAddr;
|
this.relayAddr = relayAddr;
|
||||||
this.rateLimit = rateLimit;
|
this.rateLimit = rateLimit;
|
||||||
this.pcConfig = pcConfig;
|
this.pcConfig = pcConfig;
|
||||||
|
@ -82,6 +78,7 @@ class ProxyPair {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Given a WebRTC DataChannel, prepare callbacks.
|
||||||
prepareDataChannel(channel) {
|
prepareDataChannel(channel) {
|
||||||
channel.onopen = () => {
|
channel.onopen = () => {
|
||||||
log('WebRTC DataChannel opened!');
|
log('WebRTC DataChannel opened!');
|
||||||
|
@ -104,6 +101,7 @@ class ProxyPair {
|
||||||
return channel.onmessage = this.onClientToRelayMessage;
|
return channel.onmessage = this.onClientToRelayMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assumes WebRTC datachannel is connected.
|
||||||
connectRelay() {
|
connectRelay() {
|
||||||
var params, peer_ip, ref;
|
var params, peer_ip, ref;
|
||||||
dbg('Connecting to relay...');
|
dbg('Connecting to relay...');
|
||||||
|
@ -148,12 +146,14 @@ class ProxyPair {
|
||||||
}), 5000);
|
}), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebRTC --> websocket
|
||||||
onClientToRelayMessage(msg) {
|
onClientToRelayMessage(msg) {
|
||||||
dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes');
|
dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes');
|
||||||
this.c2rSchedule.push(msg.data);
|
this.c2rSchedule.push(msg.data);
|
||||||
return this.flush();
|
return this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// websocket --> WebRTC
|
||||||
onRelayToClientMessage(event) {
|
onRelayToClientMessage(event) {
|
||||||
dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes');
|
dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes');
|
||||||
this.r2cSchedule.push(event.data);
|
this.r2cSchedule.push(event.data);
|
||||||
|
@ -185,6 +185,7 @@ class ProxyPair {
|
||||||
this.onCleanup();
|
this.onCleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send as much data in both directions as the rate limit currently allows.
|
||||||
flush() {
|
flush() {
|
||||||
var busy, checkChunks;
|
var busy, checkChunks;
|
||||||
if (this.flush_timeout_id) {
|
if (this.flush_timeout_id) {
|
||||||
|
@ -239,15 +240,10 @@ class ProxyPair {
|
||||||
ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024;
|
ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024;
|
||||||
|
|
||||||
ProxyPair.prototype.pc = null;
|
ProxyPair.prototype.pc = null;
|
||||||
|
|
||||||
ProxyPair.prototype.client = null; // WebRTC Data channel
|
ProxyPair.prototype.client = null; // WebRTC Data channel
|
||||||
|
|
||||||
ProxyPair.prototype.relay = null; // websocket
|
ProxyPair.prototype.relay = null; // websocket
|
||||||
|
|
||||||
ProxyPair.prototype.timer = 0;
|
ProxyPair.prototype.timer = 0;
|
||||||
|
|
||||||
ProxyPair.prototype.flush_timeout_id = null;
|
ProxyPair.prototype.flush_timeout_id = null;
|
||||||
|
|
||||||
ProxyPair.prototype.onCleanup = null;
|
ProxyPair.prototype.onCleanup = null;
|
||||||
|
|
||||||
ProxyPair.prototype.id = null;
|
|
||||||
|
|
|
@ -16,9 +16,8 @@ class Snowflake {
|
||||||
|
|
||||||
// Prepare the Snowflake with a Broker (to find clients) and optional UI.
|
// Prepare the Snowflake with a Broker (to find clients) and optional UI.
|
||||||
constructor(config, ui, broker) {
|
constructor(config, ui, broker) {
|
||||||
// Receive an SDP offer from some client assigned by the Broker,
|
|
||||||
// |pair| - an available ProxyPair.
|
|
||||||
this.receiveOffer = this.receiveOffer.bind(this);
|
this.receiveOffer = this.receiveOffer.bind(this);
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.ui = ui;
|
this.ui = ui;
|
||||||
this.broker = broker;
|
this.broker = broker;
|
||||||
|
@ -85,6 +84,8 @@ class Snowflake {
|
||||||
return this.retries++;
|
return this.retries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Receive an SDP offer from some client assigned by the Broker,
|
||||||
|
// |pair| - an available ProxyPair.
|
||||||
receiveOffer(pair, desc) {
|
receiveOffer(pair, desc) {
|
||||||
var e, offer, sdp;
|
var e, offer, sdp;
|
||||||
try {
|
try {
|
||||||
|
@ -156,13 +157,9 @@ class Snowflake {
|
||||||
}
|
}
|
||||||
|
|
||||||
Snowflake.prototype.relayAddr = null;
|
Snowflake.prototype.relayAddr = null;
|
||||||
|
|
||||||
Snowflake.prototype.rateLimit = null;
|
Snowflake.prototype.rateLimit = null;
|
||||||
|
|
||||||
Snowflake.prototype.pollInterval = null;
|
Snowflake.prototype.pollInterval = null;
|
||||||
|
|
||||||
Snowflake.prototype.retries = 0;
|
|
||||||
|
|
||||||
Snowflake.MESSAGE = {
|
Snowflake.MESSAGE = {
|
||||||
CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'
|
CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue