send proxy activated stanza to peer

This commit is contained in:
Zhenchao Li 2010-07-15 13:38:53 +08:00
parent 2938838f54
commit 7d0029879a
3 changed files with 48 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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