better handling of sessions in zeroconf. Fixes #4529
This commit is contained in:
parent
9963bea638
commit
df1e5ee990
|
@ -164,10 +164,11 @@ class P2PClient(IdleObject):
|
||||||
if on_not_ok:
|
if on_not_ok:
|
||||||
on_not_ok('Connection to host could not be established.')
|
on_not_ok('Connection to host could not be established.')
|
||||||
return
|
return
|
||||||
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
|
id = stanza.getThread()
|
||||||
self.conn_holder.number_of_awaiting_messages[self.fd] += 1
|
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
|
||||||
|
self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
|
||||||
else:
|
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):
|
def add_stanza(self, stanza, is_message=False):
|
||||||
if self.Connection:
|
if self.Connection:
|
||||||
|
@ -178,15 +179,16 @@ class P2PClient(IdleObject):
|
||||||
self.stanzaqueue.append((stanza, is_message))
|
self.stanzaqueue.append((stanza, is_message))
|
||||||
|
|
||||||
if is_message:
|
if is_message:
|
||||||
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
|
id = stanza.getThread()
|
||||||
self.conn_holder.number_of_awaiting_messages[self.fd] += 1
|
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
|
||||||
|
self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
|
||||||
else:
|
else:
|
||||||
self.conn_holder.number_of_awaiting_messages[self.fd] = 1
|
self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_message_sent(self, connection_id):
|
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):
|
def on_connect(self, conn):
|
||||||
self.Connection = conn
|
self.Connection = conn
|
||||||
|
@ -245,8 +247,8 @@ class P2PClient(IdleObject):
|
||||||
|
|
||||||
def on_disconnect(self):
|
def on_disconnect(self):
|
||||||
if self.conn_holder:
|
if self.conn_holder:
|
||||||
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
|
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
|
||||||
del self.conn_holder.number_of_awaiting_messages[self.fd]
|
del self.conn_holder.ids_of_awaiting_messages[self.fd]
|
||||||
self.conn_holder.remove_connection(self.sock_hash)
|
self.conn_holder.remove_connection(self.sock_hash)
|
||||||
if self.__dict__.has_key('Dispatcher'):
|
if self.__dict__.has_key('Dispatcher'):
|
||||||
self.Dispatcher.PlugOut()
|
self.Dispatcher.PlugOut()
|
||||||
|
@ -402,11 +404,11 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self._plug_idle()
|
self._plug_idle()
|
||||||
|
|
||||||
def read_timeout(self):
|
def read_timeout(self):
|
||||||
if self.client.conn_holder.number_of_awaiting_messages.has_key(self.fd) \
|
ids = self.client.conn_holder.ids_of_awaiting_messages
|
||||||
and self.client.conn_holder.number_of_awaiting_messages[self.fd] > 0:
|
if self.fd in ids and len(ids[self.fd]) > 0:
|
||||||
self.client._caller.dispatch('MSGERROR',[unicode(self.client.to), -1,
|
for id in ids[self.fd]:
|
||||||
_('Connection to host could not be established: Timeout while sending data.'), None, None])
|
self._owner.Dispatcher.Event('', DATA_ERROR, (self.client.to, id))
|
||||||
self.client.conn_holder.number_of_awaiting_messages[self.fd] = 0
|
ids[self.fd] = []
|
||||||
self.pollend()
|
self.pollend()
|
||||||
|
|
||||||
def do_connect(self):
|
def do_connect(self):
|
||||||
|
@ -577,7 +579,7 @@ class ClientZeroconf:
|
||||||
self.ip_to_hash = {}
|
self.ip_to_hash = {}
|
||||||
self.hash_to_port = {}
|
self.hash_to_port = {}
|
||||||
self.listener = None
|
self.listener = None
|
||||||
self.number_of_awaiting_messages = {}
|
self.ids_of_awaiting_messages = {}
|
||||||
|
|
||||||
def connect(self, show, msg):
|
def connect(self, show, msg):
|
||||||
self.port = self.start_listener(self.caller.port)
|
self.port = self.start_listener(self.caller.port)
|
||||||
|
|
|
@ -376,7 +376,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.status in ('invisible', 'offline'):
|
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
|
return
|
||||||
|
|
||||||
msgtxt = msg
|
msgtxt = msg
|
||||||
|
@ -475,13 +477,13 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
|
|
||||||
def on_send_not_ok(reason):
|
def on_send_not_ok(reason):
|
||||||
reason += ' ' + _('Your message could not be sent.')
|
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,
|
ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
|
||||||
on_not_ok=on_send_not_ok)
|
on_not_ok=on_send_not_ok)
|
||||||
if ret == -1:
|
if ret == -1:
|
||||||
# Contact Offline
|
# 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
|
return ret
|
||||||
|
|
||||||
def send_stanza(self, stanza):
|
def send_stanza(self, stanza):
|
||||||
|
@ -573,6 +575,13 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.dispatch('STANZA_ARRIVED', unicode(data, errors = 'ignore'))
|
self.dispatch('STANZA_ARRIVED', unicode(data, errors = 'ignore'))
|
||||||
elif event == common.xmpp.transports.DATA_SENT:
|
elif event == common.xmpp.transports.DATA_SENT:
|
||||||
self.dispatch('STANZA_SENT', unicode(data))
|
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
|
# END ConnectionZeroconf
|
||||||
|
|
||||||
|
|
|
@ -947,7 +947,8 @@ class Interface:
|
||||||
if array[3]:
|
if array[3]:
|
||||||
msg = _('error while sending %(message)s ( %(error)s )') % {
|
msg = _('error while sending %(message)s ( %(error)s )') % {
|
||||||
'message': array[3], 'error': msg}
|
'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):
|
def handle_event_msgsent(self, account, array):
|
||||||
#('MSGSENT', account, (jid, msg, keyID))
|
#('MSGSENT', account, (jid, msg, keyID))
|
||||||
|
|
Loading…
Reference in New Issue