you can now disable keepalives; we know now if keepalive disconnected us; experts can change the seconds for keepalive stuff
This commit is contained in:
parent
ad05a9d1de
commit
d29bbbee55
|
@ -131,6 +131,13 @@ class Config:
|
|||
'sync_with_global_status': [ opt_bool, False ],
|
||||
'no_log_for': [ opt_str, '' ],
|
||||
'attached_gpg_keys': [ opt_str, '' ],
|
||||
'keep_alives_enabled': [ opt_bool, True],
|
||||
# send keepalive every 60 seconds of inactivity
|
||||
'keep_alive_every_foo_secs': [ opt_int, 60 ],
|
||||
# disconnect if 2 minutes have passed and server didn't reply
|
||||
'keep_alive_disconnect_secs': [ opt_int, 120 ],
|
||||
# try for 2 minutes before giving up (aka. timeout after those seconds)
|
||||
'try_connecting_for_foo_secs': [ opt_int, 120 ],
|
||||
}, {}),
|
||||
'statusmsg': ({
|
||||
'message': [ opt_str, '' ],
|
||||
|
|
|
@ -127,8 +127,8 @@ class Connection:
|
|||
self.myVCardID = []
|
||||
self.bookmarks = []
|
||||
self.on_purpose = False
|
||||
self._lastIncome = time.time()
|
||||
self._natSent = False
|
||||
self.last_incoming = time.time()
|
||||
self.keep_alive_sent = False
|
||||
self.password = gajim.config.get_per('accounts', name, 'password')
|
||||
if USE_GPG:
|
||||
self.gpg = GnuPG.GnuPG()
|
||||
|
@ -597,8 +597,8 @@ class Connection:
|
|||
self.dispatch('ERROR_ANSWER', (jid_from, errmsg, errcode))
|
||||
|
||||
def _StanzaArrivedCB(self, con, obj):
|
||||
self._lastIncome = time.time()
|
||||
self._natSent = False
|
||||
self.last_incoming = time.time()
|
||||
self.keep_alive_sent = False
|
||||
|
||||
def _event_dispatcher(self, realm, event, data):
|
||||
if realm == common.xmpp.NS_REGISTER:
|
||||
|
@ -612,6 +612,8 @@ class Connection:
|
|||
hostname = gajim.config.get_per('accounts', self.name, 'hostname')
|
||||
resource = gajim.config.get_per('accounts', self.name, 'resource')
|
||||
usessl = gajim.config.get_per('accounts', self.name, 'usessl')
|
||||
try_connecting_for_foo_secs = gajim.config.get_per('accounts', self.name,
|
||||
'try_connecting_for_foo_secs')
|
||||
|
||||
#create connection if it doesn't already exist
|
||||
if self.connection:
|
||||
|
@ -629,7 +631,7 @@ class Connection:
|
|||
con = common.xmpp.Client(hostname)
|
||||
else:
|
||||
con = common.xmpp.Client(hostname, debug = [])
|
||||
common.xmpp.dispatcher.DefaultTimeout = 45 # wait 45 seconds until you timeout connection
|
||||
common.xmpp.dispatcher.DefaultTimeout = try_connecting_for_foo_secs
|
||||
con.UnregisterDisconnectHandler(con.DisconnectHandler)
|
||||
con.RegisterDisconnectHandler(self._disconnectedCB)
|
||||
|
||||
|
@ -1157,21 +1159,36 @@ class Connection:
|
|||
q = iq.setTag(common.xmpp.NS_REGISTER + ' query').setTag('remove')
|
||||
self.connection.send(iq)
|
||||
|
||||
def send_keepalive(self):
|
||||
# we received nothing for the last foo seconds (60 secs by default)
|
||||
hostname = gajim.config.get_per('accounts', self.name,
|
||||
'hostname')
|
||||
iq = common.xmpp.Iq('get', common.xmpp.NS_LAST, to = hostname)
|
||||
self.connection.send(iq)
|
||||
self.keep_alive_sent = True
|
||||
|
||||
def process(self, timeout):
|
||||
if not self.connection:
|
||||
return
|
||||
if self.connected:
|
||||
try:
|
||||
if time.time() > (self._lastIncome + 60) and not self._natSent:
|
||||
# we received nothing since 1 minute
|
||||
hostname = gajim.config.get_per('accounts', self.name,
|
||||
'hostname')
|
||||
iq = common.xmpp.Iq('get', common.xmpp.NS_LAST, to = hostname)
|
||||
self.connection.send(iq)
|
||||
self._natSent = True
|
||||
if time.time() > self._lastIncome + 105: #1 min + 45 sec for answer
|
||||
self.connection.disconnect()
|
||||
if gajim.config.get_per('accounts', self.name,
|
||||
'keep_alives_enabled'): # do we want keepalives?
|
||||
keep_alive_every_foo_secs = gajim.config.get_per('accounts',
|
||||
self.name,'keep_alive_every_foo_secs')
|
||||
if time.time() > (self.last_incoming + keep_alive_every_foo_secs)\
|
||||
and not self.keep_alive_sent: #should we send keepalive?
|
||||
self.send_keepalive()
|
||||
return
|
||||
|
||||
# did the server reply to the keepalive? if no disconnect
|
||||
keep_alive_disconnect_secs = gajim.config.get_per('accounts',
|
||||
self.name, 'keep_alive_disconnect_secs') # 2 mins by default
|
||||
if time.time() > (self.last_incoming + keep_alive_disconnect_secs):
|
||||
self.connection.disconnect() # disconnect if no answer
|
||||
msg = str(keep_alive_disconnect_secs) +\
|
||||
' seconds have passed and server did not reply to our keepalive. Gajim disconnected from ' + self.name
|
||||
gajim.log.debug(msg)
|
||||
self.connection.Process(timeout)
|
||||
except:
|
||||
gajim.log.debug('error appeared while processing xmpp:')
|
||||
|
|
|
@ -1311,6 +1311,11 @@ _('There was a problem retrieving your GPG secret keys.')).get_response()
|
|||
else:
|
||||
self.xml.get_widget('custom_port_entry').set_text('5222')
|
||||
|
||||
def on_send_keepalive_checkbutton_toggled(self, widget):
|
||||
isactive = widget.get_active()
|
||||
gajim.config.set_per('accounts', self.account,
|
||||
'keep_alives_enabled', isactive)
|
||||
|
||||
def on_custom_host_port_checkbutton_toggled(self, widget):
|
||||
isactive = widget.get_active()
|
||||
self.xml.get_widget('custom_host_port_hbox').set_sensitive(isactive)
|
||||
|
|
|
@ -1338,6 +1338,27 @@
|
|||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="send_keepalive_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">If checked, Gajim will send keep-alive packets so it prevents connection timeout which results in disconnection</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Send keep-alive packets</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">True</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_send_keepalive_checkbutton_toggled" last_modification_time="Sat, 25 Jun 2005 21:29:56 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="custom_host_port_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
|
|
Loading…
Reference in New Issue