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.
This commit is contained in:
Goffi 2018-12-26 17:21:38 +01:00
commit 6852b6b677

View file

@ -60,7 +60,7 @@ MAX_DELAY_ACK_R = 30
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 @@ class XEP_0198(object):
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 @@ class XEP_0198(object):
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 @@ class XEP_0198(object):
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: