def main(): global __file__ __file__ = os.path.abspath(__file__) if os.path.islink(__file__): __file__ = getattr(os, 'readlink', lambda x: x)(__file__) os.chdir(os.path.dirname(os.path.abspath(__file__))) logging.basicConfig(level=logging.DEBUG if common.LISTEN_DEBUGINFO else logging.INFO, format='%(levelname)s - %(asctime)s %(message)s', datefmt='[%b %d %H:%M:%S]') pre_start() logging.info(common.info()) if common.PAC_ENABLE: server = LocalProxyServer((common.PAC_IP, common.PAC_PORT), pac_server.PACServerHandler) p = threading.Thread(target=server.serve_forever) p.setDaemon(True) p.start() if common.CONTROL_ENABLE: control_server = LocalProxyServer((common.CONTROL_IP, common.CONTROL_PORT), remote_control.RemoveContralServerHandler) p = threading.Thread(target=control_server.serve_forever) p.setDaemon(True) p.start() server = LocalProxyServer((common.LISTEN_IP, common.LISTEN_PORT), proxy_handler.GAEProxyHandler) p = threading.Thread(target=server.serve_forever) p.setDaemon(True) p.start() CertUtil.check_ca() while True: time.sleep(100000)
def main(): # to profile goagent, run proxy.py, visit some web by proxy, then visit http://127.0.0.1:8084/quit to quit and print result. do_profile = False if do_profile: import cProfile, pstats pr = cProfile.Profile() pr.enable() global __file__ __file__ = os.path.abspath(__file__) if os.path.islink(__file__): __file__ = getattr(os, 'readlink', lambda x: x)(__file__) os.chdir(os.path.dirname(os.path.abspath(__file__))) logging.basicConfig( level=logging.DEBUG if config.LISTEN_DEBUGINFO else logging.INFO, format='%(levelname)s - %(asctime)s %(message)s', datefmt='[%b %d %H:%M:%S]') pre_start() logging.info(config.info()) if config.PAC_ENABLE: server = LocalProxyServer((config.PAC_IP, config.PAC_PORT), pac_server.PACServerHandler) p = threading.Thread(target=server.serve_forever) p.setDaemon(True) p.start() if config.CONTROL_ENABLE: control_server = LocalProxyServer( (config.CONTROL_IP, config.CONTROL_PORT), remote_control.RemoveContralServerHandler) p = threading.Thread(target=control_server.serve_forever) p.setDaemon(True) p.start() server = LocalProxyServer((config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler) p = threading.Thread(target=server.serve_forever) p.setDaemon(True) p.start() CertUtil.check_ca() while config.keep_run: time.sleep(1) if do_profile: pr.disable() pr.print_stats(sort="cumtime")