send proxy activated stanza to peer
This commit is contained in:
parent
2938838f54
commit
7d0029879a
|
@ -30,6 +30,11 @@ import logging
|
||||||
|
|
||||||
log = logging.getLogger('gajim.c.jingle_ft')
|
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):
|
class JingleFileTransfer(JingleContent):
|
||||||
def __init__(self, session, transport=None, file_props=None):
|
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['transport-info'] += [self.__on_transport_info]
|
||||||
self.callbacks['iq-result'] += [self.__on_iq_result]
|
self.callbacks['iq-result'] += [self.__on_iq_result]
|
||||||
|
|
||||||
|
self.state = STATE_NOT_STARTED
|
||||||
|
|
||||||
self.file_props = file_props
|
self.file_props = file_props
|
||||||
if file_props is None:
|
if file_props is None:
|
||||||
self.weinitiate = False
|
self.weinitiate = False
|
||||||
|
@ -137,6 +144,8 @@ class JingleFileTransfer(JingleContent):
|
||||||
def __on_transport_info(self, stanza, content, error, action):
|
def __on_transport_info(self, stanza, content, error, action):
|
||||||
log.info("__on_transport_info")
|
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_cid = content.getTag('transport').getTag('candidate-used').getAttr('cid')
|
||||||
streamhost_used = None
|
streamhost_used = None
|
||||||
for cand in self.transport.candidates:
|
for cand in self.transport.candidates:
|
||||||
|
@ -171,7 +180,8 @@ class JingleFileTransfer(JingleContent):
|
||||||
def __on_iq_result(self, stanza, content, error, action):
|
def __on_iq_result(self, stanza, content, error, action):
|
||||||
log.info("__on_iq_result")
|
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
|
self.session.connection.files_props[self.file_props['sid']] = self.file_props
|
||||||
receiver = self.file_props['receiver']
|
receiver = self.file_props['receiver']
|
||||||
sender = self.file_props['sender']
|
sender = self.file_props['sender']
|
||||||
|
@ -187,12 +197,17 @@ class JingleFileTransfer(JingleContent):
|
||||||
if not listener:
|
if not listener:
|
||||||
return
|
return
|
||||||
# send error message, notify the user
|
# send error message, notify the user
|
||||||
else: # session-accept iq-result
|
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']):
|
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.add_file_props(self.session.ourjid, self.file_props)
|
||||||
jid = gajim.get_jid_without_resource(self.session.ourjid)
|
jid = gajim.get_jid_without_resource(self.session.ourjid)
|
||||||
gajim.socks5queue.connect_to_hosts(jid, self.file_props['sid'],
|
gajim.socks5queue.connect_to_hosts(jid, self.file_props['sid'],
|
||||||
self.send_candidate_used, self._on_connect_error)
|
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):
|
def send_candidate_used(self, streamhost):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -277,6 +277,7 @@ class JingleSession(object):
|
||||||
stanza, jingle = self.__make_jingle('transport-info')
|
stanza, jingle = self.__make_jingle('transport-info')
|
||||||
jingle.addChild(node=content)
|
jingle.addChild(node=content)
|
||||||
self.connection.connection.send(stanza)
|
self.connection.connection.send(stanza)
|
||||||
|
self.collect_iq_id(stanza.getID())
|
||||||
|
|
||||||
def send_description_info(self, content):
|
def send_description_info(self, content):
|
||||||
assert self.state != JingleStates.ended
|
assert self.state != JingleStates.ended
|
||||||
|
|
|
@ -230,6 +230,30 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
iq.setID(auth_id)
|
iq.setID(auth_id)
|
||||||
self.connection.connection.send(iq)
|
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
|
import farsight
|
||||||
|
|
||||||
class JingleTransportICEUDP(JingleTransport):
|
class JingleTransportICEUDP(JingleTransport):
|
||||||
|
|
Loading…
Reference in New Issue