Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chatmaild/src/chatmaild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, inipath, params):
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
Expand Down
5 changes: 4 additions & 1 deletion chatmaild/src/chatmaild/ini/chatmail.ini.f
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
# 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

Expand Down
7 changes: 5 additions & 2 deletions chatmaild/src/chatmaild/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ def get_tokens_for_addr(self, addr):


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
Expand All @@ -101,7 +102,7 @@ def handle_lookup(self, parts):
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"
Expand Down Expand Up @@ -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():
Expand All @@ -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)
4 changes: 2 additions & 2 deletions chatmaild/src/chatmaild/turnserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading