[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[flashproxy/master] Rename proxy_addr → remote_addr because it could be a proxy or a client.
commit fe80b0fd55a2a5a0c091edb6aadf61595a144667
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Wed Dec 19 18:31:17 2012 -0800
Rename proxy_addr â?? remote_addr because it could be a proxy or a client.
---
facilitator/facilitator | 29 +++++++++++++++++++++++++++--
facilitator/facilitator.cgi | 10 +++++-----
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/facilitator/facilitator b/facilitator/facilitator
index af2c04c..bc47281 100755
--- a/facilitator/facilitator
+++ b/facilitator/facilitator
@@ -234,7 +234,30 @@ class Handler(SocketServer.StreamRequestHandler):
print >> self.wfile, "ERROR"
def do_GET(self, params):
- reg = REGS.fetch()
+ # Get the proxy's address so we know what kind of client to give it
+ # (IPv4 or IPv6).
+ proxy_spec = fac.param_first("FROM", params)
+ if proxy_spec is None:
+ log(u"GET missing FROM param")
+ self.send_error()
+ return False
+ try:
+ _, _, af = fac.parse_addr_spec_af(proxy_spec, defport=0)
+ except ValueError, e:
+ log(u"syntax error in proxy address %s: %s" % (safe_str(repr(proxy_spec)), safe_str(repr(str(e)))))
+ self.send_error()
+ return False
+
+ if af == socket.AF_INET:
+ regs = REGS_IPV4
+ elif af == socket.AF_INET6:
+ regs = REGS_IPV6
+ else:
+ log(u"unknown address family %d in proxy address %s" % (af, safe_str(repr(proxy_spec))))
+ self.send_error()
+ return False
+
+ reg = regs.fetch()
if reg:
log(u"proxy gets %s, relay %s (now %d)" %
(safe_str(unicode(reg)), options.relay_spec, len(REGS)))
@@ -273,7 +296,9 @@ class Handler(SocketServer.StreamRequestHandler):
class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
allow_reuse_address = True
-REGS = RegSet()
+# Separate pools for IPv4 and IPv6 clients.
+REGS_IPV4 = RegSet()
+REGS_IPV6 = RegSet()
def main():
opts, args = getopt.gnu_getopt(sys.argv[1:], "dhl:p:r:",
diff --git a/facilitator/facilitator.cgi b/facilitator/facilitator.cgi
index f35c9a3..c21e67d 100755
--- a/facilitator/facilitator.cgi
+++ b/facilitator/facilitator.cgi
@@ -17,10 +17,10 @@ Status: %d\r
sys.exit()
method = os.environ.get("REQUEST_METHOD")
-proxy_addr = (os.environ.get("REMOTE_ADDR"), None)
+remote_addr = (os.environ.get("REMOTE_ADDR"), None)
path_info = os.environ.get("PATH_INFO") or "/"
-if not method or not proxy_addr[0]:
+if not method or not remote_addr[0]:
exit_error(400)
fs = cgi.FieldStorage()
@@ -29,7 +29,7 @@ def do_get():
if path_info != "/":
exit_error(400)
try:
- reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr) or ""
+ reg = fac.get_reg(FACILITATOR_ADDR, remote_addr) or ""
except:
exit_error(500)
# Allow XMLHttpRequest from any domain. http://www.w3.org/TR/cors/.
@@ -49,10 +49,10 @@ def do_post():
exit_error(400)
client_spec = client_specs[0].strip()
try:
- client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
+ 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, proxy_addr):
+ if not fac.put_reg(FACILITATOR_ADDR, client_addr, remote_addr):
exit_error(500)
print """\
Status: 200\r
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits