diff --git a/src/common/jingle.py b/src/common/jingle.py index 5c11b70ac..b8238a4b3 100644 --- a/src/common/jingle.py +++ b/src/common/jingle.py @@ -140,26 +140,18 @@ class ConnectionJingle(object): def start_file_transfer(self, jid, file_props): logger.info("start file transfer with file: %s" % file_props) - jingle = self.get_jingle_session(jid, media='file') contact = gajim.contacts.get_contact_with_highest_priority(self.name, gajim.get_jid_without_resource(jid)) if contact is None: return use_security = contact.supports(xmpp.NS_JINGLE_XTLS) - if jingle: - file_props['sid'] = jingle.sid - c = JingleFileTransfer(jingle, file_props=file_props, - use_security=use_security) - jingle.add_content('file' + helpers.get_random_string_16(), c) - jingle.on_session_state_changed(c) - else: - jingle = JingleSession(self, weinitiate=True, jid=jid) - self._sessions[jingle.sid] = jingle - file_props['sid'] = jingle.sid - c = JingleFileTransfer(jingle, file_props=file_props, - use_security=use_security) - jingle.add_content('file' + helpers.get_random_string_16(), c) - jingle.start_session() + jingle = JingleSession(self, weinitiate=True, jid=jid) + self._sessions[jingle.sid] = jingle + file_props['sid'] = jingle.sid + c = JingleFileTransfer(jingle, file_props=file_props, + use_security=use_security) + jingle.add_content('file' + helpers.get_random_string_16(), c) + jingle.start_session() return c.transport.sid diff --git a/src/common/jingle_ft.py b/src/common/jingle_ft.py index f2862640a..794d953e9 100644 --- a/src/common/jingle_ft.py +++ b/src/common/jingle_ft.py @@ -373,9 +373,6 @@ class JingleFileTransfer(JingleContent): def start_transfer(self): - # We start the transfer, session negociation is over. - self.session.state = 0 # STATE 0 SESSION_ENDED - self.state = STATE_TRANSFERING # It tells wether we start the transfer as client or server diff --git a/src/common/jingle_session.py b/src/common/jingle_session.py index f8ada4fdc..76c0aabd9 100644 --- a/src/common/jingle_session.py +++ b/src/common/jingle_session.py @@ -488,19 +488,25 @@ class JingleSession(object): # subscription) and the receiver has a policy of not communicating via # Jingle with unknown entities, it SHOULD return a # error. - - # Check if there's already a session with this user: - for session in self.connection.iter_jingle_sessions(self.peerjid): - if not session is self: - reason = xmpp.Node('reason') - alternative_session = reason.setTag('alternative-session') - alternative_session.setTagData('sid', session.sid) - self.__ack(stanza, jingle, error, action) - self._session_terminate(reason) - raise xmpp.NodeProcessed - + + # Lets check what kind of jingle session does the peer want contents, contents_rejected, reason_txt = self.__parse_contents(jingle) + + + # If we are not receivin a file + # Check if there's already a session with this user: + if contents[0][0] != 'file': + for session in self.connection.iter_jingle_sessions(self.peerjid): + if not session is self: + reason = xmpp.Node('reason') + alternative_session = reason.setTag('alternative-session') + alternative_session.setTagData('sid', session.sid) + self.__ack(stanza, jingle, error, action) + self._session_terminate(reason) + raise xmpp.NodeProcessed + + # If there's no content we understand... if not contents: @@ -699,6 +705,7 @@ class JingleSession(object): self.connection.connection.send(stanza) def _session_terminate(self, reason=None): + assert self.state != JingleStates.ended stanza, jingle = self.__make_jingle('session-terminate', reason=reason) self.__broadcast_all(stanza, jingle, None, 'session-terminate-sent') if self.connection.connection and self.connection.connected >= 2: diff --git a/src/common/socks5.py b/src/common/socks5.py index 992f84072..2aa5f991d 100644 --- a/src/common/socks5.py +++ b/src/common/socks5.py @@ -517,10 +517,10 @@ class Socks5: for ai in self.ais: try: self._sock = socket.socket(*ai[:3]) - ''' + if not self.fingerprint is None: self._sock = OpenSSL.SSL.Connection( - jingle_xtls.get_context('client'), self._sock)''' + jingle_xtls.get_context('client'), self._sock) # this will not block the GUI self._sock.setblocking(False) self._server = ai[4] @@ -956,12 +956,12 @@ class Socks5Sender(IdleObject): if _sock is not None: - '''if self.fingerprint is not None: + if self.fingerprint is not None: self._sock = OpenSSL.SSL.Connection( jingle_xtls.get_context('server'), _sock) else: self._sock.setblocking(False) - ''' + self.fd = _sock.fileno() self._recv = _sock.recv self._send = _sock.send @@ -1445,9 +1445,9 @@ class Socks5Listener(IdleObject): # try the different possibilities (ipv6, ipv4, etc.) try: self._serv = socket.socket(*ai[:3]) - '''if self.fingerprint is not None: + if self.fingerprint is not None: self._serv = OpenSSL.SSL.Connection( - jingle_xtls.get_context('server'), self._serv)''' + jingle_xtls.get_context('server'), self._serv) except socket.error, e: if e.args[0] == EAFNOSUPPORT: self.ai = None