diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index de6704c0..9e3b9839 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -66,6 +66,7 @@ class Config: self.acme_email = params.get("acme_email", "") self.imap_rawlog = params.get("imap_rawlog", "false").lower() == "true" self.imap_compress = params.get("imap_compress", "false").lower() == "true" + self.turn_socket_path = params.get("turn_socket_path", "/run/chatmail-turn/turn.socket") if "iroh_relay" not in params: self.iroh_relay = "https://" + raw_domain self.enable_iroh_relay = True diff --git a/chatmaild/src/chatmaild/ini/chatmail.ini.f b/chatmaild/src/chatmaild/ini/chatmail.ini.f index 5d3cbe0d..27a3a952 100644 --- a/chatmaild/src/chatmaild/ini/chatmail.ini.f +++ b/chatmaild/src/chatmaild/ini/chatmail.ini.f @@ -63,7 +63,10 @@ passthrough_recipients = # Deployment Details # -# SMTP outgoing filtermail and reinjection +# Path to the TURN server Unix socket +turn_socket_path = /run/chatmail-turn/turn.socket + +# SMTP outgoing filtermail and reinjection filtermail_smtp_port = 10080 postfix_reinject_port = 10025 diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index 03bdc2da..01114539 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -79,12 +79,13 @@ class Metadata: class MetadataDictProxy(DictProxy): - def __init__(self, notifier, metadata, iroh_relay=None, turn_hostname=None): + def __init__(self, notifier, metadata, iroh_relay=None, turn_hostname=None, turn_socket_path=None): super().__init__() self.notifier = notifier self.metadata = metadata self.iroh_relay = iroh_relay self.turn_hostname = turn_hostname + self.turn_socket_path = turn_socket_path def handle_lookup(self, parts): # Lpriv/43f5f508a7ea0366dff30200c15250e3/devicetoken\tlkj123poi@c2.testrun.org @@ -101,7 +102,7 @@ class MetadataDictProxy(DictProxy): return f"O{self.iroh_relay}\n" case "turn": try: - res = turn_credentials() + res = turn_credentials(self.turn_socket_path) except Exception: logging.exception("failed to get TURN credentials") return "N\n" @@ -135,6 +136,7 @@ def main(): config = read_config(config_path) iroh_relay = config.iroh_relay mail_domain = config.mail_domain + socket_path = config.turn_socket_path vmail_dir = config.mailboxes_dir if not vmail_dir.exists(): @@ -152,6 +154,7 @@ def main(): metadata=metadata, iroh_relay=iroh_relay, turn_hostname=mail_domain, + turn_socket_path=socket_path, ) dictproxy.serve_forever_from_socket(socket) diff --git a/chatmaild/src/chatmaild/turnserver.py b/chatmaild/src/chatmaild/turnserver.py index a82cfc97..91557542 100644 --- a/chatmaild/src/chatmaild/turnserver.py +++ b/chatmaild/src/chatmaild/turnserver.py @@ -2,9 +2,9 @@ import socket -def turn_credentials() -> str: +def turn_credentials(turn_socket_path) -> str: with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client_socket: client_socket.settimeout(5) - client_socket.connect("/run/chatmail-turn/turn.socket") + client_socket.connect(turn_socket_path) with client_socket.makefile("rb") as file: return file.readline().decode("utf-8").strip()