From d1779dd51e4799f3d17c7f84f9495ed29536a725 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Tue, 16 Jul 2024 21:57:35 +0000 Subject: [PATCH] Adds an option for the server to intentionally crash when it's outbound links go down --- server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.py b/server.py index a41f4cf..f69328c 100644 --- a/server.py +++ b/server.py @@ -4,6 +4,9 @@ from traceback import format_exc from logs import log +class LinksDownException(Exception): ... + + class Globals: ... @@ -23,6 +26,7 @@ G.interruptCount = 0 G.killList = {} G.outboundLinks = [] G.S2SLogs = [] +G.cwlgd = False saveLogs = True address = "0.0.0.0" # Try to load a message log, if one exists @@ -58,6 +62,7 @@ Accepted arguments: --link=: - Establishes an S2S link with remote server on port when the server starts up --hostname= - Sets the hostname for this server to use when talking to other servers. Defaults to the current system's hostname (limit of 16 chars) --address= - Sets the IP to listen on, defaults to all addresses (0.0.0.0) +--cwlgd - Crashes the server when outbound links go down Examples: python3 {filename} --hostname=Fun-chat --link=chat.example.com:65048 --port=92628 @@ -76,6 +81,9 @@ python3 {filename} --address=127.0.0.1 -l -p=7288""" raise ValueError elif arg.startswith("--address"): address = arg[9:] + elif arg.startswith("--cwlgd"): + G.cwlgd = True + log("Server will crasg when outbound links go down!", "WARN") else: log(f"Unrecognized argument {arg}!", "WARN") except Exception: @@ -537,6 +545,8 @@ async def connectServer(hostname: str, port: int): pass await writer.drain() msgInd += 1 + if G.cwlgd: + raise LinksDownException await writer.drain() writer.close() await writer.wait_closed() @@ -546,6 +556,8 @@ async def connectServer(hostname: str, port: int): del G.servers[rID] G.msgs.append(log(f"{rID} has de-linked from the network")) except (ConnectionResetError, BrokenPipeError, IndexError): + if G.cwlgd: + raise LinksDownException for cName in G.servers[rID]: G.msgs.append(log(f"{cName}'s server is going down")) try: