Merge remote-tracking branch 'origin/mr/28'

Address multiple reconnect issues. Thanks Ge0rG!
This commit is contained in:
Maxime “pep” Buquet 2019-07-29 19:42:53 +02:00
commit d43c8cf878
2 changed files with 25 additions and 14 deletions

View file

@ -256,6 +256,9 @@ class Core:
('roster_update', self.handler.on_roster_update), ('roster_update', self.handler.on_roster_update),
('session_start', self.handler.on_session_start), ('session_start', self.handler.on_session_start),
('session_start', self.handler.on_session_start_features), ('session_start', self.handler.on_session_start_features),
('session_end', self.handler.on_session_end),
('sm_failed', self.handler.on_session_end),
('session_resumed', self.handler.on_session_resumed),
('ssl_cert', self.handler.validate_ssl), ('ssl_cert', self.handler.validate_ssl),
('ssl_invalid_chain', self.handler.ssl_invalid_chain), ('ssl_invalid_chain', self.handler.ssl_invalid_chain),
('stream_error', self.handler.on_stream_error), ('stream_error', self.handler.on_stream_error),
@ -832,16 +835,12 @@ class Core:
parts of the client (for example, set the MucTabs as not joined, etc) parts of the client (for example, set the MucTabs as not joined, etc)
""" """
self.legitimate_disconnect = True self.legitimate_disconnect = True
for tab in self.get_tabs(tabs.MucTab):
tab.command_part(msg)
self.xmpp.disconnect()
if reconnect: if reconnect:
# Add a one-time event to reconnect as soon as we are self.xmpp.reconnect(wait=0.0, reason=msg)
# effectively disconnected else:
self.xmpp.add_event_handler( for tab in self.get_tabs(tabs.MucTab):
'disconnected', tab.command_part(msg)
lambda event: self.xmpp.connect(), self.xmpp.disconnect(reason=msg)
disposable=True)
def send_message(self, msg: str) -> bool: def send_message(self, msg: str) -> bool:
""" """

View file

@ -1152,20 +1152,32 @@ class HandlerCore:
self.core.information( self.core.information(
"Connection to remote server failed: %s" % (error, ), 'Error') "Connection to remote server failed: %s" % (error, ), 'Error')
def on_session_end(self, event):
"""
Called when a session is terminated (e.g. due to a manual disconnect or a 0198 resume fail)
"""
roster.connected = 0
roster.modified()
for tab in self.core.get_tabs(tabs.MucTab):
tab.disconnect()
def on_session_resumed(self, event):
"""
Called when a session is successfully resumed by 0198
"""
self.core.information("Resumed session as %s" % self.core.xmpp.boundjid.full, 'Info')
self.core.xmpp.plugin['xep_0199'].enable_keepalive()
async def on_disconnected(self, event): async def on_disconnected(self, event):
""" """
When we are disconnected from remote server When we are disconnected from remote server
""" """
if 'disconnect' in config.get('beep_on').split(): if 'disconnect' in config.get('beep_on').split():
curses.beep() curses.beep()
roster.connected = 0
# Stop the ping plugin. It would try to send stanza on regular basis # Stop the ping plugin. It would try to send stanza on regular basis
self.core.xmpp.plugin['xep_0199'].disable_keepalive() self.core.xmpp.plugin['xep_0199'].disable_keepalive()
roster.modified()
for tab in self.core.get_tabs(tabs.MucTab):
tab.disconnect()
msg_typ = 'Error' if not self.core.legitimate_disconnect else 'Info' msg_typ = 'Error' if not self.core.legitimate_disconnect else 'Info'
self.core.information("Disconnected from server.", msg_typ) self.core.information("Disconnected from server%s." % (event and ": %s" % event or ""), msg_typ)
if self.core.legitimate_disconnect or not config.get( if self.core.legitimate_disconnect or not config.get(
'auto_reconnect', True): 'auto_reconnect', True):
return return