send transport info, start "send_file" after receiving transport-info.

TODO: implement file transfer complete callback, various session management code for abnormal FT interactions.
This commit is contained in:
Zhenchao Li 2010-07-05 13:46:53 +08:00
parent d0adcb1a05
commit 14fe189b00
3 changed files with 36 additions and 9 deletions

View File

@ -117,7 +117,6 @@ class JingleFileTransfer(JingleContent):
def __on_session_accept(self, stanza, content, error, action):
log.info("__on_session_accept")
gajim.socks5queue.send_file(self.file_props, self.session.ourjid)
def __on_session_terminate(self, stanza, content, error, action):
log.info("__on_session_terminate")
@ -133,6 +132,7 @@ class JingleFileTransfer(JingleContent):
def __on_transport_info(self, stanza, content, error, action):
log.info("__on_transport_info")
gajim.socks5queue.send_file(self.file_props, self.session.ourjid)
def __on_iq_result(self, stanza, content, error, action):
log.info("__on_iq_result")
@ -152,7 +152,39 @@ 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)
gajim.socks5queue.connect_to_hosts(self.session.ourjid, self.file_props['sid'],
self.send_candidate_used, self._on_connect_error)
def send_candidate_used(self, streamhost):
"""
send candidate-used stanza
"""
log.info("send_candidate_used")
if streamhost is None:
return
content = xmpp.Node('content')
content.setAttr('creator', 'initiator')
content.setAttr('name', 'file')
transport = xmpp.Node('transport')
transport.setAttr('xmlns', xmpp.NS_JINGLE_BYTESTREAM)
candidateused = xmpp.Node('candidate-used')
candidateused.setAttr('cid', streamhost['cid'])
transport.addChild(node=candidateused)
content.addChild(node=transport)
self.session.send_transport_info(content)
def _on_connect_error(self, to, _id, sid, code=404):
log.info("connect error, sid=" + sid)
return
def _fill_content(self, content):
description_node = xmpp.simplexml.Node(tag=xmpp.NS_JINGLE_FILE_TRANSFER + ' description')

View File

@ -123,7 +123,8 @@ class JingleTransportSocks5(JingleTransport):
'state': 0,
'target': self.ourjid,
'host': candidate['host'],
'port': candidate['port']
'port': candidate['port'],
'cid': candidate['cid']
}
candidates.append(cand)

View File

@ -143,13 +143,7 @@ class ConnectionBytestream:
if not session.accepted:
session.approve_session()
session.approve_content('file')
if not gajim.socks5queue.get_file_props(session.ourjid, sid):
gajim.socks5queue.add_file_props(session.ourjid, file_props)
gajim.socks5queue.connect_to_hosts(session.ourjid, sid,
lambda streamhost: log.info("connected to" + str(streamhost)),
lambda a, b, c, d: log.info("connect error!" + a + b + c + d))
return
return
iq = xmpp.Iq(to=unicode(file_props['sender']), typ='result')
iq.setAttr('id', file_props['request-id'])