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

[tor-commits] [flashproxy/master] Update TCPReg to support transports.



commit e69f0ca9090920a7af72b5ac6fdd26e97f426393
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Fri Sep 6 17:24:02 2013 +0300

    Update TCPReg to support transports.
---
 facilitator/facilitator |   30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/facilitator/facilitator b/facilitator/facilitator
index 8d3f835..7b1c51a 100755
--- a/facilitator/facilitator
+++ b/facilitator/facilitator
@@ -107,9 +107,30 @@ def log(msg):
         log_lock.release()
 
 class TCPReg(object):
-    def __init__(self, host, port):
+    def __init__(self, host, port, transport_chain):
         self.host = host
         self.port = port
+        self.transport_chain = transport_chain
+        # Get a relay for this registration. Throw UnknownTransport if
+        # could not be found.
+        self.relay = self._get_matching_relay()
+
+    def _get_matching_relay(self):
+        """
+        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)
+
+        # 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]
 
     def __unicode__(self):
         return fac.format_addr((self.host, self.port))
@@ -119,15 +140,16 @@ class TCPReg(object):
 
     def __cmp__(self, other):
         if isinstance(other, TCPReg):
-            return cmp((self.host, self.port), (other.host, other.port))
+            # XXX is this correct comparison?
+            return cmp((self.host, self.port, self.transport_chain), (other.host, other.port, other.transport_chain))
         else:
             return False
 
 class Reg(object):
     @staticmethod
-    def parse(spec, defhost = None, defport = None):
+    def parse(spec, transport_chain, defhost = None, defport = None):
         host, port = fac.parse_addr_spec(spec, defhost, defport)
-        return TCPReg(host, port)
+        return TCPReg(host, port, transport_chain)
 
 class RegSet(object):
     def __init__(self):



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