# HG changeset patch # User Goffi # Date 1580325681 -3600 # Node ID f3700175c6a354d790acf8ef250dfe1ff9cdcc9f # Parent 60a9e47ef98897cb2f1b573d19d0e6787fd73498 core (xmpp): use a stable resource (sat.[shortuuid]) instead of server one if nothing is specified diff -r 60a9e47ef988 -r f3700175c6a3 sat/core/xmpp.py --- a/sat/core/xmpp.py Wed Jan 29 19:42:02 2020 +0100 +++ b/sat/core/xmpp.py Wed Jan 29 20:21:21 2020 +0100 @@ -22,6 +22,7 @@ import calendar import uuid from functools import partial +import shortuuid from sat.core.i18n import _ from sat.core.constants import Const as C from sat.memory import cache @@ -171,9 +172,31 @@ if profile in host.profiles: raise exceptions.InternalError( f"There is already a profile of name {profile} in host") + + entity_jid_s = yield host.memory.asyncGetParamA( + "JabberID", "Connection", profile_key=profile) + entity_jid = jid.JID(entity_jid_s) + + if not entity_jid.resource and not cls.is_component and entity_jid.user: + # if no resource is specified, we create our own instead of using + # server returned one, as it will then stay stable in case of reconnection. + # we only do that for client and if there is a user part, to let server + # decide for anonymous login + resource_dict = yield host.memory.storage.getPrivates( + "core:xmpp", ["resource"] , profile=profile) + try: + resource = resource_dict["resource"] + except KeyError: + resource = f"{C.APP_NAME_FILE}.{shortuuid.uuid()}" + yield host.memory.storage.setPrivateValue( + "core:xmpp", "resource", resource, profile=profile) + + log.info(_("We'll use the stable resource {resource}").format( + resource=resource)) + entity_jid.resource = resource + entity = host.profiles[profile] = cls( - host, profile, jid.JID(host.memory.getParamA("JabberID", "Connection", - profile_key=profile)), password, + host, profile, entity_jid, password, host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile) or None, port, max_retries,