From 46440d8409dbe50e87c731fd72a0ccffc6383a3f Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 3 May 2026 10:46:23 +0200 Subject: [PATCH] core (xmpp/messages): Optimize and avoir exception on `parse_message`: - When we want to disco a bare JID, disco its server instead, to avoid many uncached requests. In most case, the server disco is enough to discover JID origin. - Avoid exception on `exceptions.ExternalRequestError`, print a warning instead. --- libervia/backend/core/xmpp.py | 46 ++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libervia/backend/core/xmpp.py b/libervia/backend/core/xmpp.py index a62dc8e3..5427bab1 100644 --- a/libervia/backend/core/xmpp.py +++ b/libervia/backend/core/xmpp.py @@ -1649,24 +1649,36 @@ class SatMessageProtocol(xmppim.MessageProtocol): # origin if not from_jid_bare in (client.jid.userhostJID(), client.server_jid): - disco_infos = await G.host.memory.disco.get_infos(client, from_jid_bare) - if from_jid_bare.user: - domain_disco_infos = await G.host.memory.disco.get_infos( - client, jid.JID(from_jid_bare.host) + try: + # For bare JIDs, query the server instead: bare jids are not cached by + # XEP-0115, so we'll have an actual disco request each time. On the other + # hand, server disco is cached after first request, and should gives us + # the gateway/origin info we need. + # FIXME: Check if this cause trouble in practice. + query_jid = from_jid if from_jid.resource else jid.JID(from_jid.host) + disco_infos = await G.host.memory.disco.get_infos(client, query_jid) + if from_jid_bare.user: + domain_disco_infos = await G.host.memory.disco.get_infos( + client, jid.JID(from_jid_bare.host) + ) + else: + domain_disco_infos = disco_infos + if ("client", "bot") in disco_infos.identities: + extra["is-bot"] = True + for ( + category, + type_, + ), identities_map in domain_disco_infos.identities.items(): + for lang, identity in identities_map.items(): + if category == "gateway": + extra["origin"] = identity.type + if identity.name: + extra["origin_name"] = identity.name + except exceptions.ExternalRequestError: + log.warning( + f"Disco query failed for {from_jid.full()}, skipping identity " + "detection" ) - else: - domain_disco_infos = disco_infos - if ("client", "bot") in disco_infos.identities: - extra["is-bot"] = True - for ( - category, - type_, - ), identities_map in domain_disco_infos.identities.items(): - for lang, identity in identities_map.items(): - if category == "gateway": - extra["origin"] = identity.type - if identity.name: - extra["origin_name"] = identity.name # message for e in message_elt.elements(C.NS_CLIENT, "body"):