Mercurial > libervia-backend
changeset 2727:59ac9284dee8
plugin XEP-0198: allow to customise/disable ack_timeout:
"ack_timeout" setting can be set in [DEFAULT] section to the number of seconds before timing out, or to 0 to disable the timeout.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Dec 2018 17:21:38 +0100 (2018-12-26) |
parents | a86f494457c2 |
children | 1b11da85492c |
files | sat/plugins/plugin_xep_0198.py |
diffstat | 1 files changed, 20 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0198.py Wed Dec 26 17:18:52 2018 +0100 +++ b/sat/plugins/plugin_xep_0198.py Wed Dec 26 17:21:38 2018 +0100 @@ -60,7 +60,7 @@ MAX_COUNTER = 2**32 RESUME_MAX = 5*60 # if we don't have an answer to ACK REQUEST after this delay, connection is aborted -ACK_R_TIMEOUT = 25 +ACK_TIMEOUT = 25 class ProfileSessionData(object): @@ -129,6 +129,16 @@ host.trigger.add("xml_init", self._XMLInitTrigger) host.trigger.add("disconnecting", self._disconnectingTrigger) host.trigger.add("disconnected", self._disconnectedTrigger) + try: + self._ack_timeout = int(host.memory.getConfig("", "ack_timeout", ACK_TIMEOUT)) + except ValueError: + log.error(_(u"Invalid ack_timeout value, please check your configuration")) + self._ack_timeout = ACK_TIMEOUT + if not self._ack_timeout: + log.info(_(u"Ack timeout disabled")) + else: + log.info(_(u"Ack timeout set to {timeout} s").format( + timeout=self._ack_timeout)) def profileConnecting(self, client): client._xep_0198_session = ProfileSessionData(callback=self.checkAcks, @@ -240,7 +250,9 @@ client.send(r_elt) if session.req_timer is not None: raise exceptions.InternalError("req_timer should not be set") - session.req_timer = reactor.callLater(ACK_R_TIMEOUT, self.onAckTimeOut, client) + if self._ack_timeout: + session.req_timer = reactor.callLater(self._ack_timeout, self.onAckTimeOut, + client) def _connectionFailed(self, failure_, connector): normal_host, normal_port = connector.normal_location @@ -413,11 +425,12 @@ def onAckAnswer(self, a_elt, client): session = client._xep_0198_session session.ack_requested = False - if session.req_timer is None: - log.error("reg_timer should be set") - else: - session.req_timer.cancel() - session.req_timer = None + if self._ack_timeout: + if session.req_timer is None: + log.error("reg_timer should be set") + else: + session.req_timer.cancel() + session.req_timer = None try: server_acked = int(a_elt['h']) except ValueError: