Philipp Hörist pushed to branch master at gajim / gajim

Commits:

4 changed files:

Changes:

  • gajim/common/connection.py
    ... ... @@ -595,6 +595,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    595 595
                 self.retrycount = 0
    
    596 596
     
    
    597 597
         def disconnect(self, reconnect=True, immediately=False):
    
    598
    +        self.get_module('Ping').remove_timeout()
    
    598 599
             if self.connection is None:
    
    599 600
                 if not reconnect:
    
    600 601
                     self._sm_resume_data = {}
    

  • gajim/common/connection_handlers.py
    ... ... @@ -24,27 +24,26 @@
    24 24
     # You should have received a copy of the GNU General Public License
    
    25 25
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    26 26
     
    
    27
    +import logging
    
    27 28
     import operator
    
    28
    -from time import time as time_time
    
    29
    +import time
    
    29 30
     
    
    30 31
     import nbxmpp
    
    31 32
     
    
    32
    -from gajim.common import modules
    
    33
    -from gajim.common import helpers
    
    34 33
     from gajim.common import app
    
    34
    +from gajim.common import ged
    
    35
    +from gajim.common import helpers
    
    35 36
     from gajim.common import jingle_xtls
    
    37
    +from gajim.common import modules
    
    36 38
     from gajim.common.caps_cache import muc_caps_cache
    
    37
    -from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
    
    38
    -from gajim.common.protocol.bytestream import ConnectionIBBytestream
    
    39 39
     from gajim.common.connection_handlers_events import *
    
    40
    -
    
    41
    -from gajim.common import ged
    
    42
    -from gajim.common.nec import NetworkEvent
    
    43 40
     from gajim.common.const import KindConstant
    
    44
    -
    
    45 41
     from gajim.common.jingle import ConnectionJingle
    
    42
    +from gajim.common.nec import NetworkEvent
    
    43
    +from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
    
    44
    +from gajim.common.protocol.bytestream import ConnectionIBBytestream
    
    45
    +
    
    46 46
     
    
    47
    -import logging
    
    48 47
     log = logging.getLogger('gajim.c.connection_handlers')
    
    49 48
     
    
    50 49
     # kind of events we can wait for an answer
    
    ... ... @@ -193,7 +192,7 @@ class ConnectionHandlersBase:
    193 192
                 if show is not None:
    
    194 193
                     app.logger.insert_into_logs(self.name,
    
    195 194
                                                 nbxmpp.JID(obj.jid).getStripped(),
    
    196
    -                                            time_time(),
    
    195
    +                                            time.time(),
    
    197 196
                                                 KindConstant.STATUS,
    
    198 197
                                                 message=obj.status,
    
    199 198
                                                 show=show)
    

  • gajim/common/modules/ping.py
    ... ... @@ -21,6 +21,7 @@ import logging
    21 21
     import time
    
    22 22
     
    
    23 23
     import nbxmpp
    
    24
    +from gi.repository import GLib
    
    24 25
     
    
    25 26
     from gajim.common import app
    
    26 27
     from gajim.common.nec import NetworkIncomingEvent
    
    ... ... @@ -34,7 +35,7 @@ class Ping:
    34 35
         def __init__(self, con: ConnectionT) -> None:
    
    35 36
             self._con = con
    
    36 37
             self._account = con.name
    
    37
    -        self._alarm_time = None
    
    38
    +        self._timeout_id = None
    
    38 39
     
    
    39 40
             self.handlers = [
    
    40 41
                 ('iq', self._answer_request, 'get', nbxmpp.NS_PING),
    
    ... ... @@ -50,19 +51,19 @@ class Ping:
    50 51
             if not app.account_is_connected(self._account):
    
    51 52
                 return
    
    52 53
     
    
    53
    -        to = app.config.get_per('accounts', self._account, 'hostname')
    
    54
    -        self._con.connection.SendAndCallForResponse(self._get_ping_iq(to),
    
    55
    -                                                    self._keepalive_received)
    
    56
    -
    
    57 54
             log.info('Send keepalive')
    
    58 55
     
    
    59 56
             seconds = app.config.get_per('accounts', self._account,
    
    60 57
                                          'time_for_ping_alive_answer')
    
    61
    -        self._alarm_time = app.idlequeue.set_alarm(self._reconnect, seconds)
    
    58
    +        self._timeout_id = GLib.timeout_add_seconds(seconds, self._reconnect)
    
    59
    +
    
    60
    +        to = app.config.get_per('accounts', self._account, 'hostname')
    
    61
    +        self._con.connection.SendAndCallForResponse(self._get_ping_iq(to),
    
    62
    +                                                    self._keepalive_received)
    
    62 63
     
    
    63 64
         def _keepalive_received(self, _stanza: nbxmpp.Iq) -> None:
    
    64 65
             log.info('Received keepalive')
    
    65
    -        app.idlequeue.remove_alarm(self._reconnect, self._alarm_time)
    
    66
    +        self.remove_timeout()
    
    66 67
     
    
    67 68
         def _reconnect(self) -> None:
    
    68 69
             if not app.config.get_per('accounts', self._account, 'active'):
    
    ... ... @@ -118,6 +119,16 @@ class Ping:
    118 119
             log.info('Send pong to %s', stanza.getFrom())
    
    119 120
             raise nbxmpp.NodeProcessed
    
    120 121
     
    
    122
    +    def remove_timeout(self) -> None:
    
    123
    +        if self._timeout_id is None:
    
    124
    +            return
    
    125
    +        log.info('Remove ping timeout')
    
    126
    +        GLib.source_remove(self._timeout_id)
    
    127
    +        self._timeout_id = None
    
    128
    +
    
    129
    +    def cleanup(self) -> None:
    
    130
    +        self.remove_timeout()
    
    131
    +
    
    121 132
     
    
    122 133
     class PingSentEvent(NetworkIncomingEvent):
    
    123 134
         name = 'ping-sent'
    

  • gajim/common/zeroconf/connection_zeroconf.py
    ... ... @@ -27,24 +27,17 @@
    27 27
     # You should have received a copy of the GNU General Public License
    
    28 28
     # along with Gajim.  If not, see <http://www.gnu.org/licenses/>.
    
    29 29
     
    
    30
    -import os
    
    31 30
     import socket
    
    32
    -import random
    
    33
    -random.seed()
    
    31
    +import getpass
    
    34 32
     
    
    35 33
     import nbxmpp
    
    36
    -
    
    37
    -import signal
    
    38
    -if os.name != 'nt':
    
    39
    -    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    
    40
    -import getpass
    
    41 34
     from gi.repository import GLib
    
    42 35
     
    
    43
    -from gajim.common.connection import CommonConnection
    
    44 36
     from gajim.common import app
    
    45 37
     from gajim.common import ged
    
    46 38
     from gajim.common import modules
    
    47 39
     from gajim.common.i18n import _
    
    40
    +from gajim.common.connection import CommonConnection
    
    48 41
     from gajim.common.zeroconf import client_zeroconf
    
    49 42
     from gajim.common.zeroconf import zeroconf
    
    50 43
     from gajim.common.zeroconf.connection_handlers_zeroconf import *
    
    ... ... @@ -52,6 +45,7 @@ from gajim.common.connection_handlers_events import *
    52 45
     
    
    53 46
     log = logging.getLogger('gajim.c.connection_zeroconf')
    
    54 47
     
    
    48
    +
    
    55 49
     class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
    
    56 50
         def __init__(self, name):
    
    57 51
             ConnectionHandlersZeroconf.__init__(self)