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

[tor-commits] [flashproxy/master] Use "transports" for a transport chain tuple everywhere.



commit 1dc3f414da9bc44a69f5767bca6aece70c00fc0a
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Fri Sep 20 22:37:06 2013 -0700

    Use "transports" for a transport chain tuple everywhere.
---
 facilitator/facilitator |   51 +++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/facilitator/facilitator b/facilitator/facilitator
index 1e708d4..55304ec 100755
--- a/facilitator/facilitator
+++ b/facilitator/facilitator
@@ -87,12 +87,12 @@ def parse_transport_chain(transport_chain):
     # be manipulated so it should be cool.
     return tuple(transport_chain.split("|"))
 
-def get_outermost_transport(transport_chain):
+def get_outermost_transport(transports):
     """Given a combined transport name in 'transport', return the name of the
     outermost transport. e.g. if 'transport' is (obfs3, websocket) this function
     returns 'websocket'"""
-    assert(transport_chain)
-    return transport_chain[-1]
+    assert(transports)
+    return transports[-1]
 
 def safe_str(s):
     """Return "[scrubbed]" if options.safe_logging is true, and s otherwise."""
@@ -111,11 +111,11 @@ def log(msg):
         log_lock.release()
 
 class TCPReg(object):
-    def __init__(self, host, port, transport_chain):
-        """transport_chain: transport chain list. e.g. (obfs3, websocket)"""
+    def __init__(self, host, port, transports):
+        """transports: transport chain list. e.g. (obfs3, websocket)"""
         self.host = host
         self.port = port
-        self.transport_chain = transport_chain
+        self.transports = transports
         # Get a relay for this registration. Throw UnknownTransport if
         # could not be found.
         self.relay = self._get_matching_relay()
@@ -124,15 +124,15 @@ class TCPReg(object):
         """Return a matching relay addrspec for this registration. Raise
         UnknownTransport if a relay with a matching transport chain could not be
         found."""
-        if self.transport_chain not in options.relays:
-            raise UnknownTransport("Can't find relay with transport chain: %s" % self.transport_chain)
+        if self.transports not in options.relays:
+            raise UnknownTransport("Can't find relay with transport chain: %s" % self.transports)
 
         # Maybe this should be a random pick from the set of all the
         # eligible relays. But let's keep it deterministic for now,
         # and return the first one.
 
-        # return random.choice(options.relays[self.transport_chain])
-        return options.relays[self.transport_chain][0]
+        # return random.choice(options.relays[self.transports])
+        return options.relays[self.transports][0]
 
     def __unicode__(self):
         return fac.format_addr((self.host, self.port))
@@ -143,15 +143,15 @@ class TCPReg(object):
     def __cmp__(self, other):
         if isinstance(other, TCPReg):
             # XXX is this correct comparison?
-            return cmp((self.host, self.port, self.transport_chain), (other.host, other.port, other.transport_chain))
+            return cmp((self.host, self.port, self.transports), (other.host, other.port, other.transports))
         else:
             return False
 
 class Reg(object):
     @staticmethod
-    def parse(spec, transport_chain, defhost = None, defport = None):
+    def parse(spec, transports, defhost = None, defport = None):
         host, port = fac.parse_addr_spec(spec, defhost, defport)
-        return TCPReg(host, port, transport_chain)
+        return TCPReg(host, port, transports)
 
 class RegSet(object):
     def __init__(self):
@@ -303,8 +303,8 @@ class Handler(SocketServer.StreamRequestHandler):
         check_back_in = get_check_back_in_for_proxy(proxy_addr)
 
         if reg:
-            log(u"proxy (%s) gets client '%s' (transport_chain: %s) (num relays: %s) (remaining regs: %d/%d)" %
-                (safe_str(repr(proxy_spec)), safe_str(unicode(reg)), reg.transport_chain, options.num_relays(), num_unhandled_regs(), num_regs()))
+            log(u"proxy (%s) gets client '%s' (transports: %s) (num relays: %s) (remaining regs: %d/%d)" %
+                (safe_str(repr(proxy_spec)), safe_str(unicode(reg)), reg.transports, options.num_relays(), num_unhandled_regs(), num_regs()))
             print >> self.wfile, fac.render_transaction("OK", ("CLIENT", str(reg)), ("RELAY", reg.relay), ("CHECK-BACK-IN", str(check_back_in)))
         else:
             log(u"proxy (%s) gets none" % safe_str(repr(proxy_spec)))
@@ -316,23 +316,22 @@ class Handler(SocketServer.StreamRequestHandler):
     # Example: PUT CLIENT="1.1.1.1:5555" FROM="1.1.1.2:6666" TRANSPORT_CHAIN="obfs3|websocket"
     def do_PUT(self, params):
         # Check out if we recognize the transport chain in this registration request
-        transport_chain = fac.param_first("TRANSPORT_CHAIN", params)
-        if transport_chain is None:
+        transports_spec = fac.param_first("TRANSPORT_CHAIN", params)
+        if transports_spec is None:
             log(u"PUT missing TRANSPORT_CHAIN param")
             self.send_error()
             return False
 
-        # Turn the transport chain to tuple-form.
-        transport_chain = parse_transport_chain(transport_chain)
+        transports = parse_transport_chain(transports_spec)
 
         # See if we have relays that support this transport chain
-        if transport_chain not in options.relays:
-            log(u"Unrecognized transport chain: %s" % transport_chain)
+        if transports not in options.relays:
+            log(u"Unrecognized transport chain: %s" % transports)
             self.send_error() # XXX can we tell the flashproxy client of this error?
             return False
         # if we have relays that support this transport chain, we
         # certainly have a regset for its outermost transport too.
-        assert(get_outermost_transport(transport_chain) in REGSETS_IPV4)
+        assert(get_outermost_transport(transports) in REGSETS_IPV4)
 
         client_spec = fac.param_first("CLIENT", params)
         if client_spec is None:
@@ -341,7 +340,7 @@ class Handler(SocketServer.StreamRequestHandler):
             return False
 
         try:
-            reg = Reg.parse(client_spec, transport_chain)
+            reg = Reg.parse(client_spec, transports)
         except (UnknownTransport, ValueError) as e:
             # XXX should we throw a better error message to the client? Is it possible?
             log(u"syntax error in %s: %s" % (safe_str(repr(client_spec)), safe_str(repr(str(e)))))
@@ -356,9 +355,9 @@ class Handler(SocketServer.StreamRequestHandler):
             return False
 
         if ok:
-            log(u"client %s (transports: %s) (remaining regs: %d/%d)" % (safe_str(unicode(reg)), reg.transport_chain, num_unhandled_regs(), num_regs()))
+            log(u"client %s (transports: %s) (remaining regs: %d/%d)" % (safe_str(unicode(reg)), reg.transports, num_unhandled_regs(), num_regs()))
         else:
-            log(u"client %s (already present) (transports: %s) (remaining regs: %d/%d)" % (safe_str(unicode(reg)), reg.transport_chain, num_unhandled_regs(), num_regs()))
+            log(u"client %s (already present) (transports: %s) (remaining regs: %d/%d)" % (safe_str(unicode(reg)), reg.transports, num_unhandled_regs(), num_regs()))
 
         self.send_ok()
         return True
@@ -447,7 +446,7 @@ def put_reg(reg):
     """Add a registration."""
     addr_str = reg.host
     af = addr_af(addr_str)
-    REGS = get_regs(af, get_outermost_transport(reg.transport_chain))
+    REGS = get_regs(af, get_outermost_transport(reg.transports))
     return REGS.add(reg)
 
 def handle_relay_file(fname):



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