commit fb55ab7fe6aec6182217d11999a5818869f539ca Author: George Kadianakis desnacked@riseup.net Date: Wed Sep 18 16:45:48 2013 +0300
Improve client registration parsing.
Don't differentiate between old-style and new-style registrations. --- facilitator/facilitator.cgi | 59 +++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 38 deletions(-)
diff --git a/facilitator/facilitator.cgi b/facilitator/facilitator.cgi index bf2200b..e0dbb3f 100755 --- a/facilitator/facilitator.cgi +++ b/facilitator/facilitator.cgi @@ -95,53 +95,36 @@ def do_post(): # New style client registration: # client-websocket=1.2.3.4:9000&client-obfs3|websocket=1.2.3.4:10000
- is_new_style = True - if path_info != "/": exit_error(400)
- if "client" in fs.keys(): - is_new_style = False - - if is_new_style: - # It's a new style registration. We iterate through the items - # in the POST body, and see if any of them look like - # "client-websocket=1.2.3.4:9000". We then split all those - # items and send them as separate registrations to the - # facilitator. - for key in fs.keys(): - if not key.startswith("client-"): - continue - - # Get the "webssocket" part of "client-webscoket". + # We iterate through the items in the POST body, and see if any of + # them look like "client-websocket=1.2.3.4:9000". We then split + # all those items and send them as separate registrations to the + # facilitator. + for key in fs.keys(): + if key != "client" and not key.startswith("client-"): + continue + + if key == "client": # reg without transport info -- default to websocket. + transport_chain = "websocket" + else: # reg with transport info -- get the "websocket" part out of "client-websocket". transport_chain = key[len("client-"):] - # Get the "1.2.3.4:9000" part of "client-websocket=1.2.3.4:9000". - client_spec = fs[key].value.strip() - try: - client_addr = fac.parse_addr_spec(client_spec, defhost=remote_addr[0]) - except ValueError: - exit_error(400) - - # XXX what if previous registrations passed through - # successfully, but the last one failed and called - # exit_error()? - - # XXX need to link these registrations together, so that - # when one is answerered the rest are invalidated. - if not fac.put_reg(FACILITATOR_ADDR, client_addr, transport_chain, remote_addr): - exit_error(500) - - else: # old-stle registration: - client_specs = fs.getlist("client") - if len(client_specs) != 1: - exit_error(400) - client_spec = client_specs[0].strip() + + # Get the "1.2.3.4:9000" part of "client-websocket=1.2.3.4:9000". + client_spec = fs[key].value.strip() try: client_addr = fac.parse_addr_spec(client_spec, defhost=remote_addr[0]) except ValueError: exit_error(400)
- if not fac.put_reg(FACILITATOR_ADDR, client_addr, "websocket", remote_addr): + # XXX what if previous registrations passed through + # successfully, but the last one failed and called + # exit_error()? + + # XXX need to link these registrations together, so that + # when one is answerered the rest are invalidated. + if not fac.put_reg(FACILITATOR_ADDR, client_addr, transport_chain, remote_addr): exit_error(500)
print """\
tor-commits@lists.torproject.org