Пример #1
0
    def __init__(self, host, port, pwd):
        '''Create connection to Tor controller'''
        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        soc.connect((host, port))
        self.socket = soc

        ctl = TorCtl.Connection(self.socket)
        print ctl
        ctl.authenticate(pwd)
        self.ctl = ctl
Пример #2
0
def open_controller(filename):
    """ starts stat gathering thread """

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TorUtil.control_host, TorUtil.control_port))
    c = TorCtl.Connection(s)
    c.authenticate_cookie(file("./tor-data/control_auth_cookie", "r"))
    c.debug(file(filename + ".log", "w", buffering=0))

    guards = get_guards(c, 3)
    guard_str = ",".join(map(lambda r: "$" + r.idhex, guards))

    plog("NOTICE", str(pct_start) + "%: Choosing guards: " + guard_str)
    # Setconf guards for percentile range
    c.set_option("EntryNodes", guard_str)
    c.set_option("StrictNodes", "1")

    cond = threading.Condition()
    cond.min_circs = 0  # Python haxx
    cond.num_circs = 0  # Python haxx
    cond.acquire()

    h = CircHandler(c, guards)
    c.set_event_handler(h)
    c.add_event_listener(BuildTimeoutTracker(cond))

    global FUDValue
    if not FUDValue:
        FUDValue = c.get_option("FetchUselessDescriptors")[0][1]
    c.set_option("FetchUselessDescriptors", "1")

    c.set_events([
        TorCtl.EVENT_TYPE.BUILDTIMEOUT_SET, TorCtl.EVENT_TYPE.BW,
        TorCtl.EVENT_TYPE.GUARD, TorCtl.EVENT_TYPE.CIRC
    ], True)

    # Close all the already open circuits to start fresh
    h.close_all_circs()
    cond.wait()
    cond.release()

    # Write to output_file:
    # 1. Num circs
    # 2. Guards used
    # 3. Failure quantile (in rerun only)
    out = file(output_dir + "/result", "w")
    if not redo_run:
        out.write("MIN_CIRCS: " + str(cond.min_circs) + "\n")
        out.write("MIN_TIMEOUT: " + str(cond.min_timeout) + "\n")
        out.write("MIN_RESET_CNT: " + str(cond.min_reset_cnt) + "\n")
        out.write("MIN_RESET_TOTAL: " + str(cond.min_reset_total) + "\n")
    out.write("NUM_CIRCS: " + str(cond.num_circs) + "\n")
    out.write("NUM_TIMEOUT: " + str(cond.num_timeout) + "\n")
    out.write("NUM_RESET_CNT: " + str(cond.num_reset_cnt) + "\n")
    out.write("NUM_RESET_TOTAL: " + str(cond.num_reset_total) + "\n")
    timeout_cnt = len(h.timeout_circs)
    built_cnt = len(h.built_circs)
    build_rate = float(built_cnt) / (built_cnt + timeout_cnt)
    out.write("BUILD_RATE: " + str(built_cnt) + "/" +
              str(built_cnt + timeout_cnt) + " " + str(round(build_rate, 3)) +
              "\n")
    out.close()
    return 0