diff --git a/sat/core/xmpp.py b/sat/core/xmpp.py index ef0ef8a4..58f764b1 100644 --- a/sat/core/xmpp.py +++ b/sat/core/xmpp.py @@ -22,6 +22,7 @@ import time 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 @@ class SatXMPPEntity(object): 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,