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

[tor-commits] [flashproxy/master] GET command: Do "TRANSPORT=obfs2 TRANPSORT=obfs3" instead of "TRASPORTS=obfs2, obfs3".



commit 33e513526cc8541afb9345e14c2c9a0abf9ffcfb
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Thu Sep 19 13:27:08 2013 +0300

    GET command: Do "TRANSPORT=obfs2 TRANPSORT=obfs3" instead of "TRASPORTS=obfs2,obfs3".
---
 facilitator/fac.py      |   23 +++++++++++++++++++++--
 facilitator/facilitator |    9 ++++-----
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/facilitator/fac.py b/facilitator/fac.py
index f6fb43c..5e1737a 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -206,11 +206,22 @@ def parse_transaction(line):
     return command, tuple(pairs)
 
 def param_first(key, params):
+    """Search 'params' for 'key' and return the first value that
+    occurs. If 'key' was not found, return None."""
     for k, v in params:
         if key == k:
             return v
     return None
 
+def param_getlist(key, params):
+    """Search 'params' for 'key' and return a list with its values. If
+    'key' did not appear in 'params', return the empty list."""
+    result = []
+    for k, v in params:
+        if key == k:
+            result.append(v)
+    return result
+
 def quote_string(s):
     chars = []
     for c in s:
@@ -265,9 +276,17 @@ def get_reg(facilitator_addr, proxy_addr, transport_list):
     mapped to the value "" if there are no registrations available for
     proxy_addr. Raises an exception otherwise."""
     f = fac_socket(facilitator_addr)
-    transports = ",".join(transport_list) # xxx wtf
+
+    # Form a list (in transact() format) with the transports that we
+    # should send to the facilitator.  Then pass that list to the
+    # transact() function.
+    # For example, TRANSPORT=obfs2 TRANSPORT=obfs3.
+    transports = []
+    for transport in transport_list:
+        transports += ("TRANSPORT", transport)
+
     try:
-        command, params = transact(f, "GET", ("FROM", format_addr(proxy_addr)), ("TRANSPORTS", transports))
+        command, params = transact(f, "GET", ("FROM", format_addr(proxy_addr)), transports)
     finally:
         f.close()
     response = {}
diff --git a/facilitator/facilitator b/facilitator/facilitator
index e7e0325..d674769 100755
--- a/facilitator/facilitator
+++ b/facilitator/facilitator
@@ -274,7 +274,7 @@ class Handler(SocketServer.StreamRequestHandler):
         print >> self.wfile, "ERROR"
 
     # Handle a GET request (got flashproxy poll; need to return a proper client registration)
-    # Example: GET FROM="3.3.3.3:3333" TRANSPORTS="websocket,webrtc"
+    # Example: GET FROM="3.3.3.3:3333" TRANSPORT="websocket" TRANSPORT="webrtc"
     def do_GET(self, params):
         proxy_spec = fac.param_first("FROM", params)
         if proxy_spec is None:
@@ -288,12 +288,11 @@ class Handler(SocketServer.StreamRequestHandler):
             self.send_error()
             return False
 
-        transports = fac.param_first("TRANSPORTS", params)
-        if transports is None:
-            log(u"TRANSPORTS missing FROM param")
+        transport_list = fac.param_getlist("TRANSPORT", params)
+        if not transport_list:
+            log(u"TRANSPORT missing FROM param")
             self.send_error()
             return False
-        transport_list = transports.split(",") # XXX messy
 
         try:
             reg = get_reg_for_proxy(proxy_addr, transport_list)



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