From 2db2b17a86328f256cb0b042e269339829362abf Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 23 Jun 2022 15:33:34 +0800 Subject: [PATCH] bugfix --- ahserver/configuredServer.py | 56 ++++-------------------------------- 1 file changed, 5 insertions(+), 51 deletions(-) diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index f1244a7..563efd5 100644 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -16,22 +16,15 @@ from .processorResource import ProcessorResource from .auth_api import AuthAPI from .myTE import setupTemplateEngine from .globalEnv import initEnv -try: - from natpmp import NATPMP as pmp -except: - pmp = None class ConfiguredServer(AppLogger): def __init__(self, auth_klass=AuthAPI, workdir=None): super().__init__() - pp = ProgramPath() - if workdir is None: - self.natpmp_loop = True - self.nat_heartbeat = False - workdir = pp - if len(sys.argv) > 1: - workdir = sys.argv[1] - config = getConfig(workdir,{'workdir':workdir,'ProgramPath':pp}) + if workdir is not None: + pp = ProgramPath() + config = getConfig(workdir,{'workdir':workdir,'ProgramPath':pp}) + else: + config = getConfig() i18n = getI18N(path=workdir) if config.databases: DBPools(config.databases) @@ -42,34 +35,6 @@ class ConfiguredServer(AppLogger): auth.setupAuth(self.app) self.configPath(config) - def natpmp_heartbeat(self): - config = getConfig() - udpCliSock = socket(AF_INET,SOCK_DGRAM) - msg = f'{config.natpmp.appname}:{config.natpmp.nodename}'.encode('utf-8') - t = config.natpmp.heartbeat_period or 60 - addr = (gethostbyname(config.natpmp.natserver), config.natpmp.natport) - while self.nat_heartbeat: - udpCliSock.sendto(msg, addr) - udpCliSock.recv(1024) - time.sleep(t) - - def nat_pmp(self): - config = getConfig() - t = config.natpmp.portmap_period or 3600 - while self.natpmp_loop: - gateway = pmp.get_gateway_addr() - self.debug('gateway=%s' % gateway) - try: - x = pmp.map_port(pmp.NATPMP_PROTOCOL_TCP, - config.natpmp.public_port, config.website.port, - t, gateway_ip=gateway) - self.debug('gateway=%s map_port=%s' %( gateway, x)) - except Exception as e: - self.debug('mat_pmp():Exception:%s' % e) - time.sleep(t - 1) - - - def run(self): config = getConfig() ssl_context = None @@ -77,18 +42,7 @@ class ConfiguredServer(AppLogger): ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ssl_context.load_cert_chain(config.website.ssl.crtfile, config.website.ssl.keyfile) - if pmp and config.natpmp: - self.nat_heartbeat = True - b = Background(self.natpmp_heartbeat) - b.start() - if not config.natpmp: - self.natpmp_loop = False - elif config.natpmp.hardmap: - self.natpmp_loop = False - else: - b = Background(self.nat_pmp) - b.start() web.run_app(self.app,host=config.website.host or '0.0.0.0', port=config.website.port or 8080, ssl_context=ssl_context)