Add support for reconnecting based on see-other-host stream errors.
This commit is contained in:
parent
c2c7cc032b
commit
85ef2d8d0b
@ -134,6 +134,7 @@ class BaseXMPP(XMLStream):
|
|||||||
Callback('Presence',
|
Callback('Presence',
|
||||||
MatchXPath("{%s}presence" % self.default_ns),
|
MatchXPath("{%s}presence" % self.default_ns),
|
||||||
self._handle_presence))
|
self._handle_presence))
|
||||||
|
|
||||||
self.register_handler(
|
self.register_handler(
|
||||||
Callback('Stream Error',
|
Callback('Stream Error',
|
||||||
MatchXPath("{%s}error" % self.stream_ns),
|
MatchXPath("{%s}error" % self.stream_ns),
|
||||||
@ -658,6 +659,27 @@ class BaseXMPP(XMLStream):
|
|||||||
def _handle_stream_error(self, error):
|
def _handle_stream_error(self, error):
|
||||||
self.event('stream_error', error)
|
self.event('stream_error', error)
|
||||||
|
|
||||||
|
if error['condition'] == 'see-other-host':
|
||||||
|
other_host = error['see_other_host']
|
||||||
|
|
||||||
|
host = other_host
|
||||||
|
port = 5222
|
||||||
|
|
||||||
|
if '[' in other_host and ']' in other_host:
|
||||||
|
host = other_host.split(']')[0][1:]
|
||||||
|
elif ':' in other_host:
|
||||||
|
host = other_host.split(':')[0]
|
||||||
|
|
||||||
|
port_sec = other_host.split(']')[-1]
|
||||||
|
if ':' in port_sec:
|
||||||
|
port = int(port_sec.split(':')[1])
|
||||||
|
|
||||||
|
self.address = (host, port)
|
||||||
|
self.default_domain = host
|
||||||
|
self.dns_records = None
|
||||||
|
self.reconnect_delay = None
|
||||||
|
self.reconnect()
|
||||||
|
|
||||||
def _handle_message(self, msg):
|
def _handle_message(self, msg):
|
||||||
"""Process incoming message stanzas."""
|
"""Process incoming message stanzas."""
|
||||||
if not self.is_component and not msg['to'].bare:
|
if not self.is_component and not msg['to'].bare:
|
||||||
|
Loading…
Reference in New Issue
Block a user