correctly handle see-other-host (earlier in the connection process). Fixes #7179

This commit is contained in:
Yann Leboulanger 2012-06-19 19:19:24 +02:00
parent a51bf035cd
commit 449f137dd7
6 changed files with 23 additions and 7 deletions

View file

@ -1134,6 +1134,10 @@ class Connection(CommonConnection, ConnectionHandlers):
self._disconnectedReconnCB() self._disconnectedReconnCB()
def connect_to_next_type(self, retry=False): def connect_to_next_type(self, retry=False):
if self.redirected:
self.disconnect(on_purpose=True)
self.connect()
return
if len(self._connection_types): if len(self._connection_types):
self._current_type = self._connection_types.pop(0) self._current_type = self._connection_types.pop(0)
if self.last_connection: if self.last_connection:
@ -1194,6 +1198,7 @@ class Connection(CommonConnection, ConnectionHandlers):
on_connect=self.on_connect_success, on_connect=self.on_connect_success,
on_proxy_failure=self.on_proxy_failure, on_proxy_failure=self.on_proxy_failure,
on_connect_failure=self.connect_to_next_type, on_connect_failure=self.connect_to_next_type,
on_stream_error_cb=self._StreamCB,
proxy=self._proxy, proxy=self._proxy,
secure_tuple = secure_tuple) secure_tuple = secure_tuple)

View file

@ -1257,6 +1257,7 @@ ConnectionJingle, ConnectionIBBytestream):
PrivateStorageRosternotesReceivedEvent) PrivateStorageRosternotesReceivedEvent)
gajim.nec.register_incoming_event(RosternotesReceivedEvent) gajim.nec.register_incoming_event(RosternotesReceivedEvent)
gajim.nec.register_incoming_event(StreamConflictReceivedEvent) gajim.nec.register_incoming_event(StreamConflictReceivedEvent)
gajim.nec.register_incoming_event(StreamOtherHostReceivedEvent)
gajim.nec.register_incoming_event(MessageReceivedEvent) gajim.nec.register_incoming_event(MessageReceivedEvent)
gajim.nec.register_incoming_event(ArchivingErrorReceivedEvent) gajim.nec.register_incoming_event(ArchivingErrorReceivedEvent)
gajim.nec.register_incoming_event( gajim.nec.register_incoming_event(
@ -2018,8 +2019,6 @@ ConnectionJingle, ConnectionIBBytestream):
if obj.conn.name != self.name: if obj.conn.name != self.name:
return return
self.redirected = obj.redirected self.redirected = obj.redirected
self.disconnect(on_purpose=True)
self.connect()
def _StreamCB(self, con, obj): def _StreamCB(self, con, obj):
log.debug('StreamCB') log.debug('StreamCB')

View file

@ -680,8 +680,10 @@ class StreamOtherHostReceivedEvent(nec.NetworkIncomingEvent):
base_network_events = ['stream-received'] base_network_events = ['stream-received']
def generate(self): def generate(self):
other_host = obj.getTag('see-other-host') self.conn = self.base_event.conn
if other_host and self.conn.last_connection_type in ('ssl', 'tls'): self.stanza = self.base_event.stanza
other_host = self.stanza.getTag('see-other-host')
if other_host and self.conn._current_type in ('ssl', 'tls'):
host = other_host.getData() host = other_host.getData()
if ':' in host: if ':' in host:
host_l = host.split(':', 1) host_l = host.split(':', 1)

View file

@ -63,6 +63,7 @@ class CommonResolver():
self.handlers = {} self.handlers = {}
def resolve(self, host, on_ready, type='srv'): def resolve(self, host, on_ready, type='srv'):
host = host.lower()
log.debug('resolve %s type=%s' % (host, type)) log.debug('resolve %s type=%s' % (host, type))
assert(type in ['srv', 'txt']) assert(type in ['srv', 'txt'])
if not host: if not host:
@ -88,6 +89,7 @@ class CommonResolver():
def _on_ready(self, host, type, result_list): def _on_ready(self, host, type, result_list):
# practically it is impossible to be the opposite, but who knows :) # practically it is impossible to be the opposite, but who knows :)
host = host.lower()
log.debug('Resolving result for %s: %s' % (host, result_list)) log.debug('Resolving result for %s: %s' % (host, result_list))
if not self.resolved_hosts.has_key(host+type): if not self.resolved_hosts.has_key(host+type):
self.resolved_hosts[host+type] = result_list self.resolved_hosts[host+type] = result_list

View file

@ -67,6 +67,7 @@ class NonBlockingClient:
self.on_connect_failure = None self.on_connect_failure = None
self.proxy = None self.proxy = None
self.got_features = False self.got_features = False
self.got_see_other_host = None
self.stream_started = False self.stream_started = False
self.disconnecting = False self.disconnecting = False
self.protocol_type = 'XMPP' self.protocol_type = 'XMPP'
@ -138,8 +139,8 @@ class NonBlockingClient:
self.disconnecting = False self.disconnecting = False
def connect(self, on_connect, on_connect_failure, hostname=None, port=5222, def connect(self, on_connect, on_connect_failure, hostname=None, port=5222,
on_proxy_failure=None, proxy=None, secure_tuple=('plain', None, on_proxy_failure=None, on_stream_error_cb=None, proxy=None,
None)): secure_tuple=('plain', None, None)):
""" """
Open XMPP connection (open XML streams in both directions) Open XMPP connection (open XML streams in both directions)
@ -161,6 +162,7 @@ class NonBlockingClient:
self.on_connect = on_connect self.on_connect = on_connect
self.on_connect_failure=on_connect_failure self.on_connect_failure=on_connect_failure
self.on_proxy_failure = on_proxy_failure self.on_proxy_failure = on_proxy_failure
self.on_stream_error_cb = on_stream_error_cb
self.desired_security, self.cacerts, self.mycerts = secure_tuple self.desired_security, self.cacerts, self.mycerts = secure_tuple
self.Connection = None self.Connection = None
self.Port = port self.Port = port
@ -350,7 +352,10 @@ class NonBlockingClient:
# sometimes <features> are received together with document # sometimes <features> are received together with document
# attributes and sometimes on next receive... # attributes and sometimes on next receive...
self.Dispatcher.ProcessNonBlocking(data) self.Dispatcher.ProcessNonBlocking(data)
if not self.got_features: if self.got_see_other_host:
log.info('got see-other-host')
self.on_stream_error_cb(self, self.got_see_other_host)
elif not self.got_features:
self._xmpp_connect_machine( self._xmpp_connect_machine(
mode='FAILURE', mode='FAILURE',
data='Missing <features> in 1.0 stream') data='Missing <features> in 1.0 stream')

View file

@ -415,6 +415,9 @@ class XMPPDispatcher(PlugIn):
if name == 'features': if name == 'features':
self._owner.got_features = True self._owner.got_features = True
session.Stream.features = stanza session.Stream.features = stanza
if name == 'error':
if stanza.getTag('see-other-host'):
self._owner.got_see_other_host = stanza
xmlns = stanza.getNamespace() xmlns = stanza.getNamespace()