2010-06-06 17:22:52 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim 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 3 only.
|
|
|
|
##
|
|
|
|
## Gajim 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.
|
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
Handles Jingle File Transfer (XEP 0234)
|
|
|
|
"""
|
|
|
|
|
2012-06-17 00:41:33 +02:00
|
|
|
import hashlib
|
2013-01-02 13:54:02 +01:00
|
|
|
from common import gajim
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
2013-12-30 21:19:15 +01:00
|
|
|
from . import jingle_xtls
|
2013-01-02 13:54:02 +01:00
|
|
|
from common.jingle_content import contents, JingleContent
|
|
|
|
from common.jingle_transport import *
|
2010-07-03 10:22:47 +02:00
|
|
|
from common import helpers
|
2011-11-18 05:55:44 +01:00
|
|
|
from common.socks5 import Socks5ReceiverClient, Socks5SenderClient
|
2011-06-24 18:24:42 +02:00
|
|
|
from common.connection_handlers_events import FileRequestReceivedEvent
|
2012-01-16 01:37:00 +01:00
|
|
|
import threading
|
2010-06-06 17:22:52 +02:00
|
|
|
import logging
|
2013-01-02 13:54:02 +01:00
|
|
|
from common.jingle_ftstates import *
|
2010-06-06 17:22:52 +02:00
|
|
|
log = logging.getLogger('gajim.c.jingle_ft')
|
|
|
|
|
2010-07-15 07:38:53 +02:00
|
|
|
STATE_NOT_STARTED = 0
|
|
|
|
STATE_INITIALIZED = 1
|
2011-08-15 05:59:39 +02:00
|
|
|
# We send the candidates and we are waiting for a reply
|
2012-04-07 06:56:44 +02:00
|
|
|
STATE_CAND_SENT = 2
|
2011-08-15 05:59:39 +02:00
|
|
|
# We received the candidates and we are waiting to reply
|
2012-04-07 06:56:44 +02:00
|
|
|
STATE_CAND_RECEIVED = 3
|
2011-08-15 05:59:39 +02:00
|
|
|
# We have sent and received the candidates
|
|
|
|
# This also includes any candidate-error received or sent
|
2012-04-07 06:56:44 +02:00
|
|
|
STATE_CAND_SENT_AND_RECEIVED = 4
|
|
|
|
STATE_TRANSPORT_REPLACE = 5
|
2011-08-15 05:59:39 +02:00
|
|
|
# We are transfering the file
|
2012-04-07 06:56:44 +02:00
|
|
|
STATE_TRANSFERING = 6
|
2011-08-15 05:59:39 +02:00
|
|
|
|
2010-06-06 17:22:52 +02:00
|
|
|
|
|
|
|
class JingleFileTransfer(JingleContent):
|
2012-09-06 01:39:07 +02:00
|
|
|
|
2010-08-24 23:12:34 +02:00
|
|
|
def __init__(self, session, transport=None, file_props=None,
|
|
|
|
use_security=False):
|
2010-06-06 17:22:52 +02:00
|
|
|
JingleContent.__init__(self, session, transport)
|
2010-06-19 16:52:17 +02:00
|
|
|
log.info("transport value: %s" % transport)
|
2010-08-24 23:12:34 +02:00
|
|
|
# events we might be interested in
|
2010-06-06 17:22:52 +02:00
|
|
|
self.callbacks['session-initiate'] += [self.__on_session_initiate]
|
2012-08-22 12:21:45 +02:00
|
|
|
self.callbacks['session-initiate-sent'] += [
|
|
|
|
self.__on_session_initiate_sent]
|
2010-08-26 10:36:58 +02:00
|
|
|
self.callbacks['content-add'] += [self.__on_session_initiate]
|
2010-06-06 17:22:52 +02:00
|
|
|
self.callbacks['session-accept'] += [self.__on_session_accept]
|
2012-08-22 11:54:21 +02:00
|
|
|
self.callbacks['session-terminate'] += [self.__on_session_terminate]
|
2012-01-16 01:37:00 +01:00
|
|
|
self.callbacks['session-info'] += [self.__on_session_info]
|
2010-06-06 17:22:52 +02:00
|
|
|
self.callbacks['transport-accept'] += [self.__on_transport_accept]
|
2010-08-24 23:12:34 +02:00
|
|
|
self.callbacks['transport-replace'] += [self.__on_transport_replace]
|
2012-01-07 05:18:50 +01:00
|
|
|
self.callbacks['session-accept-sent'] += [self.__transport_setup]
|
2010-08-24 23:12:34 +02:00
|
|
|
# fallback transport method
|
2010-06-06 17:22:52 +02:00
|
|
|
self.callbacks['transport-reject'] += [self.__on_transport_reject]
|
|
|
|
self.callbacks['transport-info'] += [self.__on_transport_info]
|
2010-07-03 10:22:47 +02:00
|
|
|
self.callbacks['iq-result'] += [self.__on_iq_result]
|
2010-07-22 09:05:06 +02:00
|
|
|
self.use_security = use_security
|
2013-12-04 18:43:28 +01:00
|
|
|
self.x509_fingerprint = None
|
2010-06-06 17:22:52 +02:00
|
|
|
self.file_props = file_props
|
2012-09-15 16:39:35 +02:00
|
|
|
self.weinitiate = self.session.weinitiate
|
2012-12-09 21:37:51 +01:00
|
|
|
self.werequest = self.session.werequest
|
2010-06-14 15:21:22 +02:00
|
|
|
if self.file_props is not None:
|
2012-09-15 16:39:35 +02:00
|
|
|
if self.session.werequest:
|
|
|
|
self.file_props.sender = self.session.peerjid
|
|
|
|
self.file_props.receiver = self.session.ourjid
|
|
|
|
else:
|
|
|
|
self.file_props.sender = self.session.ourjid
|
|
|
|
self.file_props.receiver = self.session.peerjid
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.session_type = 'jingle'
|
2012-08-25 18:09:50 +02:00
|
|
|
self.file_props.sid = session.sid
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.transfered_size = []
|
2012-08-25 18:09:50 +02:00
|
|
|
self.file_props.transport_sid = self.transport.sid
|
2010-08-24 23:12:34 +02:00
|
|
|
log.info("FT request: %s" % file_props)
|
2010-06-14 15:21:22 +02:00
|
|
|
if transport is None:
|
2010-06-19 16:52:17 +02:00
|
|
|
self.transport = JingleTransportSocks5()
|
2011-07-18 00:28:38 +02:00
|
|
|
self.transport.set_connection(session.connection)
|
|
|
|
self.transport.set_file_props(self.file_props)
|
|
|
|
self.transport.set_our_jid(session.ourjid)
|
2010-06-19 16:52:17 +02:00
|
|
|
log.info('ourjid: %s' % session.ourjid)
|
2010-06-08 15:24:41 +02:00
|
|
|
self.session = session
|
2010-06-14 14:41:24 +02:00
|
|
|
self.media = 'file'
|
2011-08-15 05:59:39 +02:00
|
|
|
self.nominated_cand = {}
|
2012-08-23 13:10:30 +02:00
|
|
|
if gajim.contacts.is_gc_contact(session.connection.name,
|
|
|
|
session.peerjid):
|
2012-06-17 00:41:33 +02:00
|
|
|
roomjid = session.peerjid.split('/')[0]
|
2013-08-26 20:34:58 +02:00
|
|
|
dstaddr = hashlib.sha1(('%s%s%s' % (self.file_props.sid,
|
2013-01-05 00:03:36 +01:00
|
|
|
session.ourjid, roomjid)).encode('utf-8')).hexdigest()
|
2012-08-23 13:10:30 +02:00
|
|
|
self.file_props.dstaddr = dstaddr
|
2012-04-05 03:04:23 +02:00
|
|
|
self.state = STATE_NOT_STARTED
|
|
|
|
self.states = {STATE_INITIALIZED : StateInitialized(self),
|
|
|
|
STATE_CAND_SENT : StateCandSent(self),
|
|
|
|
STATE_CAND_RECEIVED : StateCandReceived(self),
|
|
|
|
STATE_TRANSFERING : StateTransfering(self),
|
|
|
|
STATE_TRANSPORT_REPLACE : StateTransportReplace(self),
|
|
|
|
STATE_CAND_SENT_AND_RECEIVED : StateCandSentAndRecv(self)
|
2012-08-22 12:21:45 +02:00
|
|
|
}
|
2012-04-05 03:04:23 +02:00
|
|
|
|
|
|
|
def __state_changed(self, nextstate, args=None):
|
|
|
|
# Executes the next state action and sets the next state
|
2012-08-22 18:09:40 +02:00
|
|
|
current_state = self.state
|
2012-04-05 03:04:23 +02:00
|
|
|
st = self.states[nextstate]
|
|
|
|
st.action(args)
|
2012-08-22 18:09:40 +02:00
|
|
|
# state can have been changed during the action. Don't go back.
|
|
|
|
if self.state == current_state:
|
|
|
|
self.state = nextstate
|
2010-08-24 23:12:34 +02:00
|
|
|
|
2010-06-06 17:22:52 +02:00
|
|
|
def __on_session_initiate(self, stanza, content, error, action):
|
2011-06-24 18:24:42 +02:00
|
|
|
gajim.nec.push_incoming_event(FileRequestReceivedEvent(None,
|
|
|
|
conn=self.session.connection, stanza=stanza, jingle_content=content,
|
|
|
|
FT_content=self))
|
2012-09-06 01:39:07 +02:00
|
|
|
if self.session.request:
|
|
|
|
# accept the request
|
|
|
|
self.session.approve_content(self.media, self.name)
|
|
|
|
self.session.accept_session()
|
2012-08-23 23:45:38 +02:00
|
|
|
|
2012-01-16 01:37:00 +01:00
|
|
|
def __on_session_initiate_sent(self, stanza, content, error, action):
|
2012-08-25 17:14:38 +02:00
|
|
|
pass
|
2012-08-22 11:54:21 +02:00
|
|
|
|
2012-05-29 01:54:59 +02:00
|
|
|
def __send_hash(self):
|
|
|
|
# Send hash in a session info
|
2012-12-09 21:37:51 +01:00
|
|
|
checksum = nbxmpp.Node(tag='checksum', payload=[nbxmpp.Node(tag='file',
|
2012-08-22 12:21:45 +02:00
|
|
|
payload=[self._calcHash()])])
|
2012-12-09 21:37:51 +01:00
|
|
|
checksum.setNamespace(nbxmpp.NS_JINGLE_FILE_TRANSFER)
|
2012-05-29 01:54:59 +02:00
|
|
|
self.session.__session_info(checksum )
|
2012-09-22 19:25:55 +02:00
|
|
|
pjid = gajim.get_jid_without_resource(self.session.peerjid)
|
2012-08-29 21:06:04 +02:00
|
|
|
file_info = {'name' : self.file_props.name,
|
2012-09-02 18:59:55 +02:00
|
|
|
'file-name' : self.file_props.file_name,
|
2012-08-29 21:06:04 +02:00
|
|
|
'hash' : self.file_props.hash_,
|
|
|
|
'size' : self.file_props.size,
|
2012-09-22 19:25:55 +02:00
|
|
|
'date' : self.file_props.date,
|
|
|
|
'peerjid' : pjid
|
2012-08-29 21:06:04 +02:00
|
|
|
}
|
2012-09-23 04:16:03 +02:00
|
|
|
self.session.connection.set_file_info(file_info)
|
2012-08-29 21:06:04 +02:00
|
|
|
|
2012-05-29 01:54:59 +02:00
|
|
|
def _calcHash(self):
|
|
|
|
# Caculates the hash and returns a xep-300 hash stanza
|
2012-08-25 02:13:25 +02:00
|
|
|
if self.file_props.algo == None:
|
2012-01-16 01:37:00 +01:00
|
|
|
return
|
|
|
|
try:
|
2013-01-05 10:09:15 +01:00
|
|
|
file_ = open(self.file_props.file_name, 'rb')
|
2012-01-16 01:37:00 +01:00
|
|
|
except:
|
2012-01-24 22:51:26 +01:00
|
|
|
# can't open file
|
2012-01-16 01:37:00 +01:00
|
|
|
return
|
2012-12-09 21:37:51 +01:00
|
|
|
h = nbxmpp.Hashes()
|
2012-08-25 02:13:25 +02:00
|
|
|
hash_ = h.calculateHash(self.file_props.algo, file_)
|
2013-01-05 10:09:15 +01:00
|
|
|
file_.close()
|
2012-05-28 03:05:43 +02:00
|
|
|
# DEBUG
|
2012-09-18 06:13:31 +02:00
|
|
|
#hash_ = '1294809248109223'
|
2012-01-24 22:51:26 +01:00
|
|
|
if not hash_:
|
|
|
|
# Hash alogrithm not supported
|
|
|
|
return
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.hash_ = hash_
|
2012-08-25 02:13:25 +02:00
|
|
|
h.addHash(hash_, self.file_props.algo)
|
2012-05-29 01:54:59 +02:00
|
|
|
return h
|
2012-08-22 11:54:21 +02:00
|
|
|
|
2013-12-04 18:43:28 +01:00
|
|
|
def on_cert_received(self):
|
|
|
|
self.session.approve_session()
|
|
|
|
self.session.approve_content('file', name=self.name)
|
|
|
|
|
2010-06-06 17:22:52 +02:00
|
|
|
def __on_session_accept(self, stanza, content, error, action):
|
|
|
|
log.info("__on_session_accept")
|
2011-07-22 22:15:34 +02:00
|
|
|
con = self.session.connection
|
2010-07-22 10:20:14 +02:00
|
|
|
security = content.getTag('security')
|
|
|
|
if not security: # responder can not verify our fingerprint
|
|
|
|
self.use_security = False
|
2013-12-04 18:43:28 +01:00
|
|
|
else:
|
|
|
|
fingerprint = security.getTag('fingerprint')
|
|
|
|
if fingerprint:
|
|
|
|
fingerprint = fingerprint.getData()
|
|
|
|
self.x509_fingerprint = fingerprint
|
|
|
|
if not jingle_xtls.check_cert(gajim.get_jid_without_resource(
|
|
|
|
self.session.responder), fingerprint):
|
|
|
|
id_ = jingle_xtls.send_cert_request(con,
|
|
|
|
self.session.responder)
|
|
|
|
jingle_xtls.key_exchange_pend(id_,
|
|
|
|
self.continue_session_accept, [stanza])
|
|
|
|
raise nbxmpp.NodeProcessed
|
|
|
|
self.continue_session_accept(stanza)
|
|
|
|
|
|
|
|
def continue_session_accept(self, stanza):
|
|
|
|
con = self.session.connection
|
2011-06-29 00:31:07 +02:00
|
|
|
if self.state == STATE_TRANSPORT_REPLACE:
|
2012-09-15 16:39:35 +02:00
|
|
|
# If we are requesting we don't have the file
|
|
|
|
if self.session.werequest:
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2011-06-29 00:31:07 +02:00
|
|
|
# We send the file
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_TRANSFERING)
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.streamhosts = self.transport.remote_candidates
|
2012-08-25 17:14:38 +02:00
|
|
|
# Calculate file hash in a new thread
|
|
|
|
# if we haven't sent the hash already.
|
2012-10-13 20:31:16 +02:00
|
|
|
if self.file_props.hash_ is None and self.file_props.algo and \
|
2013-12-04 18:43:28 +01:00
|
|
|
not self.werequest:
|
2012-08-25 17:14:38 +02:00
|
|
|
self.hashThread = threading.Thread(target=self.__send_hash)
|
|
|
|
self.hashThread.start()
|
2012-06-14 18:27:23 +02:00
|
|
|
for host in self.file_props.streamhosts:
|
2012-01-08 20:44:15 +01:00
|
|
|
host['initiator'] = self.session.initiator
|
|
|
|
host['target'] = self.session.responder
|
2012-06-14 18:27:23 +02:00
|
|
|
host['sid'] = self.file_props.sid
|
2011-07-22 22:15:34 +02:00
|
|
|
fingerprint = None
|
|
|
|
if self.use_security:
|
|
|
|
fingerprint = 'client'
|
2012-08-22 12:55:57 +02:00
|
|
|
if self.transport.type_ == TransportType.SOCKS5:
|
2012-01-07 05:18:50 +01:00
|
|
|
gajim.socks5queue.connect_to_hosts(self.session.connection.name,
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.sid, self.on_connect,
|
2012-01-08 20:44:15 +01:00
|
|
|
self._on_connect_error, fingerprint=fingerprint,
|
|
|
|
receiving=False)
|
2013-12-04 18:43:28 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_TRANSFERING)
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2010-06-06 17:22:52 +02:00
|
|
|
|
|
|
|
def __on_session_terminate(self, stanza, content, error, action):
|
|
|
|
log.info("__on_session_terminate")
|
|
|
|
|
2012-01-16 01:37:00 +01:00
|
|
|
def __on_session_info(self, stanza, content, error, action):
|
|
|
|
pass
|
2012-08-22 11:54:21 +02:00
|
|
|
|
2010-06-06 17:22:52 +02:00
|
|
|
def __on_transport_accept(self, stanza, content, error, action):
|
|
|
|
log.info("__on_transport_accept")
|
|
|
|
|
|
|
|
def __on_transport_replace(self, stanza, content, error, action):
|
|
|
|
log.info("__on_transport_replace")
|
2010-08-24 23:12:34 +02:00
|
|
|
|
2010-06-06 17:22:52 +02:00
|
|
|
def __on_transport_reject(self, stanza, content, error, action):
|
|
|
|
log.info("__on_transport_reject")
|
|
|
|
|
|
|
|
def __on_transport_info(self, stanza, content, error, action):
|
|
|
|
log.info("__on_transport_info")
|
2012-09-21 23:42:16 +02:00
|
|
|
candError = content.getTag('transport').getTag('candidate-error')
|
|
|
|
candUsed = content.getTag('transport').getTag('candidate-used')
|
|
|
|
if (candError or candUsed) and \
|
|
|
|
self.state >= STATE_CAND_SENT_AND_RECEIVED:
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.OutOfOrder
|
2012-09-21 23:42:16 +02:00
|
|
|
if candError:
|
2012-08-30 11:09:39 +02:00
|
|
|
if not gajim.socks5queue.listener.connections:
|
|
|
|
gajim.socks5queue.listener.disconnect()
|
2011-08-15 05:59:39 +02:00
|
|
|
self.nominated_cand['peer-cand'] = False
|
2012-02-13 01:36:20 +01:00
|
|
|
if self.state == STATE_CAND_SENT:
|
2011-08-15 05:59:39 +02:00
|
|
|
if not self.nominated_cand['our-cand'] and \
|
|
|
|
not self.nominated_cand['peer-cand']:
|
|
|
|
if not self.weinitiate:
|
|
|
|
return
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_TRANSPORT_REPLACE)
|
2011-08-24 23:53:36 +02:00
|
|
|
else:
|
|
|
|
response = stanza.buildReply('result')
|
2011-12-29 14:08:35 +01:00
|
|
|
response.delChild(response.getQuery())
|
2011-08-24 23:53:36 +02:00
|
|
|
self.session.connection.connection.send(response)
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_TRANSFERING)
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2011-08-15 05:59:39 +02:00
|
|
|
else:
|
2012-04-05 03:04:23 +02:00
|
|
|
args = {'candError' : True}
|
|
|
|
self.__state_changed(STATE_CAND_RECEIVED, args)
|
2011-07-05 20:05:16 +02:00
|
|
|
return
|
2012-09-21 23:42:16 +02:00
|
|
|
if candUsed:
|
|
|
|
streamhost_cid = candUsed.getAttr('cid')
|
2012-08-30 11:09:39 +02:00
|
|
|
streamhost_used = None
|
|
|
|
for cand in self.transport.candidates:
|
|
|
|
if cand['candidate_id'] == streamhost_cid:
|
|
|
|
streamhost_used = cand
|
|
|
|
break
|
|
|
|
if streamhost_used == None or streamhost_used['type'] == 'proxy':
|
|
|
|
if not gajim.socks5queue.listener.connections:
|
|
|
|
gajim.socks5queue.listener.disconnect()
|
2011-10-29 06:09:45 +02:00
|
|
|
if content.getTag('transport').getTag('activated'):
|
|
|
|
self.state = STATE_TRANSFERING
|
|
|
|
jid = gajim.get_jid_without_resource(self.session.ourjid)
|
|
|
|
gajim.socks5queue.send_file(self.file_props,
|
|
|
|
self.session.connection.name, 'client')
|
|
|
|
return
|
2012-04-05 03:04:23 +02:00
|
|
|
args = {'content' : content,
|
|
|
|
'sendCand' : False}
|
2012-02-13 01:36:20 +01:00
|
|
|
if self.state == STATE_CAND_SENT:
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_CAND_SENT_AND_RECEIVED, args)
|
|
|
|
self.__state_changed(STATE_TRANSFERING)
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2010-07-13 04:38:31 +02:00
|
|
|
else:
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_CAND_RECEIVED, args)
|
2011-08-24 10:42:16 +02:00
|
|
|
|
2010-07-03 10:22:47 +02:00
|
|
|
def __on_iq_result(self, stanza, content, error, action):
|
|
|
|
log.info("__on_iq_result")
|
2010-08-24 23:12:34 +02:00
|
|
|
|
2012-04-05 03:04:23 +02:00
|
|
|
if self.state == STATE_NOT_STARTED:
|
|
|
|
self.__state_changed(STATE_INITIALIZED)
|
2011-08-15 05:59:39 +02:00
|
|
|
elif self.state == STATE_CAND_SENT_AND_RECEIVED:
|
|
|
|
if not self.nominated_cand['our-cand'] and \
|
2011-08-24 10:42:16 +02:00
|
|
|
not self.nominated_cand['peer-cand']:
|
|
|
|
if not self.weinitiate:
|
2011-08-15 05:59:39 +02:00
|
|
|
return
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_TRANSPORT_REPLACE)
|
2011-08-24 10:42:16 +02:00
|
|
|
return
|
2011-08-15 05:59:39 +02:00
|
|
|
# initiate transfer
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_TRANSFERING)
|
2012-08-22 11:54:21 +02:00
|
|
|
|
2012-01-08 20:44:15 +01:00
|
|
|
def __transport_setup(self, stanza=None, content=None, error=None,
|
|
|
|
action=None):
|
2012-01-07 05:18:50 +01:00
|
|
|
# Sets up a few transport specific things for the file transfer
|
2012-08-22 12:55:57 +02:00
|
|
|
if self.transport.type_ == TransportType.IBB:
|
2012-04-07 06:56:44 +02:00
|
|
|
# No action required, just set the state to transfering
|
2012-01-07 05:18:50 +01:00
|
|
|
self.state = STATE_TRANSFERING
|
2012-08-30 11:09:39 +02:00
|
|
|
else:
|
|
|
|
self._listen_host()
|
2012-08-22 11:54:21 +02:00
|
|
|
|
2012-04-05 03:04:23 +02:00
|
|
|
def on_connect(self, streamhost):
|
2010-07-05 07:46:53 +02:00
|
|
|
"""
|
|
|
|
send candidate-used stanza
|
|
|
|
"""
|
2010-08-24 23:12:34 +02:00
|
|
|
log.info('send_candidate_used')
|
2010-07-05 07:46:53 +02:00
|
|
|
if streamhost is None:
|
|
|
|
return
|
2012-04-05 03:04:23 +02:00
|
|
|
args = {'streamhost' : streamhost,
|
|
|
|
'sendCand' : True}
|
2011-08-15 05:59:39 +02:00
|
|
|
self.nominated_cand['our-cand'] = streamhost
|
2012-04-07 06:56:44 +02:00
|
|
|
self.__sendCand(args)
|
2011-08-15 05:59:39 +02:00
|
|
|
|
2011-10-29 06:09:45 +02:00
|
|
|
def _on_connect_error(self, sid):
|
2012-04-05 03:04:23 +02:00
|
|
|
log.info('connect error, sid=' + sid)
|
2012-04-18 02:57:34 +02:00
|
|
|
args = {'candError' : True,
|
2012-04-18 02:47:52 +02:00
|
|
|
'sendCand' : True}
|
2012-04-07 06:56:44 +02:00
|
|
|
self.__sendCand(args)
|
|
|
|
|
|
|
|
def __sendCand(self, args):
|
2012-02-13 01:36:20 +01:00
|
|
|
if self.state == STATE_CAND_RECEIVED:
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_CAND_SENT_AND_RECEIVED, args)
|
2011-08-15 05:59:39 +02:00
|
|
|
else:
|
2012-04-05 03:04:23 +02:00
|
|
|
self.__state_changed(STATE_CAND_SENT, args)
|
2011-08-24 10:42:16 +02:00
|
|
|
|
2010-07-03 10:22:47 +02:00
|
|
|
def _store_socks5_sid(self, sid, hash_id):
|
|
|
|
# callback from socsk5queue.start_listener
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.hash_ = hash_id
|
2011-08-24 10:42:16 +02:00
|
|
|
|
2012-01-07 05:18:50 +01:00
|
|
|
def _listen_host(self):
|
2012-06-14 18:27:23 +02:00
|
|
|
receiver = self.file_props.receiver
|
|
|
|
sender = self.file_props.sender
|
|
|
|
sha_str = helpers.get_auth_sha(self.file_props.sid, sender,
|
2012-01-08 20:44:15 +01:00
|
|
|
receiver)
|
2012-06-14 18:27:23 +02:00
|
|
|
self.file_props.sha_str = sha_str
|
2011-08-09 01:43:07 +02:00
|
|
|
port = gajim.config.get('file_transfers_port')
|
|
|
|
fingerprint = None
|
|
|
|
if self.use_security:
|
|
|
|
fingerprint = 'server'
|
|
|
|
if self.weinitiate:
|
|
|
|
listener = gajim.socks5queue.start_listener(port, sha_str,
|
2012-01-08 20:44:15 +01:00
|
|
|
self._store_socks5_sid, self.file_props,
|
2012-08-22 12:55:57 +02:00
|
|
|
fingerprint=fingerprint, typ='sender')
|
2011-08-09 01:43:07 +02:00
|
|
|
else:
|
|
|
|
listener = gajim.socks5queue.start_listener(port, sha_str,
|
2012-01-08 20:44:15 +01:00
|
|
|
self._store_socks5_sid, self.file_props,
|
2012-08-22 12:55:57 +02:00
|
|
|
fingerprint=fingerprint, typ='receiver')
|
2011-08-09 01:43:07 +02:00
|
|
|
if not listener:
|
2012-01-08 20:44:15 +01:00
|
|
|
# send error message, notify the user
|
2011-08-09 01:43:07 +02:00
|
|
|
return
|
2012-08-23 23:45:38 +02:00
|
|
|
|
2011-08-15 05:59:39 +02:00
|
|
|
def isOurCandUsed(self):
|
2011-08-22 01:02:58 +02:00
|
|
|
'''
|
|
|
|
If this method returns true then the candidate we nominated will be
|
|
|
|
used, if false, the candidate nominated by peer will be used
|
|
|
|
'''
|
2011-08-24 10:42:16 +02:00
|
|
|
|
2011-08-15 05:59:39 +02:00
|
|
|
if self.nominated_cand['peer-cand'] == False:
|
|
|
|
return True
|
|
|
|
if self.nominated_cand['our-cand'] == False:
|
|
|
|
return False
|
|
|
|
peer_pr = int(self.nominated_cand['peer-cand']['priority'])
|
|
|
|
our_pr = int(self.nominated_cand['our-cand']['priority'])
|
|
|
|
if peer_pr != our_pr:
|
2011-08-23 05:57:29 +02:00
|
|
|
return our_pr > peer_pr
|
2011-08-15 05:59:39 +02:00
|
|
|
else:
|
2011-08-22 01:02:58 +02:00
|
|
|
return self.weinitiate
|
2011-08-24 10:42:16 +02:00
|
|
|
|
2012-09-15 16:39:35 +02:00
|
|
|
def start_IBB_transfer(self):
|
|
|
|
if self.file_props.type_ == 's':
|
|
|
|
self.__state_changed(STATE_TRANSFERING)
|
|
|
|
|
2011-08-24 10:42:16 +02:00
|
|
|
|
2010-06-08 10:39:44 +02:00
|
|
|
def get_content(desc):
|
|
|
|
return JingleFileTransfer
|
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
contents[nbxmpp.NS_JINGLE_FILE_TRANSFER] = get_content
|