From 6d4e67748c9816c31d52bf51cb376dc33385a3ff Mon Sep 17 00:00:00 2001 From: kc1awv Date: Wed, 31 Dec 2025 07:12:08 -0500 Subject: [PATCH] Enhance HELLO message handling to support re-authentication and reset session state --- rrcd/service.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/rrcd/service.py b/rrcd/service.py index 7ccf5eb..9c0e108 100644 --- a/rrcd/service.py +++ b/rrcd/service.py @@ -2168,8 +2168,28 @@ class HubService: return if t == T_HELLO: + # Allow re-authentication if client reconnects with same Link ID + # (can happen when client restarts but RNS reuses deterministic link_id) if self.identity is not None: - self._emit_error(outgoing, link, src=self.identity.hash, text="HELLO already sent") + # Reset session state and process as new HELLO + sess["welcomed"] = False + sess["rooms"] = set() + sess["nick"] = None + + # Process the HELLO message + if isinstance(body, dict): + nick = body.get(B_HELLO_NICK) + n = normalize_nick(nick, max_chars=self.config.nick_max_chars) + if n is not None: + sess["nick"] = n + + # Send WELCOME + sess["welcomed"] = True + body_w: dict[int, Any] = {B_WELCOME_HUB: self.config.hub_name} + if self.config.greeting: + body_w[B_WELCOME_GREETING] = self.config.greeting + welcome = make_envelope(T_WELCOME, src=self.identity.hash, body=body_w) + self._queue_env(outgoing, link, welcome) return if t == T_JOIN: