|
@ -4,10 +4,10 @@ |
|
|
import copy |
|
|
import copy |
|
|
import time |
|
|
import time |
|
|
from Checker import Checker |
|
|
from Checker import Checker |
|
|
from Basis.Logger import logging |
|
|
from Utils.Logger import logger |
|
|
|
|
|
from Utils.Common import isVacantPort |
|
|
from Builder import Builder, clientEntry |
|
|
from Builder import Builder, clientEntry |
|
|
from Basis.Exception import checkException |
|
|
from Utils.Exception import checkException |
|
|
from Basis.Functions import checkPortStatus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def buildClient(taskId: str, taskInfo: dict) -> Builder: |
|
|
def buildClient(taskId: str, taskInfo: dict) -> Builder: |
|
@ -19,36 +19,36 @@ def buildClient(taskId: str, taskInfo: dict) -> Builder: |
|
|
taskId = taskId, |
|
|
taskId = taskId, |
|
|
) |
|
|
) |
|
|
except Exception as reason: |
|
|
except Exception as reason: |
|
|
logging.error('[%s] Client build error -> %s' % (taskId, reason)) |
|
|
logger.error('[%s] Client build error -> %s' % (taskId, reason)) |
|
|
raise checkException('Client build error') |
|
|
raise checkException('Client build error') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def waitClient(taskId: str, client: Builder, times: int = 150, delay: int = 100): # wait until client port occupied |
|
|
def waitClient(taskId: str, client: Builder, times: int = 150, delay: int = 100): # wait until client port occupied |
|
|
for i in range(times): |
|
|
for i in range(times): |
|
|
if not checkPortStatus(client.socksPort): # port occupied |
|
|
if not isVacantPort(client.socksPort): # port occupied |
|
|
break |
|
|
break |
|
|
time.sleep(delay / 1000) # wait in default: 100ms * 150 => 15s |
|
|
time.sleep(delay / 1000) # wait in default: 100ms * 150 => 15s |
|
|
time.sleep(1) # wait a short time before check process |
|
|
time.sleep(1) # wait a short time before check process |
|
|
if not client.status(): # client unexpected exit |
|
|
if not client.status(): # client unexpected exit |
|
|
logging.warning('[%s] Client unexpected exit' % taskId) |
|
|
logger.warning('[%s] Client unexpected exit' % taskId) |
|
|
client.destroy() # remove file and kill sub process |
|
|
client.destroy() # remove file and kill sub process |
|
|
logging.debug('[%s] Client output\n%s', (taskId, client.output)) |
|
|
logger.debug('[%s] Client output\n%s', (taskId, client.output)) |
|
|
raise checkException('Client unexpected exit') |
|
|
raise checkException('Client unexpected exit') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Check(taskId: str, taskInfo: dict) -> dict: |
|
|
def Check(taskId: str, taskInfo: dict) -> dict: |
|
|
logging.info('[%s] Start checking process -> %s' % (taskId, taskInfo)) |
|
|
logger.info('[%s] Start checking process -> %s' % (taskId, taskInfo)) |
|
|
if taskInfo['type'] not in clientEntry: # unknown proxy type |
|
|
if taskInfo['type'] not in clientEntry: # unknown proxy type |
|
|
logging.error('[%s] Unknown proxy type %s' % (taskId, taskInfo['type'])) |
|
|
logger.error('[%s] Unknown proxy type %s' % (taskId, taskInfo['type'])) |
|
|
raise checkException('Unknown proxy type') |
|
|
raise checkException('Unknown proxy type') |
|
|
client = buildClient(taskId, taskInfo) # build proxy client |
|
|
client = buildClient(taskId, taskInfo) # build proxy client |
|
|
logging.info('[%s] Client loaded successfully' % taskId) |
|
|
logger.info('[%s] Client loaded successfully' % taskId) |
|
|
waitClient(taskId, client) # wait for the client to start |
|
|
waitClient(taskId, client) # wait for the client to start |
|
|
checkResult = Checker(taskId, taskInfo['check'], { # start check process |
|
|
checkResult = Checker(taskId, taskInfo['check'], { # start check process |
|
|
'addr': client.socksAddr, |
|
|
'addr': client.socksAddr, |
|
|
'port': client.socksPort, |
|
|
'port': client.socksPort, |
|
|
}) |
|
|
}) |
|
|
logging.info('[%s] Client check result -> %s' % (taskId, checkResult)) |
|
|
logger.info('[%s] Client check result -> %s' % (taskId, checkResult)) |
|
|
client.destroy() # clean up client |
|
|
client.destroy() # clean up client |
|
|
taskInfo = copy.deepcopy(taskInfo) |
|
|
taskInfo = copy.deepcopy(taskInfo) |
|
|
taskInfo.pop('check') # remove check items |
|
|
taskInfo.pop('check') # remove check items |