From 35a0f078870cf038c54e9faaf6e19c377bb243d8 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 21 Jul 2024 17:40:54 +0200 Subject: [PATCH] remove startup/socket setup from metadata --- chatmaild/src/chatmaild/dictproxy.py | 7 ++----- chatmaild/src/chatmaild/metadata.py | 29 +--------------------------- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/chatmaild/src/chatmaild/dictproxy.py b/chatmaild/src/chatmaild/dictproxy.py index e2f299c0..522a8cf1 100644 --- a/chatmaild/src/chatmaild/dictproxy.py +++ b/chatmaild/src/chatmaild/dictproxy.py @@ -23,7 +23,7 @@ class DictProxy: wfile.flush() def handle_dovecot_request(self, msg): - # see https://doc.dovecot.org/3.0/developer_manual/design/dict_protocol/ + # see https://doc.dovecot.org/developer_manual/design/dict_protocol/#dovecot-dict-protocol short_command = msg[0] parts = msg[1:].split("\t") @@ -67,10 +67,7 @@ class DictProxy: self.transactions[transaction_id]["res"] = "F\n" def handle_commit_transaction(self, transaction_id, parts): - # each set devicetoken operation persists directly - # and does not wait until a "commit" comes - # because our dovecot config does not involve - # multiple set-operations in a single commit + # return whatever "set" command(s) set as result. return self.transactions.pop(transaction_id)["res"] def serve_forever_from_socket(self, socket): diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index a332ccab..5d886cb8 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -1,11 +1,5 @@ import logging -import os import sys -from socketserver import ( - StreamRequestHandler, - ThreadingMixIn, - UnixStreamServer, -) from .config import read_config from .dictproxy import DictProxy @@ -83,10 +77,6 @@ class MetadataDictProxy(DictProxy): self.transactions[transaction_id]["res"] = "F\n" -class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer): - request_queue_size = 100 - - def main(): socket, config_path = sys.argv[1:] @@ -108,21 +98,4 @@ def main(): notifier=notifier, metadata=metadata, iroh_relay=iroh_relay ) - class Handler(StreamRequestHandler): - def handle(self): - try: - dictproxy.loop_forever(self.rfile, self.wfile) - except Exception: - logging.exception("Exception in the dovecot dictproxy handler") - raise - - try: - os.unlink(socket) - except FileNotFoundError: - pass - - with ThreadedUnixStreamServer(socket, Handler) as server: - try: - server.serve_forever() - except KeyboardInterrupt: - pass + dictproxy.serve_forever_from_socket(socket)