Exemplo n.º 1
0
	def timer_cb (self):
		self.__sock = socket.socket ( socket.AF_INET, \
					      socket.SOCK_STREAM)

	        while not self.__connected:
			try:
				self.__sock.connect((self.__host, self.__port))
			except:
				if self.__torStatus != 'Stopped':
					self.__torStatus = 'Stopped'
					self.notifyObservers ( \
					     Notification('TorStatusChanged',\
					         'Stopped'))
					self.__resetCounters ()
				return True
			else:
				tc.authenticate (self.__sock)
				self.__connected   = True
				self.__torStatus   = 'Started'
				self.__timeStarted = datetime.now ()
				self.__torVersion  = tc.get_info \
					(self.__sock, 'version')['version']

				self.notifyObservers (Notification \
					('TorStatusChanged', 'Started'))
				
				tc.set_events(self.__sock, self.__events)
				self.__iocb = io_add_watch (self.__sock, \
							    IO_IN, \
							    self.input_cb)

				return False
Exemplo n.º 2
0
def runControl(s):
    pendingEvents = [] #XXX This tric. should become standard
    TorControl._event_handler = pendingEvents.append
    TorControl.set_events(s,
                          [TorControl.EVENT_TYPE.CIRCSTATUS,
                           TorControl.EVENT_TYPE.STREAMSTATUS])
    TorControl.set_option(s,"__LeaveStreamsUnattached 1")
    while 1:
        e = pendingEvents[:]
        del pendingEvents[:]
        for ev in e:
            handleEvent(s, ev)
        _, tp, body = TorControl.receive_message(s)
        if tp == TorControl.MSG_TYPE.EVENT:
            handleEvent(s, body)
Exemplo n.º 3
0
def runControl(s):
    circs = {}
    s1, s2 = {}, {}
    _h = lambda body, circs=circs, s1=s1, s2=s2, s=s: handleEvent(
        s, body, circs, s1, s2)
    TorControl._event_handler = _h
    TorControl.set_events(
        s,
        [TorControl.EVENT_TYPE.CIRCSTATUS, TorControl.EVENT_TYPE.STREAMSTATUS])
    TorControl.set_option(s, "__LeaveStreamsUnattached 1")
    global N_CIRCS_DONE
    while N_CIRCS_DONE < N_CIRCS_TO_TRY:
        while len(circs) < CIRCS_AT_A_TIME:
            c, p = launchCirc(s)
            print "launching circuit %s to %s" % (c, p)
            circs[c] = p
        _, tp, body = TorControl.receive_message(s)
        if tp == TorControl.MSG_TYPE.EVENT:
            handleEvent(s, body, circs, s1, s2)
    i = HOST_STATUS.items()
    i.sort()
    for n, (all, good) in i:
        print "%s in %s circuits; %s/%s ok" % (n, all, good, all)