def circuit_failed(self, circuit, kw):
        """ICircuitListener API"""

        if kw['REASON'] != 'MEASUREMENT_EXPIRED':
            return

        # older tor versions will have empty build_flags
        if 'ONEHOP_TUNNEL' in circuit.build_flags:
            return

        if circuit.purpose == 'GENERAL':
            if len(circuit.path) > 1:
                if circuit.path[0] not in self.state.entry_guards.values():
                    # note that single-hop circuits are built for various
                    # internal reasons (and it seems they somtimes use
                    # GENERAL anyway)
                    print "WEIRD: first circuit hop not in entry guards:",
                    print circuit, circuit.path
                    return

            self.failed_circuits += 1
            print "failed", circuit.id
            if circuit.id not in self.failed_circuit_ids:
                self.failed_circuit_ids.append(circuit.id)
            else:
                print "WARNING: duplicate message for", circuit

            if len(circuit.path) > 0:
                try:
                    self.per_guard_failed[circuit.path[0].unique_name] += 1.0
                except __HOLE__:
                    self.per_guard_failed[circuit.path[0].unique_name] = 1.0
                    self.per_guard_built[circuit.path[0].unique_name] = 0.0

            self.update_percent()
dataset/ETHPy150Open meejah/txtorcon/examples/circuit_failure_rates.py/CircuitFailureWatcher.circuit_failed