[tor-commits] [flashproxy/js] Make a callback for when a proxy pair is complete.

dcf at torproject.org dcf at torproject.org
Fri Mar 30 08:13:35 UTC 2012


commit a32498f29d9363bf8107a0f02d5c22a60865c3e7
Author: David Fifield <david at bamsoftware.com>
Date:   Fri Mar 30 01:08:25 2012 -0700

    Make a callback for when a proxy pair is complete.
---
 flashproxy.js |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/flashproxy.js b/flashproxy.js
index 59bf103..1f9bc00 100644
--- a/flashproxy.js
+++ b/flashproxy.js
@@ -235,6 +235,11 @@ function FlashProxy()
 
         proxy_pair = new ProxyPair(client_addr, relay_addr);
         this.proxy_pairs.push(proxy_pair);
+        proxy_pair.complete_callback = function(event) {
+            puts("Complete.");
+            /* Delete from the list of active proxy pairs. */
+            this.proxy_pairs.splice(this.proxy_pairs.indexOf(proxy_pair), 1);
+        }.bind(this);
         proxy_pair.connect();
     };
 
@@ -254,6 +259,10 @@ function FlashProxy()
 
         this.flush_timeout_id = null;
 
+        /* This callback function can be overridden by external callers. */
+        this.complete_callback = function() {
+        };
+
         /* Return a function that shows an error message and closes the other
            half of a communication pair. */
         this.make_onerror_callback = function(partner)
@@ -263,8 +272,7 @@ function FlashProxy()
 
                 log(ws.label + ": error.");
                 partner.close();
-                // dispatchEvent(new Event(Event.COMPLETE));
-            };
+            }.bind(this);
         };
 
         this.onopen_callback = function(event) {
@@ -278,6 +286,9 @@ function FlashProxy()
 
             log(ws.label + ": closed.");
             this.flush();
+
+            if (is_closed(this.client_s) && is_closed(this.relay_s))
+                this.complete_callback();
         }.bind(this);
 
         this.onmessage_client_to_relay = function(event) {
@@ -350,10 +361,7 @@ function FlashProxy()
                 this.relay_s.close();
             }
 
-            if (is_closed(this.client_s) && is_closed(this.relay_s))
-                // dispatchEvent(new Event(Event.COMPLETE));
-                ;
-            else if (this.r2c_schedule.length > 0 || this.c2r_schedule.length > 0)
+            if (this.r2c_schedule.length > 0 || this.c2r_schedule.length > 0)
                 this.flush_timeout_id = setTimeout(this.flush, rate_limit.when() * 1000);
         };
     }



More information about the tor-commits mailing list