2009-11-15 20:47:06 +01:00
|
|
|
##
|
|
|
|
## Copyright (C) 2006 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2009-11-26 12:58:12 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
Handles Jingle Transports (currently only ICE-UDP)
|
|
|
|
"""
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
2010-06-19 16:52:17 +02:00
|
|
|
import socket
|
|
|
|
from common import gajim
|
|
|
|
from common.protocol.bytestream import ConnectionSocks5Bytestream
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger('gajim.c.jingle_transport')
|
|
|
|
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
transports = {}
|
|
|
|
|
|
|
|
def get_jingle_transport(node):
|
2010-02-08 15:08:40 +01:00
|
|
|
namespace = node.getNamespace()
|
|
|
|
if namespace in transports:
|
2010-08-25 12:05:14 +02:00
|
|
|
return transports[namespace](node)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TransportType(object):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Possible types of a JingleTransport
|
|
|
|
"""
|
2012-01-07 05:18:50 +01:00
|
|
|
ICEUDP = 1
|
|
|
|
SOCKS5 = 2
|
|
|
|
IBB = 3
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class JingleTransport(object):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
An abstraction of a transport in Jingle sessions
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, type_):
|
2012-08-22 12:55:57 +02:00
|
|
|
self.type_ = type_
|
2010-02-08 15:08:40 +01:00
|
|
|
self.candidates = []
|
|
|
|
self.remote_candidates = []
|
|
|
|
|
|
|
|
def _iter_candidates(self):
|
|
|
|
for candidate in self.candidates:
|
|
|
|
yield self.make_candidate(candidate)
|
|
|
|
|
|
|
|
def make_candidate(self, candidate):
|
|
|
|
"""
|
|
|
|
Build a candidate stanza for the given candidate
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def make_transport(self, candidates=None):
|
|
|
|
"""
|
|
|
|
Build a transport stanza with the given candidates (or self.candidates if
|
|
|
|
candidates is None)
|
|
|
|
"""
|
|
|
|
if not candidates:
|
|
|
|
candidates = self._iter_candidates()
|
|
|
|
else:
|
|
|
|
candidates = (self.make_candidate(candidate) for candidate in candidates)
|
2012-12-09 21:37:51 +01:00
|
|
|
transport = nbxmpp.Node('transport', payload=candidates)
|
2010-02-08 15:08:40 +01:00
|
|
|
return transport
|
|
|
|
|
|
|
|
def parse_transport_stanza(self, transport):
|
|
|
|
"""
|
|
|
|
Return the list of transport candidates from a transport stanza
|
|
|
|
"""
|
|
|
|
return []
|
2012-06-14 19:46:17 +02:00
|
|
|
|
2011-12-23 02:12:11 +01:00
|
|
|
def set_connection(self, conn):
|
|
|
|
self.connection = conn
|
|
|
|
if not self.sid:
|
|
|
|
self.sid = self.connection.connection.getAnID()
|
|
|
|
|
|
|
|
def set_file_props(self, file_props):
|
|
|
|
self.file_props = file_props
|
|
|
|
|
|
|
|
def set_our_jid(self, jid):
|
|
|
|
self.ourjid = jid
|
2012-06-14 19:46:17 +02:00
|
|
|
|
2011-12-23 02:12:11 +01:00
|
|
|
def set_sid(self, sid):
|
|
|
|
self.sid = sid
|
2009-11-15 21:21:10 +01:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
class JingleTransportSocks5(JingleTransport):
|
|
|
|
"""
|
|
|
|
Socks5 transport in jingle scenario
|
|
|
|
Note: Don't forget to call set_file_props after initialization
|
|
|
|
"""
|
2010-08-25 12:05:14 +02:00
|
|
|
def __init__(self, node=None):
|
2012-01-07 05:18:50 +01:00
|
|
|
JingleTransport.__init__(self, TransportType.SOCKS5)
|
2010-07-06 12:29:21 +02:00
|
|
|
self.connection = None
|
2010-07-01 09:48:44 +02:00
|
|
|
self.remote_candidates = []
|
2010-08-25 12:05:14 +02:00
|
|
|
self.sid = None
|
|
|
|
if node and node.getAttr('sid'):
|
|
|
|
self.sid = node.getAttr('sid')
|
2010-06-19 16:52:17 +02:00
|
|
|
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
def make_candidate(self, candidate):
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger()
|
|
|
|
log.info('candidate dict, %s' % candidate)
|
|
|
|
attrs = {
|
|
|
|
'cid': candidate['candidate_id'],
|
|
|
|
'host': candidate['host'],
|
|
|
|
'jid': candidate['jid'],
|
|
|
|
'port': candidate['port'],
|
|
|
|
'priority': candidate['priority'],
|
|
|
|
'type': candidate['type']
|
|
|
|
}
|
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
return nbxmpp.Node('candidate', attrs=attrs)
|
2010-06-19 16:52:17 +02:00
|
|
|
|
2011-07-23 00:00:29 +02:00
|
|
|
def make_transport(self, candidates=None, add_candidates = True):
|
2011-10-29 06:09:45 +02:00
|
|
|
if add_candidates:
|
2011-07-23 00:00:29 +02:00
|
|
|
self._add_local_ips_as_candidates()
|
|
|
|
self._add_additional_candidates()
|
|
|
|
self._add_proxy_candidates()
|
|
|
|
transport = JingleTransport.make_transport(self, candidates)
|
|
|
|
else:
|
2012-12-09 21:37:51 +01:00
|
|
|
transport = nbxmpp.Node('transport')
|
|
|
|
transport.setNamespace(nbxmpp.NS_JINGLE_BYTESTREAM)
|
2010-08-25 12:05:14 +02:00
|
|
|
transport.setAttr('sid', self.sid)
|
2012-08-23 13:10:30 +02:00
|
|
|
if self.file_props.dstaddr:
|
|
|
|
transport.setAttr('dstaddr', self.file_props.dstaddr)
|
2010-06-19 16:52:17 +02:00
|
|
|
return transport
|
|
|
|
|
|
|
|
def parse_transport_stanza(self, transport):
|
2010-07-01 09:48:44 +02:00
|
|
|
candidates = []
|
|
|
|
for candidate in transport.iterTags('candidate'):
|
2010-08-25 12:05:14 +02:00
|
|
|
typ = 'direct' # default value
|
|
|
|
if candidate.has_attr('type'):
|
|
|
|
typ = candidate['type']
|
2010-07-01 09:48:44 +02:00
|
|
|
cand = {
|
|
|
|
'state': 0,
|
|
|
|
'target': self.ourjid,
|
|
|
|
'host': candidate['host'],
|
2011-10-29 06:09:45 +02:00
|
|
|
'port': int(candidate['port']),
|
2010-08-25 12:05:14 +02:00
|
|
|
'cid': candidate['cid'],
|
2011-08-15 05:49:23 +02:00
|
|
|
'type': typ,
|
2011-10-29 06:09:45 +02:00
|
|
|
'priority': candidate['priority']
|
2010-07-01 09:48:44 +02:00
|
|
|
}
|
|
|
|
candidates.append(cand)
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-07-01 09:48:44 +02:00
|
|
|
# we need this when we construct file_props on session-initiation
|
|
|
|
self.remote_candidates = candidates
|
|
|
|
return candidates
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
|
2011-10-29 06:09:45 +02:00
|
|
|
def _add_candidates(self, candidates):
|
|
|
|
for cand in candidates:
|
|
|
|
in_remote = False
|
|
|
|
for cand2 in self.remote_candidates:
|
|
|
|
if cand['host'] == cand2['host'] and \
|
|
|
|
cand['port'] == cand2['port']:
|
|
|
|
in_remote = True
|
|
|
|
break
|
|
|
|
if not in_remote:
|
|
|
|
self.candidates.append(cand)
|
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
def _add_local_ips_as_candidates(self):
|
2012-06-14 19:46:17 +02:00
|
|
|
if not gajim.config.get_per('accounts', self.connection.name,
|
|
|
|
'ft_send_local_ips'):
|
|
|
|
return
|
2010-07-06 12:29:21 +02:00
|
|
|
if not self.connection:
|
|
|
|
return
|
2010-06-19 16:52:17 +02:00
|
|
|
local_ip_cand = []
|
2011-10-29 06:09:45 +02:00
|
|
|
port = int(gajim.config.get('file_transfers_port'))
|
2012-08-28 21:10:19 +02:00
|
|
|
#type preference of connection type. XEP-0260 section 2.2
|
2012-08-31 13:42:44 +02:00
|
|
|
type_preference = 126
|
2010-07-06 12:29:21 +02:00
|
|
|
c = {'host': self.connection.peerhost[0]}
|
|
|
|
c['candidate_id'] = self.connection.connection.getAnID()
|
2010-06-19 16:52:17 +02:00
|
|
|
c['port'] = port
|
|
|
|
c['type'] = 'direct'
|
|
|
|
c['jid'] = self.ourjid
|
|
|
|
c['priority'] = (2**16) * type_preference
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
local_ip_cand.append(c)
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
for addr in socket.getaddrinfo(socket.gethostname(), None):
|
|
|
|
if not addr[4][0] in local_ip_cand and not addr[4][0].startswith('127'):
|
|
|
|
c = {'host': addr[4][0]}
|
2011-06-29 00:31:07 +02:00
|
|
|
c['candidate_id'] = self.connection.connection.getAnID()
|
2010-06-19 16:52:17 +02:00
|
|
|
c['port'] = port
|
|
|
|
c['type'] = 'direct'
|
|
|
|
c['jid'] = self.ourjid
|
|
|
|
c['priority'] = (2**16) * type_preference
|
2012-06-14 18:27:23 +02:00
|
|
|
c['initiator'] = self.file_props.sender
|
|
|
|
c['target'] = self.file_props.receiver
|
2010-06-19 16:52:17 +02:00
|
|
|
local_ip_cand.append(c)
|
|
|
|
|
2011-10-29 06:09:45 +02:00
|
|
|
self._add_candidates(local_ip_cand)
|
2010-06-19 16:52:17 +02:00
|
|
|
|
|
|
|
def _add_additional_candidates(self):
|
2010-07-06 12:29:21 +02:00
|
|
|
if not self.connection:
|
|
|
|
return
|
2010-06-19 16:52:17 +02:00
|
|
|
type_preference = 126
|
|
|
|
additional_ip_cand = []
|
2011-10-29 06:09:45 +02:00
|
|
|
port = int(gajim.config.get('file_transfers_port'))
|
2010-08-25 12:05:14 +02:00
|
|
|
ft_add_hosts = gajim.config.get('ft_add_hosts_to_send')
|
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
if ft_add_hosts:
|
|
|
|
hosts = [e.strip() for e in ft_add_hosts.split(',')]
|
|
|
|
for h in hosts:
|
|
|
|
c = {'host': h}
|
2010-07-06 12:29:21 +02:00
|
|
|
c['candidate_id'] = self.connection.connection.getAnID()
|
2010-06-19 16:52:17 +02:00
|
|
|
c['port'] = port
|
|
|
|
c['type'] = 'direct'
|
|
|
|
c['jid'] = self.ourjid
|
|
|
|
c['priority'] = (2**16) * type_preference
|
2012-06-14 18:27:23 +02:00
|
|
|
c['initiator'] = self.file_props.sender
|
|
|
|
c['target'] = self.file_props.receiver
|
2010-06-19 16:52:17 +02:00
|
|
|
additional_ip_cand.append(c)
|
2011-10-29 06:09:45 +02:00
|
|
|
|
|
|
|
self._add_candidates(additional_ip_cand)
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
def _add_proxy_candidates(self):
|
2010-07-06 12:29:21 +02:00
|
|
|
if not self.connection:
|
|
|
|
return
|
2010-06-19 16:52:17 +02:00
|
|
|
type_preference = 10
|
|
|
|
proxy_cand = []
|
2010-07-12 04:20:31 +02:00
|
|
|
socks5conn = self.connection
|
2010-06-19 16:52:17 +02:00
|
|
|
proxyhosts = socks5conn._get_file_transfer_proxies_from_config(self.file_props)
|
|
|
|
|
|
|
|
if proxyhosts:
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.proxyhosts = proxyhosts
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-06-19 16:52:17 +02:00
|
|
|
for proxyhost in proxyhosts:
|
|
|
|
c = {'host': proxyhost['host']}
|
2010-07-06 12:29:21 +02:00
|
|
|
c['candidate_id'] = self.connection.connection.getAnID()
|
2011-10-29 06:09:45 +02:00
|
|
|
c['port'] = int(proxyhost['port'])
|
2010-06-19 16:52:17 +02:00
|
|
|
c['type'] = 'proxy'
|
2010-07-12 04:20:31 +02:00
|
|
|
c['jid'] = proxyhost['jid']
|
2010-06-19 16:52:17 +02:00
|
|
|
c['priority'] = (2**16) * type_preference
|
2012-06-14 18:27:23 +02:00
|
|
|
c['initiator'] = self.file_props.sender
|
|
|
|
c['target'] = self.file_props.receiver
|
2010-06-19 16:52:17 +02:00
|
|
|
proxy_cand.append(c)
|
2011-10-29 06:09:45 +02:00
|
|
|
|
|
|
|
self._add_candidates(proxy_cand)
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2010-08-26 10:36:58 +02:00
|
|
|
def get_content(self):
|
|
|
|
sesn = self.connection.get_jingle_session(self.ourjid,
|
2012-08-25 18:09:50 +02:00
|
|
|
self.file_props.sid)
|
2010-08-26 10:36:58 +02:00
|
|
|
for content in sesn.contents.values():
|
|
|
|
if content.transport == self:
|
|
|
|
return content
|
|
|
|
|
2010-07-13 04:38:31 +02:00
|
|
|
def _on_proxy_auth_ok(self, proxy):
|
|
|
|
log.info('proxy auth ok for ' + str(proxy))
|
|
|
|
# send activate request to proxy, send activated confirmation to peer
|
|
|
|
if not self.connection:
|
|
|
|
return
|
2011-10-29 06:09:45 +02:00
|
|
|
sesn = self.connection.get_jingle_session(self.ourjid,
|
2012-08-25 18:09:50 +02:00
|
|
|
self.file_props.sid)
|
2011-10-29 06:09:45 +02:00
|
|
|
if sesn is None:
|
|
|
|
return
|
2012-06-14 19:46:17 +02:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
iq = nbxmpp.Iq(to=proxy['jid'], frm=self.ourjid, typ='set')
|
2010-07-13 04:38:31 +02:00
|
|
|
auth_id = "au_" + proxy['sid']
|
|
|
|
iq.setID(auth_id)
|
2012-12-09 21:37:51 +01:00
|
|
|
query = iq.setTag('query', namespace=nbxmpp.NS_BYTESTREAM)
|
2010-07-13 04:38:31 +02:00
|
|
|
query.setAttr('sid', proxy['sid'])
|
|
|
|
activate = query.setTag('activate')
|
2011-10-29 06:09:45 +02:00
|
|
|
activate.setData(sesn.peerjid)
|
2010-07-13 04:38:31 +02:00
|
|
|
iq.setID(auth_id)
|
|
|
|
self.connection.connection.send(iq)
|
2010-08-25 12:05:14 +02:00
|
|
|
|
2011-10-29 06:09:45 +02:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
content = nbxmpp.Node('content')
|
2010-07-15 07:38:53 +02:00
|
|
|
content.setAttr('creator', 'initiator')
|
2010-08-26 10:36:58 +02:00
|
|
|
c = self.get_content()
|
|
|
|
content.setAttr('name', c.name)
|
2012-12-09 21:37:51 +01:00
|
|
|
transport = nbxmpp.Node('transport')
|
|
|
|
transport.setNamespace(nbxmpp.NS_JINGLE_BYTESTREAM)
|
2011-10-29 06:09:45 +02:00
|
|
|
transport.setAttr('sid', proxy['sid'])
|
2012-12-09 21:37:51 +01:00
|
|
|
activated = nbxmpp.Node('activated')
|
2010-07-15 07:38:53 +02:00
|
|
|
cid = None
|
2011-10-29 06:09:45 +02:00
|
|
|
|
|
|
|
if 'cid' in proxy:
|
|
|
|
cid = proxy['cid']
|
|
|
|
else:
|
|
|
|
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
|
2010-07-15 07:38:53 +02:00
|
|
|
if cid is None:
|
2011-10-29 06:09:45 +02:00
|
|
|
raise Exception, 'cid is missing'
|
2010-07-15 07:38:53 +02:00
|
|
|
activated.setAttr('cid', cid)
|
|
|
|
transport.addChild(node=activated)
|
|
|
|
content.addChild(node=transport)
|
|
|
|
sesn.send_transport_info(content)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2011-06-29 00:31:07 +02:00
|
|
|
|
|
|
|
class JingleTransportIBB(JingleTransport):
|
2011-10-29 06:09:45 +02:00
|
|
|
|
2011-06-29 00:31:07 +02:00
|
|
|
def __init__(self, node=None, block_sz=None):
|
2011-10-29 06:09:45 +02:00
|
|
|
|
2012-01-07 05:18:50 +01:00
|
|
|
JingleTransport.__init__(self, TransportType.IBB)
|
2011-10-29 06:09:45 +02:00
|
|
|
|
2011-06-29 00:31:07 +02:00
|
|
|
if block_sz:
|
|
|
|
self.block_sz = block_sz
|
|
|
|
else:
|
|
|
|
self.block_sz = '4096'
|
2011-10-29 06:09:45 +02:00
|
|
|
|
2011-06-29 00:31:07 +02:00
|
|
|
self.connection = None
|
|
|
|
self.sid = None
|
|
|
|
if node and node.getAttr('sid'):
|
|
|
|
self.sid = node.getAttr('sid')
|
|
|
|
|
|
|
|
|
|
|
|
def make_transport(self):
|
2011-10-29 06:09:45 +02:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
transport = nbxmpp.Node('transport')
|
|
|
|
transport.setNamespace(nbxmpp.NS_JINGLE_IBB)
|
2011-06-29 00:31:07 +02:00
|
|
|
transport.setAttr('block-size', self.block_sz)
|
|
|
|
transport.setAttr('sid', self.sid)
|
2011-10-29 06:09:45 +02:00
|
|
|
return transport
|
2012-06-14 19:46:17 +02:00
|
|
|
|
2011-12-17 20:59:15 +01:00
|
|
|
try:
|
2012-04-01 19:49:52 +02:00
|
|
|
import farstream
|
2011-12-17 20:59:15 +01:00
|
|
|
except Exception:
|
|
|
|
pass
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
class JingleTransportICEUDP(JingleTransport):
|
2010-08-25 12:05:14 +02:00
|
|
|
def __init__(self, node):
|
2012-01-07 05:18:50 +01:00
|
|
|
JingleTransport.__init__(self, TransportType.ICEUDP)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def make_candidate(self, candidate):
|
2012-04-01 19:49:52 +02:00
|
|
|
types = {farstream.CANDIDATE_TYPE_HOST: 'host',
|
|
|
|
farstream.CANDIDATE_TYPE_SRFLX: 'srflx',
|
|
|
|
farstream.CANDIDATE_TYPE_PRFLX: 'prflx',
|
|
|
|
farstream.CANDIDATE_TYPE_RELAY: 'relay',
|
|
|
|
farstream.CANDIDATE_TYPE_MULTICAST: 'multicast'}
|
2010-02-08 15:08:40 +01:00
|
|
|
attrs = {
|
|
|
|
'component': candidate.component_id,
|
|
|
|
'foundation': '1', # hack
|
|
|
|
'generation': '0',
|
|
|
|
'ip': candidate.ip,
|
|
|
|
'network': '0',
|
|
|
|
'port': candidate.port,
|
|
|
|
'priority': int(candidate.priority), # hack
|
2012-08-31 13:42:44 +02:00
|
|
|
'id': gajim.get_an_id()
|
2010-02-08 15:08:40 +01:00
|
|
|
}
|
|
|
|
if candidate.type in types:
|
|
|
|
attrs['type'] = types[candidate.type]
|
2012-04-01 19:49:52 +02:00
|
|
|
if candidate.proto == farstream.NETWORK_PROTOCOL_UDP:
|
2010-02-08 15:08:40 +01:00
|
|
|
attrs['protocol'] = 'udp'
|
|
|
|
else:
|
|
|
|
# we actually don't handle properly different tcp options in jingle
|
|
|
|
attrs['protocol'] = 'tcp'
|
2012-12-09 21:37:51 +01:00
|
|
|
return nbxmpp.Node('candidate', attrs=attrs)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def make_transport(self, candidates=None):
|
|
|
|
transport = JingleTransport.make_transport(self, candidates)
|
2012-12-09 21:37:51 +01:00
|
|
|
transport.setNamespace(nbxmpp.NS_JINGLE_ICE_UDP)
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.candidates and self.candidates[0].username and \
|
|
|
|
self.candidates[0].password:
|
|
|
|
transport.setAttr('ufrag', self.candidates[0].username)
|
|
|
|
transport.setAttr('pwd', self.candidates[0].password)
|
|
|
|
return transport
|
|
|
|
|
|
|
|
def parse_transport_stanza(self, transport):
|
|
|
|
candidates = []
|
|
|
|
for candidate in transport.iterTags('candidate'):
|
2012-04-01 19:49:52 +02:00
|
|
|
cand = farstream.Candidate()
|
2010-02-08 15:08:40 +01:00
|
|
|
cand.component_id = int(candidate['component'])
|
|
|
|
cand.ip = str(candidate['ip'])
|
|
|
|
cand.port = int(candidate['port'])
|
|
|
|
cand.foundation = str(candidate['foundation'])
|
2012-04-01 19:49:52 +02:00
|
|
|
#cand.type = farstream.CANDIDATE_TYPE_LOCAL
|
2010-02-08 15:08:40 +01:00
|
|
|
cand.priority = int(candidate['priority'])
|
|
|
|
|
|
|
|
if candidate['protocol'] == 'udp':
|
2012-04-01 19:49:52 +02:00
|
|
|
cand.proto = farstream.NETWORK_PROTOCOL_UDP
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# we actually don't handle properly different tcp options in jingle
|
2012-04-01 19:49:52 +02:00
|
|
|
cand.proto = farstream.NETWORK_PROTOCOL_TCP
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
cand.username = str(transport['ufrag'])
|
|
|
|
cand.password = str(transport['pwd'])
|
|
|
|
|
|
|
|
#FIXME: huh?
|
2012-04-01 19:49:52 +02:00
|
|
|
types = {'host': farstream.CANDIDATE_TYPE_HOST,
|
|
|
|
'srflx': farstream.CANDIDATE_TYPE_SRFLX,
|
|
|
|
'prflx': farstream.CANDIDATE_TYPE_PRFLX,
|
|
|
|
'relay': farstream.CANDIDATE_TYPE_RELAY,
|
|
|
|
'multicast': farstream.CANDIDATE_TYPE_MULTICAST}
|
2010-02-08 15:08:40 +01:00
|
|
|
if 'type' in candidate and candidate['type'] in types:
|
|
|
|
cand.type = types[candidate['type']]
|
|
|
|
else:
|
|
|
|
print 'Unknown type %s', candidate['type']
|
|
|
|
candidates.append(cand)
|
|
|
|
self.remote_candidates.extend(candidates)
|
|
|
|
return candidates
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
transports[nbxmpp.NS_JINGLE_ICE_UDP] = JingleTransportICEUDP
|
|
|
|
transports[nbxmpp.NS_JINGLE_BYTESTREAM] = JingleTransportSocks5
|
|
|
|
transports[nbxmpp.NS_JINGLE_IBB] = JingleTransportIBB
|