better handling of sessions in zeroconf. Fixes #4529

This commit is contained in:
Yann Leboulanger 2008-11-28 15:34:56 +00:00
parent 9963bea638
commit df1e5ee990
3 changed files with 31 additions and 19 deletions

View File

@ -164,10 +164,11 @@ class P2PClient(IdleObject):
if on_not_ok:
on_not_ok('Connection to host could not be established.')
return
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
self.conn_holder.number_of_awaiting_messages[self.fd] += 1
id = stanza.getThread()
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
else:
self.conn_holder.number_of_awaiting_messages[self.fd] = 1
self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
def add_stanza(self, stanza, is_message=False):
if self.Connection:
@ -178,15 +179,16 @@ class P2PClient(IdleObject):
self.stanzaqueue.append((stanza, is_message))
if is_message:
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
self.conn_holder.number_of_awaiting_messages[self.fd] += 1
id = stanza.getThread()
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
else:
self.conn_holder.number_of_awaiting_messages[self.fd] = 1
self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
return True
def on_message_sent(self, connection_id):
self.conn_holder.number_of_awaiting_messages[connection_id] -= 1
self.conn_holder.ids_of_awaiting_messages[connection_id].pop(0)
def on_connect(self, conn):
self.Connection = conn
@ -245,8 +247,8 @@ class P2PClient(IdleObject):
def on_disconnect(self):
if self.conn_holder:
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
del self.conn_holder.number_of_awaiting_messages[self.fd]
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
del self.conn_holder.ids_of_awaiting_messages[self.fd]
self.conn_holder.remove_connection(self.sock_hash)
if self.__dict__.has_key('Dispatcher'):
self.Dispatcher.PlugOut()
@ -402,11 +404,11 @@ class P2PConnection(IdleObject, PlugIn):
self._plug_idle()
def read_timeout(self):
if self.client.conn_holder.number_of_awaiting_messages.has_key(self.fd) \
and self.client.conn_holder.number_of_awaiting_messages[self.fd] > 0:
self.client._caller.dispatch('MSGERROR',[unicode(self.client.to), -1,
_('Connection to host could not be established: Timeout while sending data.'), None, None])
self.client.conn_holder.number_of_awaiting_messages[self.fd] = 0
ids = self.client.conn_holder.ids_of_awaiting_messages
if self.fd in ids and len(ids[self.fd]) > 0:
for id in ids[self.fd]:
self._owner.Dispatcher.Event('', DATA_ERROR, (self.client.to, id))
ids[self.fd] = []
self.pollend()
def do_connect(self):
@ -577,7 +579,7 @@ class ClientZeroconf:
self.ip_to_hash = {}
self.hash_to_port = {}
self.listener = None
self.number_of_awaiting_messages = {}
self.ids_of_awaiting_messages = {}
def connect(self, show, msg):
self.port = self.start_listener(self.caller.port)

View File

@ -376,7 +376,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
return
if self.status in ('invisible', 'offline'):
self.dispatch('MSGERROR', [unicode(jid), '-1', _('You are not connected or not visible to others. Your message could not be sent.'), None, None])
self.dispatch('MSGERROR', [unicode(jid), -1,
_('You are not connected or not visible to others. Your message '
'could not be sent.'), None, None, session])
return
msgtxt = msg
@ -475,13 +477,13 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
def on_send_not_ok(reason):
reason += ' ' + _('Your message could not be sent.')
self.dispatch('MSGERROR', [jid, '-1', reason, None, None, session])
self.dispatch('MSGERROR', [jid, -1, reason, None, None, session])
ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
on_not_ok=on_send_not_ok)
if ret == -1:
# Contact Offline
self.dispatch('MSGERROR', [jid, '-1', _('Contact is offline. Your message could not be sent.'), None, None, session])
self.dispatch('MSGERROR', [jid, -1, _('Contact is offline. Your message could not be sent.'), None, None, session])
return ret
def send_stanza(self, stanza):
@ -573,6 +575,13 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.dispatch('STANZA_ARRIVED', unicode(data, errors = 'ignore'))
elif event == common.xmpp.transports.DATA_SENT:
self.dispatch('STANZA_SENT', unicode(data))
elif event == common.xmpp.transports.DATA_ERROR:
thread_id = data[1]
frm = unicode(data[0])
session = self.get_or_create_session(frm, thread_id)
self.dispatch('MSGERROR', [frm, -1,
_('Connection to host could not be established: Timeout while '
'sending data.'), None, None, session])
# END ConnectionZeroconf

View File

@ -947,7 +947,8 @@ class Interface:
if array[3]:
msg = _('error while sending %(message)s ( %(error)s )') % {
'message': array[3], 'error': msg}
array[5].roster_message(jid, msg, array[4], msg_type='error')
if session:
session.roster_message(jid, msg, array[4], msg_type='error')
def handle_event_msgsent(self, account, array):
#('MSGSENT', account, (jid, msg, keyID))