[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [flashproxy/master] Poll the facilitator in a loop.



commit 7fd20939a00ec521f31821305199fd6708b3a39d
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sat Mar 31 15:44:47 2012 -0700

    Poll the facilitator in a loop.
---
 flashproxy.js |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/flashproxy.js b/flashproxy.js
index 4a758f9..7e0217e 100644
--- a/flashproxy.js
+++ b/flashproxy.js
@@ -217,12 +217,11 @@ function FlashProxy()
     this.proxy_pairs = [];
 
     this.start = function() {
-        var fac_addr;
         var client_addr;
         var relay_addr;
 
-        fac_addr = get_query_param_addr(this.query, "facilitator", DEFAULT_FACILITATOR_ADDR);
-        if (!fac_addr) {
+        this.fac_addr = get_query_param_addr(this.query, "facilitator", DEFAULT_FACILITATOR_ADDR);
+        if (!this.fac_addr) {
             puts("Error: Facilitator spec must be in the form \"host:port\".");
             return;
         }
@@ -250,18 +249,21 @@ function FlashProxy()
             puts("Error: the \"relay\" parameter requires \"client\" also.")
             return;
         } else {
-            this.proxy_main(fac_addr);
+            this.proxy_main();
         }
     };
 
-    this.proxy_main = function(fac_addr) {
+    this.proxy_main = function() {
         var fac_url;
         var xhr;
 
-        puts("Using facilitator " + format_addr(fac_addr) + ".");
+        if (this.proxy_pairs.length >= this.max_num_proxy_pairs) {
+            setTimeout(this.proxy_main.bind(this), this.facilitator_poll_interval);
+            return;
+        }
 
-        fac_url = "http://"; + encodeURIComponent(fac_addr.host)
-            + ":" + encodeURIComponent(fac_addr.port) + "/";
+        fac_url = "http://"; + encodeURIComponent(this.fac_addr.host)
+            + ":" + encodeURIComponent(this.fac_addr.port) + "/";
         xhr = new XMLHttpRequest();
         try {
             xhr.open("GET", fac_url);
@@ -294,6 +296,8 @@ function FlashProxy()
         var client_addr;
         var relay_addr;
 
+        setTimeout(this.proxy_main.bind(this), this.facilitator_poll_interval * 1000);
+
         response = parse_query_string(text);
 
         if (!response.client) {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits