def run(self):
		if not self.AgreeConnIp(self.addr):
			baseServer.log(2, self.threadid, "not agree ip %s connect!" % (self.addr))
			return;

		baseServer.log(1, self.threadid, "..... threadid start")
		self.connRemoteProxyServer()
		DDDProxySocketMessage.sendOne(self.remoteSocket, "[%d]" % (self.threadid))
		baseServer.log(1, self.threadid, "threadid mark")
		thread.start_new_thread(self.sourceToServer, tuple())
		threading.currentThread().name = "%d-%s-recv"%(self.threadid,self.addr)
		self.serverToSource()
		baseServer.log(1, self.threadid, "!!!!! threadid end")
	def run(self):
		if not self.AgreeConnIp(self.addr):
			baseServer.log(2, self.threadid, "not agree ip %s connect!" % (self.addr))
			return;

		baseServer.log(1, self.threadid, "..... threadid start")
		host,port,auth = setting[settingConfig.remoteServerKey]
		self.connRemoteProxyServer(host,port,auth)
		mark = "[%s,%s]" % (self.addr,self.threadid)
		DDDProxySocketMessage.sendOne(self.remoteSocket,mark )
		baseServer.log(1, self.threadid, "threadid mark")
		
		mainThreadPool.callInThread(self.sourceToServer)
# 		thread.start_new_thread(self.sourceToServer, tuple())
		
		self.serverToSource()
		baseServer.log(1, self.threadid, "!!!!! threadid end")
Example #3
0
	def getInThread(self):
		opt = self.get_argument("opt", default="status")
		if opt:
			opt = opt.encode("utf8")
		
# 		threading.currentThread().name = "statusPage-%s"%(opt)
		if opt == "remoteProxy":
			status = "connected"
			try:
				port = self.get_argument("port", default=0)
				port = port if port else 8083
				test = proxyServerHandler(conn=None, addr=["", ""], threadid=None)
				test.connRemoteProxyServer(host=self.get_argument("host", default=""),
										port=int(port),
										auth=self.get_argument("auth", default=""))
				DDDProxySocketMessage.sendOne(test.remoteSocket, "[%s,%s]" % ("0.0.0.0", "test"))
				DDDProxySocketMessage.sendOne(test.remoteSocket,
															"CONNECT www.google.com:443 HTTP/1.1\r\n\r\n");
				status = "connected,auth no pass"
				for d in  DDDProxySocketMessage.recv(test.remoteSocket):
					if d == "HTTP/1.1 200 OK\r\n\r\n":
						status = "connected"
				test.close()
			except:
				printError()
				status = "can not connect"
			self.write({"status":status})
		elif opt == "pac_setting_test_local":
			self.write({"status":"fail"})
		else:
			working = []
			working.extend(t.name for t in mainThreadPool.working)
			idle = []
			idle.extend(t.name for t in mainThreadPool.waiters)
			
			connectList = {}
			for handler in localProxyServer.theadList:
				try:
					addrList = None
					addr = self.gethostbyaddr(handler.addr)
					if addr in connectList:
						addrList = connectList[addr]
					else:
						connectList[addr] = addrList = []
					addrList.append([handler.httpMessage[1] if (type(handler.httpMessage) == tuple and len(handler.httpMessage) > 2) else handler.httpMessage,
									handler.remoteServer,
									handler.dataCountSend,
									handler.dataCountRecv])
				except:
					printError()
			data = {
				"count":{
						"worker":len(mainThreadPool.working),
						"idle":len(mainThreadPool.waiters)
						},
				"thread":{
# 						"worker":working,
# 						"idle":idle
						"connect":connectList
						}
				}
			self.write(data)
		self.finish()