[tor-commits] [flashproxy/master] remove failed connections from proxy_pairs as well

infinity0 at torproject.org infinity0 at torproject.org
Fri Mar 7 14:39:18 UTC 2014


commit 05b9c101ba9afe4653d1eff6f5414f90f22ef042
Author: Ximin Luo <infinity0 at torproject.org>
Date:   Fri Mar 7 13:39:31 2014 +0000

    remove failed connections from proxy_pairs as well
    - this is a pretty major fix, as the previous behaviour effectively disabled a proxy after 5 failed connections (= max_num_proxy_pairs / 2)
---
 proxy/flashproxy.js |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
index 0ce3495..5367dc6 100644
--- a/proxy/flashproxy.js
+++ b/proxy/flashproxy.js
@@ -670,8 +670,7 @@ function FlashProxy() {
 
         proxy_pair = new ProxyPair(client_addr, relay_addr, this.rate_limit);
         this.proxy_pairs.push(proxy_pair);
-        proxy_pair.complete_callback = function(event) {
-            puts("Complete.");
+        proxy_pair.cleanup_callback = function(event) {
             /* Delete from the list of active proxy pairs. */
             this.proxy_pairs.splice(this.proxy_pairs.indexOf(proxy_pair), 1);
             if (this.badge)
@@ -730,7 +729,7 @@ function ProxyPair(client_addr, relay_addr, rate_limit) {
     this.flush_timeout_id = null;
 
     /* This callback function can be overridden by external callers. */
-    this.complete_callback = function() {
+    this.cleanup_callback = function() {
     };
 
     this.connect = function() {
@@ -766,15 +765,23 @@ function ProxyPair(client_addr, relay_addr, rate_limit) {
         log(ws.label + ": connected.");
     }.bind(this);
 
+    this.maybe_cleanup = function() {
+        if (this.running && is_closed(this.client_s) && is_closed(this.relay_s)) {
+            this.running = false;
+            this.cleanup_callback();
+            return true;
+        }
+        return false;
+    }
+
     this.onclose_callback = function(event) {
         var ws = event.target;
 
         log(ws.label + ": closed.");
         this.flush();
 
-        if (this.running && is_closed(this.client_s) && is_closed(this.relay_s)) {
-            this.running = false;
-            this.complete_callback();
+        if (this.maybe_cleanup()) {
+            puts("Complete.");
         }
     }.bind(this);
 
@@ -783,6 +790,11 @@ function ProxyPair(client_addr, relay_addr, rate_limit) {
 
         log(ws.label + ": error.");
         this.close();
+
+        // we can't rely on onclose_callback to cleanup, since one common error
+        // case is when the client fails to connect and the relay never starts.
+        // in that case close() is a NOP and onclose_callback is never called.
+        this.maybe_cleanup();
     }.bind(this);
 
     this.onmessage_client_to_relay = function(event) {





More information about the tor-commits mailing list