create a new session for every new file transfer; enable OpenSSL
This commit is contained in:
parent
b85f96b929
commit
c491bd3f59
|
@ -140,26 +140,18 @@ class ConnectionJingle(object):
|
||||||
|
|
||||||
def start_file_transfer(self, jid, file_props):
|
def start_file_transfer(self, jid, file_props):
|
||||||
logger.info("start file transfer with file: %s" % 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,
|
contact = gajim.contacts.get_contact_with_highest_priority(self.name,
|
||||||
gajim.get_jid_without_resource(jid))
|
gajim.get_jid_without_resource(jid))
|
||||||
if contact is None:
|
if contact is None:
|
||||||
return
|
return
|
||||||
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)
|
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)
|
||||||
if jingle:
|
jingle = JingleSession(self, weinitiate=True, jid=jid)
|
||||||
file_props['sid'] = jingle.sid
|
self._sessions[jingle.sid] = jingle
|
||||||
c = JingleFileTransfer(jingle, file_props=file_props,
|
file_props['sid'] = jingle.sid
|
||||||
use_security=use_security)
|
c = JingleFileTransfer(jingle, file_props=file_props,
|
||||||
jingle.add_content('file' + helpers.get_random_string_16(), c)
|
use_security=use_security)
|
||||||
jingle.on_session_state_changed(c)
|
jingle.add_content('file' + helpers.get_random_string_16(), c)
|
||||||
else:
|
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
|
return c.transport.sid
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -373,9 +373,6 @@ class JingleFileTransfer(JingleContent):
|
||||||
|
|
||||||
def start_transfer(self):
|
def start_transfer(self):
|
||||||
|
|
||||||
# We start the transfer, session negociation is over.
|
|
||||||
self.session.state = 0 # STATE 0 SESSION_ENDED
|
|
||||||
|
|
||||||
self.state = STATE_TRANSFERING
|
self.state = STATE_TRANSFERING
|
||||||
|
|
||||||
# It tells wether we start the transfer as client or server
|
# It tells wether we start the transfer as client or server
|
||||||
|
|
|
@ -488,19 +488,25 @@ class JingleSession(object):
|
||||||
# subscription) and the receiver has a policy of not communicating via
|
# subscription) and the receiver has a policy of not communicating via
|
||||||
# Jingle with unknown entities, it SHOULD return a <service-unavailable/>
|
# Jingle with unknown entities, it SHOULD return a <service-unavailable/>
|
||||||
# error.
|
# 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
|
# Lets check what kind of jingle session does the peer want
|
||||||
contents, contents_rejected, reason_txt = self.__parse_contents(jingle)
|
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 there's no content we understand...
|
||||||
if not contents:
|
if not contents:
|
||||||
|
@ -699,6 +705,7 @@ class JingleSession(object):
|
||||||
self.connection.connection.send(stanza)
|
self.connection.connection.send(stanza)
|
||||||
|
|
||||||
def _session_terminate(self, reason=None):
|
def _session_terminate(self, reason=None):
|
||||||
|
assert self.state != JingleStates.ended
|
||||||
stanza, jingle = self.__make_jingle('session-terminate', reason=reason)
|
stanza, jingle = self.__make_jingle('session-terminate', reason=reason)
|
||||||
self.__broadcast_all(stanza, jingle, None, 'session-terminate-sent')
|
self.__broadcast_all(stanza, jingle, None, 'session-terminate-sent')
|
||||||
if self.connection.connection and self.connection.connected >= 2:
|
if self.connection.connection and self.connection.connected >= 2:
|
||||||
|
|
|
@ -517,10 +517,10 @@ class Socks5:
|
||||||
for ai in self.ais:
|
for ai in self.ais:
|
||||||
try:
|
try:
|
||||||
self._sock = socket.socket(*ai[:3])
|
self._sock = socket.socket(*ai[:3])
|
||||||
'''
|
|
||||||
if not self.fingerprint is None:
|
if not self.fingerprint is None:
|
||||||
self._sock = OpenSSL.SSL.Connection(
|
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
|
# this will not block the GUI
|
||||||
self._sock.setblocking(False)
|
self._sock.setblocking(False)
|
||||||
self._server = ai[4]
|
self._server = ai[4]
|
||||||
|
@ -956,12 +956,12 @@ class Socks5Sender(IdleObject):
|
||||||
|
|
||||||
|
|
||||||
if _sock is not None:
|
if _sock is not None:
|
||||||
'''if self.fingerprint is not None:
|
if self.fingerprint is not None:
|
||||||
self._sock = OpenSSL.SSL.Connection(
|
self._sock = OpenSSL.SSL.Connection(
|
||||||
jingle_xtls.get_context('server'), _sock)
|
jingle_xtls.get_context('server'), _sock)
|
||||||
else:
|
else:
|
||||||
self._sock.setblocking(False)
|
self._sock.setblocking(False)
|
||||||
'''
|
|
||||||
self.fd = _sock.fileno()
|
self.fd = _sock.fileno()
|
||||||
self._recv = _sock.recv
|
self._recv = _sock.recv
|
||||||
self._send = _sock.send
|
self._send = _sock.send
|
||||||
|
@ -1445,9 +1445,9 @@ class Socks5Listener(IdleObject):
|
||||||
# try the different possibilities (ipv6, ipv4, etc.)
|
# try the different possibilities (ipv6, ipv4, etc.)
|
||||||
try:
|
try:
|
||||||
self._serv = socket.socket(*ai[:3])
|
self._serv = socket.socket(*ai[:3])
|
||||||
'''if self.fingerprint is not None:
|
if self.fingerprint is not None:
|
||||||
self._serv = OpenSSL.SSL.Connection(
|
self._serv = OpenSSL.SSL.Connection(
|
||||||
jingle_xtls.get_context('server'), self._serv)'''
|
jingle_xtls.get_context('server'), self._serv)
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
if e.args[0] == EAFNOSUPPORT:
|
if e.args[0] == EAFNOSUPPORT:
|
||||||
self.ai = None
|
self.ai = None
|
||||||
|
|
Loading…
Reference in New Issue