Philipp Hörist pushed to branch master at gajim / gajim
Commits: 4968fe39 by Philipp Hörist at 2018-12-05T16:03:34Z Correctly remove ping timeout
Fixes #9481
- - - - - e419f752 by Philipp Hörist at 2018-12-05T16:05:10Z Remove unused imports
- - - - - a979874f by Philipp Hörist at 2018-12-05T16:05:29Z Sort imports
- - - - -
4 changed files:
- gajim/common/connection.py - gajim/common/connection_handlers.py - gajim/common/modules/ping.py - gajim/common/zeroconf/connection_zeroconf.py
Changes:
===================================== gajim/common/connection.py ===================================== @@ -595,6 +595,7 @@ class Connection(CommonConnection, ConnectionHandlers): self.retrycount = 0
def disconnect(self, reconnect=True, immediately=False): + self.get_module('Ping').remove_timeout() if self.connection is None: if not reconnect: self._sm_resume_data = {}
===================================== gajim/common/connection_handlers.py ===================================== @@ -24,27 +24,26 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+import logging import operator -from time import time as time_time +import time
import nbxmpp
-from gajim.common import modules -from gajim.common import helpers from gajim.common import app +from gajim.common import ged +from gajim.common import helpers from gajim.common import jingle_xtls +from gajim.common import modules from gajim.common.caps_cache import muc_caps_cache -from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream -from gajim.common.protocol.bytestream import ConnectionIBBytestream from gajim.common.connection_handlers_events import * - -from gajim.common import ged -from gajim.common.nec import NetworkEvent from gajim.common.const import KindConstant - from gajim.common.jingle import ConnectionJingle +from gajim.common.nec import NetworkEvent +from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream +from gajim.common.protocol.bytestream import ConnectionIBBytestream +
-import logging log = logging.getLogger('gajim.c.connection_handlers')
# kind of events we can wait for an answer @@ -193,7 +192,7 @@ class ConnectionHandlersBase: if show is not None: app.logger.insert_into_logs(self.name, nbxmpp.JID(obj.jid).getStripped(), - time_time(), + time.time(), KindConstant.STATUS, message=obj.status, show=show)
===================================== gajim/common/modules/ping.py ===================================== @@ -21,6 +21,7 @@ import logging import time
import nbxmpp +from gi.repository import GLib
from gajim.common import app from gajim.common.nec import NetworkIncomingEvent @@ -34,7 +35,7 @@ class Ping: def __init__(self, con: ConnectionT) -> None: self._con = con self._account = con.name - self._alarm_time = None + self._timeout_id = None
self.handlers = [ ('iq', self._answer_request, 'get', nbxmpp.NS_PING), @@ -50,19 +51,19 @@ class Ping: if not app.account_is_connected(self._account): return
- to = app.config.get_per('accounts', self._account, 'hostname') - self._con.connection.SendAndCallForResponse(self._get_ping_iq(to), - self._keepalive_received) - log.info('Send keepalive')
seconds = app.config.get_per('accounts', self._account, 'time_for_ping_alive_answer') - self._alarm_time = app.idlequeue.set_alarm(self._reconnect, seconds) + self._timeout_id = GLib.timeout_add_seconds(seconds, self._reconnect) + + to = app.config.get_per('accounts', self._account, 'hostname') + self._con.connection.SendAndCallForResponse(self._get_ping_iq(to), + self._keepalive_received)
def _keepalive_received(self, _stanza: nbxmpp.Iq) -> None: log.info('Received keepalive') - app.idlequeue.remove_alarm(self._reconnect, self._alarm_time) + self.remove_timeout()
def _reconnect(self) -> None: if not app.config.get_per('accounts', self._account, 'active'): @@ -118,6 +119,16 @@ class Ping: log.info('Send pong to %s', stanza.getFrom()) raise nbxmpp.NodeProcessed
+ def remove_timeout(self) -> None: + if self._timeout_id is None: + return + log.info('Remove ping timeout') + GLib.source_remove(self._timeout_id) + self._timeout_id = None + + def cleanup(self) -> None: + self.remove_timeout() +
class PingSentEvent(NetworkIncomingEvent): name = 'ping-sent'
===================================== gajim/common/zeroconf/connection_zeroconf.py ===================================== @@ -27,24 +27,17 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
-import os import socket -import random -random.seed() +import getpass
import nbxmpp - -import signal -if os.name != 'nt': - signal.signal(signal.SIGPIPE, signal.SIG_DFL) -import getpass from gi.repository import GLib
-from gajim.common.connection import CommonConnection from gajim.common import app from gajim.common import ged from gajim.common import modules from gajim.common.i18n import _ +from gajim.common.connection import CommonConnection from gajim.common.zeroconf import client_zeroconf from gajim.common.zeroconf import zeroconf from gajim.common.zeroconf.connection_handlers_zeroconf import * @@ -52,6 +45,7 @@ from gajim.common.connection_handlers_events import *
log = logging.getLogger('gajim.c.connection_zeroconf')
+ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf): def __init__(self, name): ConnectionHandlersZeroconf.__init__(self)
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/62253c804ab7d0378ddf778f07a0923e46...