mirror of https://github.com/dnomd343/ProxyC
dnomd343
2 years ago
6 changed files with 40 additions and 44 deletions
@ -1,11 +0,0 @@ |
|||||
#!/usr/bin/env python3 |
|
||||
# -*- coding: utf-8 -*- |
|
||||
|
|
||||
import compileall |
|
||||
from Basis.Logger import logging |
|
||||
|
|
||||
|
|
||||
def startCompile(dirRange: str = '/') -> None: |
|
||||
for optimize in [-1, 1, 2]: |
|
||||
compileall.compile_dir(dirRange, quiet = 1, maxlevels = 256, optimize = optimize) |
|
||||
logging.warning('Python optimize compile -> %s (level = %i)' % (dirRange, optimize)) |
|
@ -1,41 +1,44 @@ |
|||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
|
||||
import time |
import time |
||||
import _thread |
import _thread |
||||
from Basis import DnsProxy |
import compileall |
||||
|
from Basis import Constant |
||||
from Basis.Check import Check |
from Basis.Check import Check |
||||
|
from Basis import Api, DnsProxy |
||||
from Basis.Logger import logging |
from Basis.Logger import logging |
||||
from Basis.Manager import Manager |
from Basis.Manager import Manager |
||||
from Basis.Api import startServer |
|
||||
from Basis.Constant import Version |
|
||||
from Basis.Compile import startCompile |
|
||||
from concurrent.futures import ThreadPoolExecutor |
from concurrent.futures import ThreadPoolExecutor |
||||
|
|
||||
# dnsServers = None |
|
||||
dnsServers = ['223.5.5.5', '119.28.28.28'] |
def pythonCompile(dirRange: str = '/') -> None: # python optimize compile |
||||
|
for optimize in [-1, 1, 2]: |
||||
|
compileall.compile_dir(dirRange, quiet = 1, optimize = optimize) |
||||
|
logging.warning('Python optimize compile -> %s (level = %i)' % (dirRange, optimize)) |
||||
|
|
||||
|
|
||||
def runCheck(taskId: str, taskInfo: dict) -> None: |
def runCheck(taskId: str, taskInfo: dict) -> None: |
||||
checkResult = Check(taskId, taskInfo) |
checkResult = Check(taskId, taskInfo) # check by task info |
||||
logging.warning('[%s] Task finish' % taskId) |
logging.warning('[%s] Task finish' % taskId) |
||||
Manager.finishTask(taskId, checkResult) |
Manager.finishTask(taskId, checkResult) # commit check result |
||||
|
|
||||
|
|
||||
def loopCheck(threadNum: int = 16) -> None: |
def loopCheck(threadNum: int = 16) -> None: |
||||
threadPool = ThreadPoolExecutor(max_workers = threadNum) |
threadPool = ThreadPoolExecutor(max_workers = threadNum) # init thread pool |
||||
while True: |
while True: |
||||
try: |
try: |
||||
taskId, taskInfo = Manager.popTask() |
taskId, taskInfo = Manager.popTask() # pop a task |
||||
logging.warning('[%s] Load new task' % taskId) |
logging.warning('[%s] Load new task' % taskId) |
||||
except: # no more task |
except: # no more task |
||||
time.sleep(2) |
time.sleep(2) |
||||
continue |
continue |
||||
threadPool.submit(runCheck, taskId, taskInfo) |
threadPool.submit(runCheck, taskId, taskInfo) # submit into thread pool |
||||
|
|
||||
|
|
||||
logging.warning('ProxyC starts running (%s)' % Version) |
logging.warning('ProxyC starts running (%s)' % Constant.Version) |
||||
_thread.start_new_thread(startCompile, ('/usr', )) # python compile (generate .pyc file) |
_thread.start_new_thread(pythonCompile, ('/usr', )) # python compile (generate .pyc file) |
||||
_thread.start_new_thread(DnsProxy.start, (dnsServers, 53)) # start dns server |
_thread.start_new_thread(DnsProxy.start, (Constant.DnsServer, 53)) # start dns server |
||||
_thread.start_new_thread(loopCheck, ()) # start loop check |
_thread.start_new_thread(loopCheck, ()) # start loop check |
||||
startServer(apiToken = '') # start api server |
Api.startServer(apiToken = Constant.ApiToken) # start api server |
||||
|
Loading…
Reference in new issue