[tor-commits] [flashproxy/master] Make flashproxy-reg-http take a URL, not a (host, port) pair.

dcf at torproject.org dcf at torproject.org
Sun Sep 23 15:53:25 UTC 2012


commit a13a96297ca07e7c49d5a79e9173ce1e887f4fb9
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Sep 23 00:58:26 2012 -0700

    Make flashproxy-reg-http take a URL, not a (host, port) pair.
---
 flashproxy-client   |   23 +++++++++++------------
 flashproxy-reg-http |   32 +++++++++++++++++---------------
 2 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/flashproxy-client b/flashproxy-client
index 6f7477e..226be6d 100755
--- a/flashproxy-client
+++ b/flashproxy-client
@@ -39,7 +39,7 @@ LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
 class options(object):
     local_addr = None
     remote_addr = None
-    facilitator_addr = None
+    facilitator_url = None
 
     log_filename = None
     log_file = sys.stdout
@@ -67,14 +67,13 @@ If the --register option is used, then your IP address will be sent to the
 facilitator so that proxies can connect to you. You need to register in some way
 in order to get any service. The --facilitator option allows controlling which
 facilitator is used; if omitted, it uses a public default.
-  --daemon                       daemonize (Unix only).
-  -f, --facilitator=HOST[:PORT]  advertise willingness to receive connections to
-                                   HOST:PORT.
-  -h, --help                     show this help.
-  -l, --log FILENAME             write log to FILENAME (default stdout).
-      --pidfile FILENAME         write PID to FILENAME after daemonizing.
-  -r, --register                 register with the facilitator.
-  --unsafe-logging               don't scrub IP addresses from logs.\
+  --daemon                daemonize (Unix only).
+  -f, --facilitator=URL   advertise willingness to receive connections to URL.
+  -h, --help              show this help.
+  -l, --log FILENAME      write log to FILENAME (default stdout).
+      --pidfile FILENAME  write PID to FILENAME after daemonizing.
+  -r, --register          register with the facilitator.
+  --unsafe-logging        don't scrub IP addresses from logs.\
 """ % {
     "progname": sys.argv[0],
     "local": format_addr((DEFAULT_LOCAL_ADDRESS, DEFAULT_LOCAL_PORT)),
@@ -633,10 +632,10 @@ def register():
         return
     command = [os.path.join(script_dir, "flashproxy-reg-http")]
     spec = format_addr(options.remote_addr)
-    if options.facilitator_addr is None:
+    if options.facilitator_url is None:
         log(u"Registering \"%s\"." % spec)
     else:
-        command += ["-f", format_addr(options.facilitator_addr)]
+        command += ["-f", options.facilitator_url]
     command += [spec]
     try:
         p = subprocess.Popen(command)
@@ -861,7 +860,7 @@ if __name__ == "__main__":
         if o == "--daemon":
             options.daemonize = True
         elif o == "-f" or o == "--facilitator":
-            options.facilitator_addr = parse_addr_spec(a)
+            options.facilitator_url = a
         elif o == "-h" or o == "--help":
             usage()
             sys.exit()
diff --git a/flashproxy-reg-http b/flashproxy-reg-http
index 4372c1f..d137827 100755
--- a/flashproxy-reg-http
+++ b/flashproxy-reg-http
@@ -6,15 +6,15 @@ import re
 import socket
 import sys
 import urllib
+import urllib2
 
 DEFAULT_REMOTE_ADDRESS = ""
 DEFAULT_REMOTE_PORT = 9000
-DEFAULT_FACILITATOR_HOST = "tor-facilitator.bamsoftware.com"
-DEFAULT_FACILITATOR_PORT = 443
+DEFAULT_FACILITATOR_URL = "https://tor-facilitator.bamsoftware.com/"
 
 class options(object):
     remote_addr = None
-    facilitator_addr = None
+    facilitator_url = None
 
 def usage(f = sys.stdout):
     print >> f, """\
@@ -22,12 +22,12 @@ Usage: %(progname)s [REMOTE][:PORT]
 Register with a flash proxy facilitator using an HTTP POST. By default the
 remote address registered is "%(remote_addr)s".
 
-  -f, --facilitator=HOST[:PORT]  register with the given facilitator (by
-                                   default "%(fac_addr)s".)
-  -h, --help                     show this help. \
+  -f, --facilitator=URL  register with the given facilitator
+                           (by default "%(fac_url)s").
+  -h, --help             show this help. \
 """ % {
     "progname": sys.argv[0],
-    "fac_addr": format_addr((DEFAULT_FACILITATOR_HOST, DEFAULT_FACILITATOR_PORT)),
+    "fac_url": DEFAULT_FACILITATOR_URL,
     "remote_addr": format_addr((DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT)),
 }
 
@@ -81,13 +81,13 @@ def format_addr(addr):
         result += u":%d" % port
     return result
 
-options.facilitator_addr = (DEFAULT_FACILITATOR_HOST, DEFAULT_FACILITATOR_PORT)
+options.facilitator_url = DEFAULT_FACILITATOR_URL
 options.remote_addr = (DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT)
 
 opts, args = getopt.gnu_getopt(sys.argv[1:], "f:h", ["facilitator=", "help"])
 for o, a in opts:
     if o == "-f" or o == "--facilitator":
-        options.facilitator_addr = parse_addr_spec(a, DEFAULT_FACILITATOR_HOST, DEFAULT_FACILITATOR_PORT)
+        options.facilitator_url = a
     elif o == "-h" or o == "--help":
         usage()
         sys.exit()
@@ -101,15 +101,17 @@ else:
     sys.exit(1)
 
 spec = format_addr(options.remote_addr)
-http = httplib.HTTPSConnection(*options.facilitator_addr)
 try:
-    http.request("POST", "/", urllib.urlencode({"client": spec}))
-    resp = http.getresponse()
-    if resp.status != 200:
-        raise ValueError("Status code was %d, not 200" % resp.status)
+    http = urllib2.urlopen(options.facilitator_url, urllib.urlencode({"client": spec}), 10)
+except urllib2.HTTPError, e:
+    print >> sys.stderr, "Status code was %d, not 200" % e.code
+    sys.exit(1)
+except urllib2.URLError, e:
+    print >> sys.stderr, "Failed to register: %s" % str(e.reason)
+    sys.exit(1)
 except Exception, e:
     print >> sys.stderr, "Failed to register: %s" % str(e)
     sys.exit(1)
 http.close()
 
-print "Registered \"%s\" with %s." % (spec, format_addr(options.facilitator_addr))
+print "Registered \"%s\" with %s." % (spec, options.facilitator_url)



More information about the tor-commits mailing list