From 7d0029879a575e2d2ebdbf03cda27198267dcc80 Mon Sep 17 00:00:00 2001 From: Zhenchao Li Date: Thu, 15 Jul 2010 13:38:53 +0800 Subject: [PATCH] send proxy activated stanza to peer --- src/common/jingle_ft.py | 31 +++++++++++++++++++++++-------- src/common/jingle_session.py | 1 + src/common/jingle_transport.py | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/common/jingle_ft.py b/src/common/jingle_ft.py index 237422774..fb6b43c7e 100644 --- a/src/common/jingle_ft.py +++ b/src/common/jingle_ft.py @@ -30,6 +30,11 @@ import logging log = logging.getLogger('gajim.c.jingle_ft') +STATE_NOT_STARTED = 0 +STATE_INITIALIZED = 1 +STATE_ACCEPTED = 2 +STATE_TRANSPORT_INFO = 3 +STATE_PROXY_ACTIVATED = 4 class JingleFileTransfer(JingleContent): def __init__(self, session, transport=None, file_props=None): @@ -47,6 +52,8 @@ class JingleFileTransfer(JingleContent): self.callbacks['transport-info'] += [self.__on_transport_info] self.callbacks['iq-result'] += [self.__on_iq_result] + self.state = STATE_NOT_STARTED + self.file_props = file_props if file_props is None: self.weinitiate = False @@ -137,6 +144,8 @@ class JingleFileTransfer(JingleContent): def __on_transport_info(self, stanza, content, error, action): log.info("__on_transport_info") + if not self.weinitiate: # proxy activated from initiator + return streamhost_cid = content.getTag('transport').getTag('candidate-used').getAttr('cid') streamhost_used = None for cand in self.transport.candidates: @@ -171,7 +180,8 @@ class JingleFileTransfer(JingleContent): def __on_iq_result(self, stanza, content, error, action): log.info("__on_iq_result") - if self.weinitiate: + if self.weinitiate and self.state == STATE_NOT_STARTED: + self.state = STATE_INITIALIZED self.session.connection.files_props[self.file_props['sid']] = self.file_props receiver = self.file_props['receiver'] sender = self.file_props['sender'] @@ -187,13 +197,18 @@ class JingleFileTransfer(JingleContent): if not listener: return # send error message, notify the user - else: # session-accept iq-result - if not gajim.socks5queue.get_file_props(self.session.ourjid, self.file_props['sid']): - gajim.socks5queue.add_file_props(self.session.ourjid, self.file_props) - jid = gajim.get_jid_without_resource(self.session.ourjid) - gajim.socks5queue.connect_to_hosts(jid, self.file_props['sid'], - self.send_candidate_used, self._on_connect_error) - + elif not self.weinitiate and self.state == STATE_NOT_STARTED: # session-accept iq-result + self.state = STATE_ACCEPTED + if not gajim.socks5queue.get_file_props(self.session.ourjid, self.file_props['sid']): + gajim.socks5queue.add_file_props(self.session.ourjid, self.file_props) + jid = gajim.get_jid_without_resource(self.session.ourjid) + gajim.socks5queue.connect_to_hosts(jid, self.file_props['sid'], + self.send_candidate_used, self._on_connect_error) + elif not self.weinitiate and self.state == STATE_ACCEPTED: # transport-info iq-result + self.state = STATE_TRANSPORT_INFO + elif self.weinitiate and self.state == STATE_INITIALIZED: # proxy activated + self.state = STATE_PROXY_ACTIVATED + def send_candidate_used(self, streamhost): """ send candidate-used stanza diff --git a/src/common/jingle_session.py b/src/common/jingle_session.py index d0302359d..862b6cf2e 100644 --- a/src/common/jingle_session.py +++ b/src/common/jingle_session.py @@ -277,6 +277,7 @@ class JingleSession(object): stanza, jingle = self.__make_jingle('transport-info') jingle.addChild(node=content) self.connection.connection.send(stanza) + self.collect_iq_id(stanza.getID()) def send_description_info(self, content): assert self.state != JingleStates.ended diff --git a/src/common/jingle_transport.py b/src/common/jingle_transport.py index 009c1eb4f..7c1adf374 100644 --- a/src/common/jingle_transport.py +++ b/src/common/jingle_transport.py @@ -229,6 +229,30 @@ class JingleTransportSocks5(JingleTransport): activate.setData(file_props['proxy_receiver']) iq.setID(auth_id) self.connection.connection.send(iq) + + content = xmpp.Node('content') + content.setAttr('creator', 'initiator') + content.setAttr('name', 'file') + transport = xmpp.Node('transport') + transport.setAttr('xmlns', xmpp.NS_JINGLE_BYTESTREAM) + activated = xmpp.Node('activated') + cid = None + for host in self.candidates: + if host['host'] == proxy['host'] and \ + host['jid'] == proxy['jid'] and \ + host['port'] == proxy['port']: + cid = host['candidate_id'] + break + if cid is None: + return + activated.setAttr('cid', cid) + transport.addChild(node=activated) + content.addChild(node=transport) + sesn = self.connection.get_jingle_session(self.ourjid, self.file_props['sid']) + + if sesn is None: + return + sesn.send_transport_info(content) import farsight