def dumpAssignments(self, f, description=""): logging.info("Dumping bridge assignments for %s..." % self.name) for b in self.bridges.itervalues(): desc = [ description ] ident = b.getID() for tp,val,_,subring in self.subrings: if subring.getBridgeByID(ident): desc.append("%s=%s"%(tp,val)) f.write("%s %s\n"%( toHex(ident), " ".join(desc).strip()))
def dumpAssignments(self, f, description=""): logging.info("Dumping bridge assignments for %s..." % self.name) for b in self.bridges.itervalues(): desc = [description] ident = b.getID() for tp, val, _, subring in self.subrings: if subring.getBridgeByID(ident): desc.append("%s=%s" % (tp, val)) f.write("%s %s\n" % (toHex(ident), " ".join(desc).strip()))
def filterDistinctSubnets(self, fingerprints): """Given a chosen set of ``fingerprints`` of bridges to distribute, filter the bridges such that they are in distinct subnets. """ logging.debug("Got %d possible bridges to filter" % len(fingerprints)) bridges = [] subnets = [] for fingerprint in fingerprints: bridge = self.bridges[fingerprint] jump = False # HOTFIX for https://bugs.torproject.org/26150 if not bridge.address: logging.error( "Got strange bridge with no address field set: %s" % toHex(fingerprint)) continue for subnet in subnets: if bridge.address in subnet: jump = True logging.debug(( "Skipping distribution of bridge %s in a subnet which " "contains another bridge we're already distributing") % bridge) break if jump: continue bridges.append(bridge) if bridge.address.version == 4: cidr = str(bridge.address) + "/16" else: cidr = str(bridge.address) + "/32" subnets.append(ipaddr.IPNetwork(cidr)) return bridges
def filterDistinctSubnets(self, fingerprints): """Given a chosen set of ``fingerprints`` of bridges to distribute, filter the bridges such that they are in distinct subnets. """ logging.debug("Got %d possible bridges to filter" % len(fingerprints)) bridges = [] subnets = [] for fingerprint in fingerprints: bridge = self.bridges[fingerprint] jump = False # HOTFIX for https://bugs.torproject.org/26150 if not bridge.address: logging.error("Got strange bridge with no address field set: %s" % toHex(fingerprint)) continue for subnet in subnets: if bridge.address in subnet: jump = True logging.debug( ("Skipping distribution of bridge %s in a subnet which " "contains another bridge we're already distributing") % bridge) break if jump: continue bridges.append(bridge) if bridge.address.version == 4: cidr = str(bridge.address) + "/16" else: cidr = str(bridge.address) + "/32" subnets.append(ipaddr.IPNetwork(cidr)) return bridges
def dumpAssignments(self, f, description=""): # one ring per filter set # bridges may be present in multiple filter sets # only one line should be dumped per bridge for b in self.bridges: # gather all the filter descriptions desc = [] for n,(g,r) in self.filterRings.items(): if g(b): # ghetto. get subring flags, ports for tp,val,_,subring in r.subrings: if subring.getBridgeByID(b.getID()): desc.append("%s=%s"%(tp,val)) try: desc.extend(g.description.split()) except TypeError: desc.append(g.description) # add transports logging.debug("%s supports %d transports" % (b, len(b.transports))) for transport in b.transports: desc.append("transport=%s"%(transport.methodname)) # dedupe and group desc = set(desc) grouped = dict() for kw in desc: l,r = kw.split('=') try: grouped[l] = "%s,%s"%(grouped[l],r) except KeyError: grouped[l] = kw # add to assignments desc = "%s %s" % (description.strip(), " ".join([v for k,v in grouped.items()]).strip()) f.write("%s %s\n"%( toHex(b.getID()), desc))
def dumpAssignments(self, f, description=""): # one ring per filter set # bridges may be present in multiple filter sets # only one line should be dumped per bridge for b in self.bridges: # gather all the filter descriptions desc = [] for n, (g, r) in self.filterRings.items(): if g(b): # ghetto. get subring flags, ports for tp, val, _, subring in r.subrings: if subring.getBridgeByID(b.getID()): desc.append("%s=%s" % (tp, val)) try: desc.extend(g.description.split()) except TypeError: desc.append(g.description) # add transports logging.debug("%s supports %d transports" % (b, len(b.transports))) for transport in b.transports: desc.append("transport=%s" % (transport.methodname)) # dedupe and group desc = set(desc) grouped = dict() for kw in desc: l, r = kw.split('=') try: grouped[l] = "%s,%s" % (grouped[l], r) except KeyError: grouped[l] = kw # add to assignments desc = "%s %s" % (description.strip(), " ".join( [v for k, v in grouped.items()]).strip()) f.write("%s %s\n" % (toHex(b.getID()), desc))