From ed73e70bb1d2518163a653d3edb3dea4db429c05 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 May 2026 09:40:33 +0000 Subject: [PATCH] feat: deny incoming LXST calls via MESHCHAT_DENY_INCOMING_CALL_HASHES - Parse comma/whitespace-separated hex hashes from env - Match remote identity hash or call/audio destination hash - Wait up to ~5s for remote identify before decision - Tear down link immediately if denied (implements TODO denylist) Co-authored-by: Cursor --- src/backend/audio_call_manager.py | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/backend/audio_call_manager.py b/src/backend/audio_call_manager.py index b277099..9be2b12 100644 --- a/src/backend/audio_call_manager.py +++ b/src/backend/audio_call_manager.py @@ -1,11 +1,28 @@ import asyncio +import os import time -from typing import List +from typing import List, Optional, Set import RNS # todo optionally identity self over link -# todo allowlist/denylist for incoming calls +# Deny incoming calls: comma-separated hex hashes (identity or call/audio destination) in env: +# MESHCHAT_DENY_INCOMING_CALL_HASHES=e6631a6a6886dad4816135bb2aaaf382 + + +def _parse_incoming_call_denylist() -> Optional[Set[str]]: + + raw = os.environ.get("MESHCHAT_DENY_INCOMING_CALL_HASHES", "").strip() + if not raw: + return None + + denied: Set[str] = set() + for part in raw.replace(",", " ").split(): + h = part.strip().lower().strip("<>").strip() + if h: + denied.add(h) + + return denied if denied else None class CallFailedException(Exception): @@ -101,9 +118,33 @@ class AudioCallManager: def register_outgoing_call_callback(self, callback): self.on_outgoing_call_callback = callback + def _should_deny_incoming_call(self, audio_call: AudioCall) -> bool: + + deny = _parse_incoming_call_denylist() + if deny is None: + return False + + # wait briefly for remote identify() after link comes up + for _ in range(50): + remote_identity = audio_call.get_remote_identity() + if remote_identity is not None: + id_hash = remote_identity.hash.hex().lower() + dest_hash = RNS.Destination.hash(remote_identity, "call", "audio").hex().lower() + if id_hash in deny or dest_hash in deny: + return True + return False + time.sleep(0.1) + + return False + # handle incoming calls from audio call receiver def handle_incoming_call(self, audio_call: AudioCall): + if self._should_deny_incoming_call(audio_call): + print("[AudioCallManager] denied incoming call (matches MESHCHAT_DENY_INCOMING_CALL_HASHES)") + audio_call.hangup() + return + # remember it self.audio_calls.append(audio_call)