[tor-commits] [snowflake/master] Moved function comments to their definitions

cohosh at torproject.org cohosh at torproject.org
Thu Oct 31 16:00:23 UTC 2019


commit 64b66c855fe35d2e56fca7510e913482cdb85793
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Fri Oct 18 17:48:45 2019 -0400

    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.
---
 proxy/broker.js    | 15 ++++++++-------
 proxy/proxypair.js | 16 ++++++----------
 proxy/snowflake.js |  9 +++------
 3 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/proxy/broker.js b/proxy/broker.js
index 9806e76..7b5b7e4 100644
--- a/proxy/broker.js
+++ b/proxy/broker.js
@@ -15,15 +15,9 @@ class Broker {
   // On construction, this Broker object does not do anything until
   // |getClientOffer| is called.
   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);
-    // urlSuffix for the broker is different depending on what action
-    // is desired.
     this._postRequest = this._postRequest.bind(this);
+
     this.url = url;
     this.clients = 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) {
     return new Promise((fulfill, reject) => {
       var xhr;
@@ -87,6 +86,8 @@ class Broker {
     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) {
     var err;
     try {
diff --git a/proxy/proxypair.js b/proxy/proxypair.js
index 52594e9..25eaa9d 100644
--- a/proxy/proxypair.js
+++ b/proxy/proxypair.js
@@ -17,17 +17,13 @@ class ProxyPair {
   - @rateLimit specifies a rate limit on traffic
   */
   constructor(relayAddr, rateLimit, pcConfig) {
-    // Given a WebRTC DataChannel, prepare callbacks.
     this.prepareDataChannel = this.prepareDataChannel.bind(this);
-    // Assumes WebRTC datachannel is connected.
     this.connectRelay = this.connectRelay.bind(this);
-    // WebRTC --> websocket
     this.onClientToRelayMessage = this.onClientToRelayMessage.bind(this);
-    // websocket --> WebRTC
     this.onRelayToClientMessage = this.onRelayToClientMessage.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.relayAddr = relayAddr;
     this.rateLimit = rateLimit;
     this.pcConfig = pcConfig;
@@ -82,6 +78,7 @@ class ProxyPair {
     return true;
   }
 
+  // Given a WebRTC DataChannel, prepare callbacks.
   prepareDataChannel(channel) {
     channel.onopen = () => {
       log('WebRTC DataChannel opened!');
@@ -104,6 +101,7 @@ class ProxyPair {
     return channel.onmessage = this.onClientToRelayMessage;
   }
 
+  // Assumes WebRTC datachannel is connected.
   connectRelay() {
     var params, peer_ip, ref;
     dbg('Connecting to relay...');
@@ -148,12 +146,14 @@ class ProxyPair {
     }), 5000);
   }
 
+  // WebRTC --> websocket
   onClientToRelayMessage(msg) {
     dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes');
     this.c2rSchedule.push(msg.data);
     return this.flush();
   }
 
+  // websocket --> WebRTC
   onRelayToClientMessage(event) {
     dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes');
     this.r2cSchedule.push(event.data);
@@ -185,6 +185,7 @@ class ProxyPair {
     this.onCleanup();
   }
 
+  // Send as much data in both directions as the rate limit currently allows.
   flush() {
     var busy, checkChunks;
     if (this.flush_timeout_id) {
@@ -239,15 +240,10 @@ class ProxyPair {
 ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024;
 
 ProxyPair.prototype.pc = null;
-
 ProxyPair.prototype.client = null; // WebRTC Data channel
-
 ProxyPair.prototype.relay = null; // websocket
 
 ProxyPair.prototype.timer = 0;
-
 ProxyPair.prototype.flush_timeout_id = null;
 
 ProxyPair.prototype.onCleanup = null;
-
-ProxyPair.prototype.id = null;
diff --git a/proxy/snowflake.js b/proxy/snowflake.js
index c914520..ba1ef03 100644
--- a/proxy/snowflake.js
+++ b/proxy/snowflake.js
@@ -16,9 +16,8 @@ class Snowflake {
 
   // Prepare the Snowflake with a Broker (to find clients) and optional UI.
   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.config = config;
     this.ui = ui;
     this.broker = broker;
@@ -85,6 +84,8 @@ class Snowflake {
     return this.retries++;
   }
 
+  // Receive an SDP offer from some client assigned by the Broker,
+  // |pair| - an available ProxyPair.
   receiveOffer(pair, desc) {
     var e, offer, sdp;
     try {
@@ -156,13 +157,9 @@ class Snowflake {
 }
 
 Snowflake.prototype.relayAddr = null;
-
 Snowflake.prototype.rateLimit = null;
-
 Snowflake.prototype.pollInterval = null;
 
-Snowflake.prototype.retries = 0;
-
 Snowflake.MESSAGE = {
   CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'
 };



More information about the tor-commits mailing list