From b9e6265063a9955d23084837e5b6853a9b4693da Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Thu, 7 Mar 2024 02:53:32 +0900 Subject: [PATCH] Update server.py --- server.py | 70 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/server.py b/server.py index 2cda210..101c39e 100644 --- a/server.py +++ b/server.py @@ -44,6 +44,41 @@ def extract_credentials(url): else: return None, None, url +# initalization +try: + listening_port = config('PORT', default=5555, cast=int) + _username, _password, server_url = extract_credentials(config('SERVER_URL', default='localhost')) + server_connection_type = config('SERVER_CONNECTION_TYPE', default='stateless') + cakey = config('CA_KEY', default='ca.key') + cacert = config('CA_CERT', default='ca.crt') + certkey = config('CERT_KEY', default='cert.key') + certdir = config('CERT_DIR', default='certs/') + openssl_binpath = config('OPENSSL_BINPATH', default='openssl') + client_encoding = config('CLIENT_ENCODING', default='utf-8') + local_domain = config('LOCAL_DOMAIN', default='') + proxy_pass = config('PROXY_PASS', default='') +except KeyboardInterrupt: + print("\n[*] User has requested an interrupt") + print("[*] Application Exiting.....") + sys.exit() +except Exception as e: + print("[*] Failed to initialize:", str(e)) + +parser = argparse.ArgumentParser() +parser.add_argument('--max_conn', help="Maximum allowed connections", default=255, type=int) +parser.add_argument('--buffer_size', help="Number of samples to be used", default=8192, type=int) + +args = parser.parse_args() +max_connection = args.max_conn +buffer_size = args.buffer_size +accepted_relay = {} +resolved_address_list = [] + +# set basic authentication +auth = None +if _username: + auth = HTTPBasicAuth(_username, _password) + def jsonrpc2_create_id(data): return hashlib.sha1(json.dumps(data).encode(client_encoding)).hexdigest() @@ -566,41 +601,6 @@ def connect(self, conn, data, webserver, port, scheme, method, url): raise NotImplementedError if __name__== "__main__": - # initalization - try: - listening_port = config('PORT', default=5555, cast=int) - _username, _password, server_url = extract_credentials(config('SERVER_URL', default='localhost')) - server_connection_type = config('SERVER_CONNECTION_TYPE', default='stateless') - cakey = config('CA_KEY', default='ca.key') - cacert = config('CA_CERT', default='ca.crt') - certkey = config('CERT_KEY', default='cert.key') - certdir = config('CERT_DIR', default='certs/') - openssl_binpath = config('OPENSSL_BINPATH', default='openssl') - client_encoding = config('CLIENT_ENCODING', default='utf-8') - local_domain = config('LOCAL_DOMAIN', default='') - proxy_pass = config('PROXY_PASS', default='') - except KeyboardInterrupt: - print("\n[*] User has requested an interrupt") - print("[*] Application Exiting.....") - sys.exit() - except Exception as e: - print("[*] Failed to initialize:", str(e)) - - parser = argparse.ArgumentParser() - parser.add_argument('--max_conn', help="Maximum allowed connections", default=255, type=int) - parser.add_argument('--buffer_size', help="Number of samples to be used", default=8192, type=int) - - args = parser.parse_args() - max_connection = args.max_conn - buffer_size = args.buffer_size - accepted_relay = {} - resolved_address_list = [] - - # set basic authentication - auth = None - if _username: - auth = HTTPBasicAuth(_username, _password) - # load extensions #Extension.register(importlib.import_module("plugins.fediverse").Fediverse()) #Extension.register(importlib.import_module("plugins.container").Container())