def list_circuits(options, proto): print("Circuits:") state = txtorcon.TorState(proto) yield state.post_bootstrap now = datetime.datetime.utcnow() util.dump_circuits(state, options['verbose'])
async def list_circuits(reactor, cfg, tor, verbose): print("Circuits:") state = await tor.create_state() now = datetime.datetime.utcnow() util.dump_circuits(state, verbose)
def monitor_callback(options, state): follow_string = None if options['log-level'] and not options['once']: follow_string = 'Logging (' for event in options['log-level']: # LOG_LEVELS: state.protocol.add_event_listener(event, functools.partial(tor_log, event)) follow_string += event + ', ' if event == options['log-level']: break follow_string = follow_string[:-2] + ')' if not options['no-streams']: if follow_string: follow_string += ' and Stream' else: follow_string = 'Stream' if len(state.streams): print("Current streams:") for stream in state.streams.values(): print(' ' + string_for_stream(state, stream)) else: print("No streams.") state.add_stream_listener(StreamLogger(state, options['verbose'])) if not options['no-circuits']: if follow_string: follow_string += ' and Circuit' else: follow_string = 'Circuit' if len(state.circuits): print("Current circuits:") dump_circuits(state, verbose=options['verbose']) else: print("No circuits.") state.add_circuit_listener(CircuitLogger(state, show_flags=options['verbose'])) if not options['no-guards']: if len(state.entry_guards): print("Current Entry Guards:") for (name, router) in state.entry_guards.iteritems(): if not router.from_consensus: if router.name: print(" %s: %s (not in consensus)" % (router.name, router.id_hex)) else: print(" %s (not in consensus)" % router.id_hex) else: print(" ", router.id_hex, router.name, format_net_location(router.location)) else: print("No Guard nodes!") if not options['no-addr']: if follow_string: follow_string += ' and Address' else: follow_string = 'Address' if len(state.addrmap.addr): print("Current address mappings:") for addr in state.addrmap.addr.values(): print(' %s -> %s' % (addr.name, addr.ip)) state.addrmap.add_listener(AddressLogger()) else: print("No address mappings.") all_done = defer.Deferred() if not options['once']: print('') print("Following new %s activity:" % follow_string) def stop_reactor(arg): print("Tor disconnected.") all_done.callback(None) def error(fail): print(colors.red('Error:'), fail.getErrorMessage()) state.protocol.on_disconnect.addErrback(error).addBoth(stop_reactor) else: all_done.callback(None) return all_done
def run(reactor, cfg, tor, verbose, no_guards, no_addr, no_circuits, no_streams, once, log_level): state = yield tor.create_state() follow_string = None if log_level and not once: follow_string = 'Logging (' for event in log_level: # LOG_LEVELS: state.protocol.add_event_listener( event, functools.partial(tor_log, event)) follow_string += event + ', ' if event == log_level: break follow_string = follow_string[:-2] + ')' if not no_streams: if follow_string: follow_string += ' and Stream' else: follow_string = 'Stream' if len(state.streams): print("Current streams:") for stream in state.streams.values(): print(' ' + string_for_stream(state, stream)) else: print("No streams.") state.add_stream_listener(StreamLogger(state, verbose)) if not no_circuits: if follow_string: follow_string += ' and Circuit' else: follow_string = 'Circuit' if len(state.circuits): print("Current circuits:") dump_circuits(state, verbose=verbose) else: print("No circuits.") state.add_circuit_listener(CircuitLogger(state, show_flags=verbose)) if not no_guards: if len(state.entry_guards): print("Current Entry Guards:") for (name, router) in state.entry_guards.iteritems(): if not router.from_consensus: if router.name: print(" %s: %s (not in consensus)" % (router.name, router.id_hex)) else: print(" %s (not in consensus)" % router.id_hex) else: print(" ", router.id_hex, router.name, format_net_location(router.location)) else: print("No Guard nodes!") if not no_addr: if follow_string: follow_string += ' and Address' else: follow_string = 'Address' if len(state.addrmap.addr): print("Current address mappings:") for addr in state.addrmap.addr.values(): print(' %s -> %s' % (addr.name, addr.ip)) state.addrmap.add_listener(AddressLogger()) else: print("No address mappings.") all_done = defer.Deferred() if not once: print('') print("Following new %s activity:" % follow_string) def stop_reactor(arg): print("Tor disconnected.") all_done.callback(None) def error(fail): print(colors.red('Error:'), fail.getErrorMessage()) state.protocol.on_disconnect.addErrback(error).addBoth(stop_reactor) else: all_done.callback(None) yield all_done