def run(self): # Establish a connection with the redis server r = redis.Redis(host=self.host,port=self.port,db=self.db) tasklib.register("resolver",self) try: while True: # Get an outgoing message target, msg = self.recv() print("RESOLVER:", target, msg) # Check if a proxy was already registered if tasklib.lookup(target): tasklib.send(target,msg) continue # See if redis knows anything about the target try: target_info = r.get(target) if target_info: host, port = target_info.decode('utf-8').split(":") port = int(port) # Create a proxy task proxy(target,target,(host,port),self.authkey) self.log.info("Connected to %s", (host,port)) # Send the message to the proxy tasklib.send(target,msg) else: self.log.info("Nothing known about target '%s'", target) except Exception as e: self.log.info("Couldn't resolve '%s' : %s:%s", target, type(e),e) finally: tasklib.unregister("resolver")
def run(self): try: while True: msg = self.recv() self.conn.send((self.target,msg)) finally: self.conn.close() if self.export: tasklib.unregister(self.proxyname)