[tor-commits] [flashproxy/master] Support new flashproxy polling.
infinity0 at torproject.org
infinity0 at torproject.org
Mon Oct 28 14:47:40 UTC 2013
commit 1b5028f98f11711d5773c1481729379f00715428
Author: George Kadianakis <desnacked at riseup.net>
Date: Fri Sep 6 17:27:41 2013 +0300
Support new flashproxy polling.
---
facilitator/fac.py | 17 ++++++++++++-----
facilitator/facilitator | 12 +++++++++++-
facilitator/facilitator.cgi | 13 +++++++++++--
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/facilitator/fac.py b/facilitator/fac.py
index c79e415..f6fb43c 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -253,14 +253,21 @@ def put_reg(facilitator_addr, client_addr, transport_chain, registrant_addr=None
f.close()
return command == "OK"
-def get_reg(facilitator_addr, proxy_addr):
- """Get a registration from the facilitator using a one-time socket. Returns
- a dict with keys "client" and "relay" if successful, or a dict with the key
- "client" mapped to the value "" if there are no registrations available for
+def get_reg(facilitator_addr, proxy_addr, transport_list):
+ """
+ Get a client registration for proxy 'proxy_addr' from the
+ facilitator at 'facilitator_addr' using a one-time
+ socket. 'transports' is a list containing the transport names that
+ the flashproxy supports.
+
+ Returns a dict with keys "client-<transport>" and
+ "relay-<transport>" if successful, or a dict with the key "client"
+ 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
try:
- command, params = transact(f, "GET", ("FROM", format_addr(proxy_addr)))
+ command, params = transact(f, "GET", ("FROM", format_addr(proxy_addr)), ("TRANSPORTS", transports))
finally:
f.close()
response = {}
diff --git a/facilitator/facilitator b/facilitator/facilitator
index 3b99346..e3df8c6 100755
--- a/facilitator/facilitator
+++ b/facilitator/facilitator
@@ -270,6 +270,8 @@ class Handler(SocketServer.StreamRequestHandler):
def send_error(self):
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"
def do_GET(self, params):
proxy_spec = fac.param_first("FROM", params)
if proxy_spec is None:
@@ -283,12 +285,20 @@ 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")
+ self.send_error()
+ return False
+ transport_list = transports.split(",") # XXX messy
+
try:
- reg = get_reg_for_proxy(proxy_addr)
+ reg = get_reg_for_proxy(proxy_addr, transport_list)
except Exception, e:
log(u"error getting reg for proxy address %s: %s" % (safe_str(repr(proxy_spec)), safe_str(repr(str(e)))))
self.send_error()
return False
+
check_back_in = get_check_back_in_for_proxy(proxy_addr)
if reg:
log(u"proxy gets %s, num_relays %s (now %d)" %
diff --git a/facilitator/facilitator.cgi b/facilitator/facilitator.cgi
index b20a9ed..f970c51 100755
--- a/facilitator/facilitator.cgi
+++ b/facilitator/facilitator.cgi
@@ -32,7 +32,6 @@ path_info = os.environ.get("PATH_INFO") or "/"
if not method or not remote_addr[0]:
exit_error(400)
-
fs = cgi.FieldStorage()
# Print the HEAD part of a URL-based registration response, or exit with an
@@ -54,6 +53,10 @@ def do_head():
exit_error(400)
def do_get():
+ """Parses flashproxy polls.
+ Example: GET /r=1&client=7.1.43.21&client=1.2.3.4&transports=webrtc,websocket
+ """
+
path_parts = [x for x in path_info.split("/") if x]
if len(path_parts) == 2 and path_parts[0] == "reg":
url_reg(path_parts[1])
@@ -63,8 +66,14 @@ def do_get():
if len(r) != 1 or r[0] != "1":
exit_error(400)
+ # 'transports' (optional) can be repeated and carries
+ # transport names.
+ transport_list = fs.getlist("transports")
+ if transport_list is None:
+ transport_list = ["websocket"]
+
try:
- reg = fac.get_reg(FACILITATOR_ADDR, remote_addr) or ""
+ reg = fac.get_reg(FACILITATOR_ADDR, remote_addr, transport_list) or ""
except Exception:
exit_error(500)
# Allow XMLHttpRequest from any domain. http://www.w3.org/TR/cors/.
More information about the tor-commits
mailing list