- use transport sid to compute hash sent to proxies
- Don't use XTLS when using proxies
This commit is contained in:
parent
556236ac38
commit
833983eab8
|
@ -148,18 +148,18 @@ class ConnectionJingle(object):
|
|||
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)
|
||||
if jingle:
|
||||
file_props['sid'] = jingle.sid
|
||||
jingle.add_content('file',
|
||||
JingleFileTransfer(jingle, file_props = file_props, use_security=use_security)
|
||||
)
|
||||
c = JingleFileTransfer(jingle, file_props=file_props,
|
||||
use_security=use_security)
|
||||
jingle.add_content('file', c)
|
||||
else:
|
||||
jingle = JingleSession(self, weinitiate=True, jid=jid)
|
||||
self.__sessions[jingle.sid] = jingle
|
||||
file_props['sid'] = jingle.sid
|
||||
jingle.add_content('file',
|
||||
JingleFileTransfer(jingle, file_props=file_props, use_security=use_security)
|
||||
)
|
||||
c = JingleFileTransfer(jingle, file_props=file_props,
|
||||
use_security=use_security)
|
||||
jingle.add_content('file', c)
|
||||
jingle.start_session()
|
||||
return jingle.sid
|
||||
return c.transport.sid
|
||||
|
||||
|
||||
def iter_jingle_sessions(self, jid, sid=None, media=None):
|
||||
|
|
|
@ -67,18 +67,21 @@ class JingleFileTransfer(JingleContent):
|
|||
self.file_props['sender'] = session.ourjid
|
||||
self.file_props['receiver'] = session.peerjid
|
||||
self.file_props['session-type'] = 'jingle'
|
||||
self.file_props['sid'] = session.sid
|
||||
self.file_props['session-sid'] = session.sid
|
||||
self.file_props['transfered_size'] = []
|
||||
|
||||
log.info("FT request: %s" % file_props)
|
||||
|
||||
if transport is None:
|
||||
self.transport = JingleTransportSocks5()
|
||||
self.transport.set_connection(session.connection)
|
||||
self.transport.set_file_props(self.file_props)
|
||||
self.transport.set_our_jid(session.ourjid)
|
||||
self.transport.set_connection(session.connection)
|
||||
log.info('ourjid: %s' % session.ourjid)
|
||||
|
||||
if self.file_props is not None:
|
||||
self.file_props['sid'] = self.transport.sid
|
||||
|
||||
self.session = session
|
||||
self.media = 'file'
|
||||
|
||||
|
@ -109,17 +112,19 @@ class JingleFileTransfer(JingleContent):
|
|||
|
||||
file_props['receiver'] = self.session.ourjid
|
||||
log.info("ourjid: %s" % self.session.ourjid)
|
||||
file_props['sid'] = unicode(stanza.getTag('jingle').getAttr('sid'))
|
||||
file_props['session-sid'] = unicode(stanza.getTag('jingle').getAttr('sid'))
|
||||
file_props['transfered_size'] = []
|
||||
|
||||
self.file_props = file_props
|
||||
self.session.connection.files_props[file_props['sid']] = file_props
|
||||
|
||||
if self.transport is None:
|
||||
self.transport = JingleTransportSocks5()
|
||||
self.transport.set_our_jid(self.session.ourjid)
|
||||
self.transport.set_connection(self.session.connection)
|
||||
self.file_props['sid'] = self.transport.sid
|
||||
self.session.connection.files_props[file_props['sid']] = file_props
|
||||
self.transport.set_file_props(self.file_props)
|
||||
if self.file_props.has_key("streamhosts"):
|
||||
if self.file_props.has_key('streamhosts'):
|
||||
self.file_props['streamhosts'].extend(
|
||||
self.transport.remote_candidates)
|
||||
else:
|
||||
|
@ -247,7 +252,8 @@ class JingleFileTransfer(JingleContent):
|
|||
content.setAttr('name', 'file')
|
||||
|
||||
transport = xmpp.Node('transport')
|
||||
transport.setAttr('xmlns', xmpp.NS_JINGLE_BYTESTREAM)
|
||||
transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM)
|
||||
transport.setAttr('sid', self.transport.sid)
|
||||
|
||||
candidateused = xmpp.Node('candidate-used')
|
||||
candidateused.setAttr('cid', streamhost['cid'])
|
||||
|
|
|
@ -17,6 +17,7 @@ Handles Jingle Transports (currently only ICE-UDP)
|
|||
|
||||
import xmpp
|
||||
import socket
|
||||
from common import helpers
|
||||
from common import gajim
|
||||
from common.protocol.bytestream import ConnectionSocks5Bytestream
|
||||
import logging
|
||||
|
@ -29,7 +30,7 @@ transports = {}
|
|||
def get_jingle_transport(node):
|
||||
namespace = node.getNamespace()
|
||||
if namespace in transports:
|
||||
return transports[namespace]()
|
||||
return transports[namespace](node)
|
||||
|
||||
|
||||
class TransportType(object):
|
||||
|
@ -83,10 +84,13 @@ class JingleTransportSocks5(JingleTransport):
|
|||
Socks5 transport in jingle scenario
|
||||
Note: Don't forget to call set_file_props after initialization
|
||||
"""
|
||||
def __init__(self):
|
||||
def __init__(self, node=None):
|
||||
JingleTransport.__init__(self, TransportType.streaming)
|
||||
self.connection = None
|
||||
self.remote_candidates = []
|
||||
self.sid = None
|
||||
if node and node.getAttr('sid'):
|
||||
self.sid = node.getAttr('sid')
|
||||
|
||||
def set_file_props(self, file_props):
|
||||
self.file_props = file_props
|
||||
|
@ -96,6 +100,8 @@ class JingleTransportSocks5(JingleTransport):
|
|||
|
||||
def set_connection(self, conn):
|
||||
self.connection = conn
|
||||
if not self.sid:
|
||||
self.sid = self.connection.connection.getAnID()
|
||||
|
||||
def make_candidate(self, candidate):
|
||||
import logging
|
||||
|
@ -118,17 +124,22 @@ class JingleTransportSocks5(JingleTransport):
|
|||
self._add_proxy_candidates()
|
||||
transport = JingleTransport.make_transport(self, candidates)
|
||||
transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM)
|
||||
transport.setAttr('sid', self.sid)
|
||||
return transport
|
||||
|
||||
def parse_transport_stanza(self, transport):
|
||||
candidates = []
|
||||
for candidate in transport.iterTags('candidate'):
|
||||
typ = 'direct' # default value
|
||||
if candidate.has_attr('type'):
|
||||
typ = candidate['type']
|
||||
cand = {
|
||||
'state': 0,
|
||||
'target': self.ourjid,
|
||||
'host': candidate['host'],
|
||||
'port': candidate['port'],
|
||||
'cid': candidate['cid']
|
||||
'cid': candidate['cid'],
|
||||
'type': typ
|
||||
}
|
||||
candidates.append(cand)
|
||||
|
||||
|
@ -138,6 +149,7 @@ class JingleTransportSocks5(JingleTransport):
|
|||
|
||||
|
||||
def _add_local_ips_as_candidates(self):
|
||||
return
|
||||
if not self.connection:
|
||||
return
|
||||
local_ip_cand = []
|
||||
|
@ -167,6 +179,7 @@ class JingleTransportSocks5(JingleTransport):
|
|||
self.candidates += local_ip_cand
|
||||
|
||||
def _add_additional_candidates(self):
|
||||
return
|
||||
if not self.connection:
|
||||
return
|
||||
type_preference = 126
|
||||
|
@ -234,7 +247,7 @@ class JingleTransportSocks5(JingleTransport):
|
|||
content.setAttr('creator', 'initiator')
|
||||
content.setAttr('name', 'file')
|
||||
transport = xmpp.Node('transport')
|
||||
transport.setAttr('xmlns', xmpp.NS_JINGLE_BYTESTREAM)
|
||||
transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM)
|
||||
activated = xmpp.Node('activated')
|
||||
cid = None
|
||||
for host in self.candidates:
|
||||
|
@ -248,7 +261,8 @@ class JingleTransportSocks5(JingleTransport):
|
|||
activated.setAttr('cid', cid)
|
||||
transport.addChild(node=activated)
|
||||
content.addChild(node=transport)
|
||||
sesn = self.connection.get_jingle_session(self.ourjid, self.file_props['sid'])
|
||||
sesn = self.connection.get_jingle_session(self.ourjid,
|
||||
self.file_props['session-sid'])
|
||||
|
||||
if sesn is None:
|
||||
return
|
||||
|
@ -257,7 +271,7 @@ class JingleTransportSocks5(JingleTransport):
|
|||
import farsight
|
||||
|
||||
class JingleTransportICEUDP(JingleTransport):
|
||||
def __init__(self):
|
||||
def __init__(self, node):
|
||||
JingleTransport.__init__(self, TransportType.datagram)
|
||||
|
||||
def make_candidate(self, candidate):
|
||||
|
|
|
@ -136,16 +136,16 @@ class ConnectionBytestream:
|
|||
# file transfer initiated by a jingle session
|
||||
log.info("send_file_approval: jingle session accept")
|
||||
if file_props.get('session-type') == 'jingle':
|
||||
session = self.get_jingle_session(file_props['sender'], file_props['sid'])
|
||||
session = self.get_jingle_session(file_props['sender'],
|
||||
file_props['session-sid'])
|
||||
if not session:
|
||||
return
|
||||
sid = file_props['sid']
|
||||
gajim.socks5queue.add_file_props(self.name, file_props)
|
||||
|
||||
if not session.accepted:
|
||||
if session.get_content('file').use_security:
|
||||
id = jingle_xtls.send_cert_request(self, file_props['sender'])
|
||||
jingle_xtls.key_exchange_pend(id, session)
|
||||
id_ = jingle_xtls.send_cert_request(self, file_props['sender'])
|
||||
jingle_xtls.key_exchange_pend(id_, session)
|
||||
return
|
||||
session.approve_session()
|
||||
session.approve_content('file')
|
||||
|
|
|
@ -122,7 +122,8 @@ class SocksQueue:
|
|||
return 1
|
||||
return 0
|
||||
|
||||
def connect_to_hosts(self, account, sid, on_success=None, on_failure=None, fingerprint=None):
|
||||
def connect_to_hosts(self, account, sid, on_success=None, on_failure=None,
|
||||
fingerprint=None):
|
||||
self.on_success = on_success
|
||||
self.on_failure = on_failure
|
||||
file_props = self.files_props[account][sid]
|
||||
|
@ -130,7 +131,12 @@ class SocksQueue:
|
|||
|
||||
# add streamhosts to the queue
|
||||
for streamhost in file_props['streamhosts']:
|
||||
receiver = Socks5Receiver(self.idlequeue, streamhost, sid, file_props, fingerprint=fingerprint)
|
||||
if 'type' in streamhost and streamhost['type'] == 'proxy':
|
||||
fp = None
|
||||
else:
|
||||
fd = fingerprint
|
||||
receiver = Socks5Receiver(self.idlequeue, streamhost, sid,
|
||||
file_props, fingerprint=fp)
|
||||
self.add_receiver(account, receiver)
|
||||
streamhost['idx'] = receiver.queue_idx
|
||||
|
||||
|
|
Loading…
Reference in New Issue