summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-06-18 20:37:57 +0200
committerFlorent Le Coz <louiz@louiz.org>2013-06-18 20:37:57 +0200
commit4d73c29836b2c74253dbce0df7af4d976440217f (patch)
tree4c59bd583f5ca83e28a47a0c77a45b30a0985081 /src
parent39fa811374b7119173120175e70fb4f197bc0aba (diff)
downloadpoezio-4d73c29836b2c74253dbce0df7af4d976440217f.tar.gz
poezio-4d73c29836b2c74253dbce0df7af4d976440217f.tar.bz2
poezio-4d73c29836b2c74253dbce0df7af4d976440217f.tar.xz
poezio-4d73c29836b2c74253dbce0df7af4d976440217f.zip
Add config_change handlers for the two keepalive options
We can now change the keepalive values with /set, without restarting
Diffstat (limited to 'src')
-rw-r--r--src/connection.py25
-rw-r--r--src/core.py2
2 files changed, 20 insertions, 7 deletions
diff --git a/src/connection.py b/src/connection.py
index 0db7acad..d6b3fca0 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -72,13 +72,8 @@ class Connection(sleekxmpp.ClientXMPP):
self.register_plugin('xep_0085')
self.register_plugin('xep_0115')
self.register_plugin('xep_0191')
- ping_interval = config.get('connection_check_interval', 60)
- if ping_interval <= 0:
- ping_interval = 60
- timeout_delay = config.get('connection_timeout_delay', 10)
- if timeout_delay <= 0:
- timeout_delay = 10
- self.register_plugin('xep_0199', pconfig={'keepalive': True, 'interval': ping_interval, 'timeout': timeout_delay})
+ self.register_plugin('xep_0199')
+ self.set_keepalive_values()
if config.get('enable_user_tune', 'true') != 'false':
self.register_plugin('xep_0118')
@@ -112,6 +107,22 @@ class Connection(sleekxmpp.ClientXMPP):
self.register_plugin('xep_0297')
self.register_plugin('xep_0308')
+ def set_keepalive_values(self, option=None, value=None):
+ """
+ Called at startup, or triggered when one of
+ "connection_timeout_delay" and "connection_check_interval" options
+ is changed.
+ Unload and reload the ping plugin, with the new values.
+ """
+ ping_interval = config.get('connection_check_interval', 60)
+ if ping_interval <= 0:
+ ping_interval = 60
+ timeout_delay = config.get('connection_timeout_delay', 10)
+ if timeout_delay <= 0:
+ timeout_delay = 10
+ self.plugin['xep_0199'].disable_keepalive()
+ self.plugin['xep_0199'].enable_keepalive(ping_interval, timeout_delay)
+
def start(self):
# TODO, try multiple servers
# With anon auth.
diff --git a/src/core.py b/src/core.py
index 9476bd42..c330bbde 100644
--- a/src/core.py
+++ b/src/core.py
@@ -299,6 +299,8 @@ class Core(object):
self.add_configuration_handler("create_gaps", self.on_gaps_config_change)
self.add_configuration_handler("plugins_dir", self.on_plugins_dir_config_change)
self.add_configuration_handler("plugins_conf_dir", self.on_plugins_conf_dir_config_change)
+ self.add_configuration_handler("connection_timeout_delay", self.xmpp.set_keepalive_values)
+ self.add_configuration_handler("connection_check_interval", self.xmpp.set_keepalive_values)
self.add_configuration_handler("", self.on_any_config_change)
def on_any_config_change(self, option, value):