diff --git a/matrix/_weechat.py b/matrix/_weechat.py index d8b8356..3dd422e 100644 --- a/matrix/_weechat.py +++ b/matrix/_weechat.py @@ -75,6 +75,8 @@ class MockConfig(object): 'print_unconfirmed_messages': None, 'read_markers_conditions': None, 'typing_notice_conditions': None, + 'autoreconnect_delay_growing': None, + 'autoreconnect_delay_max': None, }, } diff --git a/matrix/config.py b/matrix/config.py index 82063d2..209ac90 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -629,6 +629,26 @@ class MatrixConfig(WeechatConfig): ("Reconnect to the server if the lag is greater than this " "value (in seconds)"), ), + Option( + "autoreconnect_delay_growing", + "integer", + "", + 1, + 100, + "2", + ("growing factor for autoreconnect delay to server " + "(1 = always same delay, 2 = delay*2 for each retry, etc.)"), + ), + Option( + "autoreconnect_delay_max", + "integer", + "", + 0, + 604800, + "600", + ("maximum autoreconnect delay to server " + "(in seconds, 0 = no maximum)"), + ), Option( "print_unconfirmed_messages", "boolean", diff --git a/matrix/server.py b/matrix/server.py index 9ac47c1..1ef69c4 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -671,10 +671,17 @@ class MatrixServer(object): self.reconnect_time = time.time() if self.reconnect_delay: - self.reconnect_delay = self.reconnect_delay * 2 + self.reconnect_delay = ( + self.reconnect_delay + * G.CONFIG.network.autoreconnect_delay_growing + ) else: self.reconnect_delay = self.config.reconnect_delay + if G.CONFIG.network.autoreconnect_delay_max > 0: + self.reconnect_delay = min(self.reconnect_delay, + G.CONFIG.network.autoreconnect_delay_max) + message = ( "{prefix}matrix: reconnecting to server in {t} " "seconds" ).format(prefix=W.prefix("network"), t=self.reconnect_delay)