Browse Source

feat: backend check loop

master
Dnomd343 3 years ago
parent
commit
205534a180
  1. 2
      Checker.py
  2. 41
      Loop.py
  3. 2
      ProxyChecker/Http.py
  4. 13
      Run.py
  5. 5
      Web.py
  6. 11
      redisTest.py

2
Checker.py

@ -39,7 +39,7 @@ def proxyTest(
startDelay = 1, startDelay = 1,
workDir = '/tmp/ProxyC', workDir = '/tmp/ProxyC',
httpCheckUrl = 'http://gstatic.com/generate_204', httpCheckUrl = 'http://gstatic.com/generate_204',
httpCheckTimeout = 12, httpCheckTimeout = 20,
): ):
''' '''
代理检测入口 代理检测入口

41
Loop.py

@ -0,0 +1,41 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import redis
import subprocess
maxThread = 32
redisPort = 6379
redisHost = 'localhost'
redisPrefix = 'proxyc-'
redisObject = redis.StrictRedis(
db = 0,
host = redisHost,
port = redisPort
)
processList = []
while True:
spareNum = min(
maxThread - len(processList), # 空余进程数
len(redisObject.keys(redisPrefix + 'check-*')) # 待检测个数
)
if spareNum < 0:
spareNum = 0
print("spareNum = " + str(spareNum))
for i in range(spareNum): # 运行检测进程
processList.append(
subprocess.Popen(['python','Run.py'])
)
time.sleep(0.2)
for process in processList: # 遍历子进程
if process.poll() != None: # 进程已退出
print("remove subprocess")
processList.remove(process)
time.sleep(0.5)

2
ProxyChecker/Http.py

@ -54,7 +54,9 @@ def httpCheck(port, url = 'http://gstatic.com/generate_204', timeout = 30):
''' '''
result = [] result = []
failNum = 0 failNum = 0
timeout = timeout * 64 / 119 # 4/64 + 2/64 + 1/64 + 1/4 + 1/2 + 1/1
for i in [4, 2, 1]: # 三次测试 for i in [4, 2, 1]: # 三次测试
time.sleep(timeout / 64 * i)
status, delay = httpPing(port, url, timeout / i) status, delay = httpPing(port, url, timeout / i)
if status == None: # 测试异常 if status == None: # 测试异常
return None, delay return None, delay

13
Run.py

@ -60,7 +60,12 @@ def main(startDelay, httpCheckUrl, httpCheckTimeout):
print("no task found") print("no task found")
return return
print(checkInfo) print(checkInfo)
checkResult = Checker.proxyTest(checkInfo) checkResult = Checker.proxyTest(
checkInfo,
startDelay = startDelay,
httpCheckUrl = httpCheckUrl,
httpCheckTimeout = httpCheckTimeout
)
if checkResult == None: if checkResult == None:
print("some bad things happen") print("some bad things happen")
return return
@ -73,8 +78,8 @@ def main(startDelay, httpCheckUrl, httpCheckTimeout):
return return
print("ok") print("ok")
defaultStartDelay = 1 defaultStartDelay = 1.5
defaultHttpCheckTimeout = 30 defaultHttpCheckTimeout = 20
defaultHttpCheckUrl = 'https://api.v2fly.org/checkConnection.svgz' defaultHttpCheckUrl = 'http://gstatic.com/generate_204'
main(defaultStartDelay, defaultHttpCheckUrl, defaultHttpCheckTimeout) main(defaultStartDelay, defaultHttpCheckUrl, defaultHttpCheckTimeout)

5
Web.py

@ -144,6 +144,7 @@ def getTaskInfo(checkId): # 获取任务详情
'success': True, 'success': True,
'complete': True, 'complete': True,
'checkId': checkId, 'checkId': checkId,
'number': len(taskInfo['proxy']),
'result': taskInfo['result'] 'result': taskInfo['result']
} }
@ -156,7 +157,8 @@ def getTaskInfo(checkId): # 获取任务详情
'success': True, 'success': True,
'complete': False, 'complete': False,
'checkId': checkId, 'checkId': checkId,
'schedule': format(completeNum / len(taskInfo['proxy']), '.2f') 'number': len(taskInfo['proxy']),
'schedule': round(completeNum / len(taskInfo['proxy']), 2)
} }
checkResult = [] checkResult = []
@ -174,6 +176,7 @@ def getTaskInfo(checkId): # 获取任务详情
'success': True, 'success': True,
'complete': True, 'complete': True,
'checkId': checkId, 'checkId': checkId,
'number': len(taskInfo['proxy']),
'result': taskInfo['result'] 'result': taskInfo['result']
} }
except: except:

11
redisTest.py

@ -1,11 +0,0 @@
import redis
redisPrefix = 'proxyc-'
redisHost = 'localhost'
redisPort = 6379
ssInfo = '{"tag": "f43c9bae21ae8693", "check": ["http"], "info": {"type": "ss", "server": "127.0.0.1", "port": 12345, "password": "dnomd343", "method": "aes-256-ctr", "plugin": "", "pluginParam": ""}}'
ssrInfo = '{"tag": "54cd9ba3a8e86f93", "check": ["http"], "info": {"type": "ssr", "server": "127.0.0.1", "port": 23456, "password": "dnomd343", "method": "table", "protocol": "auth_aes128_md5", "protocolParam": "", "obfs": "tls1.2_ticket_auth", "obfsParam": ""}}'
redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0)
redisObject.set(redisPrefix + 'check-a-f43c9bae21ae8693', ssInfo)
redisObject.set(redisPrefix + 'check-c-54cd9ba3a8e86f93', ssrInfo)
Loading…
Cancel
Save