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

[tor-commits] [sbws/master] chg: circuitbuilder: Simplify building circuit



commit b3ab8ebf9209f4e396f42e254afcca58fefc1e58
Author: juga0 <juga@xxxxxxxxxx>
Date:   Tue Dec 8 15:43:23 2020 +0000

    chg: circuitbuilder: Simplify building circuit
    
    Since sbws is only building 2 hop paths, there is no need to add random
    relays to the path, or convert back and forth between fingerprint and
    ``Relay`` objects.
    
    This will eliminate the circuit errors:
    - Tor seems to no longer think XXX is a relay
    - Can not build a circuit, no path.
    - Can not build a circuit with the current relays.
    If a relay is not longer running when attempting to build the circuit,
    it will probably fail with one of the other circuit errors: TIMEOUT,
    DESTROYED or CHANNEL_CLOSED.
    
    Closes: #40027
---
 sbws/lib/circuitbuilder.py | 62 ++++++----------------------------------------
 1 file changed, 8 insertions(+), 54 deletions(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index 45b807f..fb23737 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -91,62 +91,16 @@ class CircuitBuilder:
 # build the circuit, the relays are not just choosen as random as this class
 # does.
 class GapsCircuitBuilder(CircuitBuilder):
-    ''' The build_circuit member function takes a list. Falsey values in the
-    list will be replaced with relays chosen uniformally at random; Truthy
-    values will be assumed to be relays. '''
+    """Same as ``CircuitBuilder`` but implements build_circuit."""
     def __init__(self, *a, **kw):
         super().__init__(*a, **kw)
 
-    def _normalize_path(self, path):
-        ''' Change fingerprints/nicks to relay descriptor and change Falsey
-        values to None. Return the new path, or None if error '''
-        new_path = []
-        for fp in path:
-            if not fp:
-                new_path.append(None)
-                continue
-            relay = Relay(fp, self.controller)
-            if not relay.fingerprint:
-                log.debug('Tor seems to no longer think %s is a relay', fp)
-                return None
-            new_path.append(relay)
-        return new_path
-
-    def _random_sample_relays(self, number, blacklist):
-        ''' Get <number> random relays from self.relays that are not in the
-        blacklist. Return None if it cannot be done because too many are
-        blacklisted. Otherwise return a list of relays. '''
-        all_fps = [r.fingerprint for r in self.relays]
-        black_fps = [r.fingerprint for r in blacklist]
-        if len(black_fps) + number > len(all_fps):
-            return None
-        chosen_fps = []
-        while len(chosen_fps) < number:
-            choice = self.rng.choice(all_fps)
-            if choice in black_fps:
-                continue
-            chosen_fps.append(choice)
-            black_fps.append(choice)
-        return [Relay(fp, self.controller) for fp in chosen_fps]
-
     def build_circuit(self, path):
-        ''' <path> is a list of relays and Falsey values. Relays can be
-        specified by fingerprint or nickname, and fingerprint is highly
-        recommended. Falsey values (like None) will be replaced with relays
-        chosen uniformally at random. A relay will not be in a circuit twice.
-        '''
-        if not valid_circuit_length(path):
-            return None, "Can not build a circuit, invalid path."
-        path = self._normalize_path(path)
-        if path is None:
-            return None, "Can not build a circuit, no path."
-        num_missing = len(['foo' for r in path if not r])
-        insert_relays = self._random_sample_relays(
-            num_missing, [r for r in path if r is not None])
-        if insert_relays is None:
-            path = ','.join([r.nickname if r else str(None) for r in path])
-            return None, "Can not build a circuit with the current relays."
-        assert len(insert_relays) == num_missing
-        path = [r.fingerprint if r else insert_relays.pop().fingerprint
-                for r in path]
+        """Return parent class build circuit method.
+
+        Since sbws is only building 2 hop paths, there is no need to add random
+        relays to the path, or convert back and forth between fingerprint and
+        ``Relay`` objects.
+
+        """
         return self._build_circuit_impl(path)



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