Move ConnectionSocks5Bytestream code to module

This commit is contained in:
Philipp Hörist 2019-05-19 22:24:26 +02:00
parent 275e719da3
commit 2485227701
17 changed files with 127 additions and 129 deletions

View File

@ -1470,7 +1470,7 @@ class ChatControl(ChatControlBase):
app.events.remove_events(self.account, self.contact.jid, event=ev) app.events.remove_events(self.account, self.contact.jid, event=ev)
def _on_cancel_file_request(self, widget, file_props): def _on_cancel_file_request(self, widget, file_props):
app.connections[self.account].send_file_rejection(file_props) app.connections[self.account].get_module('Bytestream').send_file_rejection(file_props)
ev = self._get_file_props_event(file_props, 'file-request') ev = self._get_file_props_event(file_props, 'file-request')
if ev: if ev:
app.events.remove_events(self.account, self.contact.jid, event=ev) app.events.remove_events(self.account, self.contact.jid, event=ev)

View File

@ -588,7 +588,7 @@ class Connection(CommonConnection, ConnectionHandlers):
app.proxy65_manager.disconnect(self.connection) app.proxy65_manager.disconnect(self.connection)
self.terminate_sessions() self.terminate_sessions()
self.remove_all_transfers() self.get_module('Bytestream').remove_all_transfers()
self._unregister_new_handlers(self.connection) self._unregister_new_handlers(self.connection)
self.connection = None self.connection = None
@ -1348,7 +1348,7 @@ class Connection(CommonConnection, ConnectionHandlers):
# If we are already connected, and privacy rules are supported, send # If we are already connected, and privacy rules are supported, send
# offline presence first as it's required by XEP-0126 # offline presence first as it's required by XEP-0126
if self.connected > 1 and self.get_module('PrivacyLists').supported: if self.connected > 1 and self.get_module('PrivacyLists').supported:
self.remove_all_transfers() self.get_module('Bytestream').remove_all_transfers()
self.get_module('Presence').send_presence( self.get_module('Presence').send_presence(
typ='unavailable', typ='unavailable',
status=msg, status=msg,

View File

@ -30,9 +30,6 @@ import operator
import nbxmpp import nbxmpp
from gajim.common import app from gajim.common import app
from gajim.common import helpers
from gajim.common import jingle_xtls
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
from gajim.common.connection_handlers_events import StreamReceivedEvent from gajim.common.connection_handlers_events import StreamReceivedEvent
from gajim.common.connection_handlers_events import PresenceReceivedEvent from gajim.common.connection_handlers_events import PresenceReceivedEvent
from gajim.common.connection_handlers_events import StreamConflictReceivedEvent from gajim.common.connection_handlers_events import StreamConflictReceivedEvent
@ -181,28 +178,14 @@ class ConnectionHandlersBase:
return sess return sess
class ConnectionHandlers(ConnectionSocks5Bytestream, class ConnectionHandlers(ConnectionHandlersBase):
ConnectionHandlersBase):
def __init__(self): def __init__(self):
ConnectionSocks5Bytestream.__init__(self)
ConnectionHandlersBase.__init__(self) ConnectionHandlersBase.__init__(self)
app.nec.register_incoming_event(PresenceReceivedEvent) app.nec.register_incoming_event(PresenceReceivedEvent)
app.nec.register_incoming_event(StreamConflictReceivedEvent) app.nec.register_incoming_event(StreamConflictReceivedEvent)
app.nec.register_incoming_event(NotificationEvent) app.nec.register_incoming_event(NotificationEvent)
def _PubkeyGetCB(self, con, iq_obj):
log.info('PubkeyGetCB')
jid_from = helpers.get_full_jid_from_iq(iq_obj)
sid = iq_obj.getAttr('id')
jingle_xtls.send_cert(con, jid_from, sid)
raise nbxmpp.NodeProcessed
def _PubkeyResultCB(self, con, iq_obj):
log.info('PubkeyResultCB')
jid_from = helpers.get_full_jid_from_iq(iq_obj)
jingle_xtls.handle_new_cert(con, iq_obj, jid_from)
def _StreamCB(self, con, obj): def _StreamCB(self, con, obj):
log.debug('StreamCB') log.debug('StreamCB')
app.nec.push_incoming_event(StreamReceivedEvent(None, app.nec.push_incoming_event(StreamReceivedEvent(None,
@ -212,16 +195,5 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
# try to find another way to register handlers in each class # try to find another way to register handlers in each class
# that defines handlers # that defines handlers
con.RegisterHandler('iq', self._bytestreamSetCB, 'set',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamResultCB, 'result',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamErrorCB, 'error',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._ResultCB, 'result')
con.RegisterHandler('unknown', self._StreamCB, con.RegisterHandler('unknown', self._StreamCB,
nbxmpp.NS_XMPP_STREAMS, xmlns=nbxmpp.NS_STREAMS) nbxmpp.NS_XMPP_STREAMS, xmlns=nbxmpp.NS_STREAMS)
con.RegisterHandler('iq', self._PubkeyGetCB, 'get',
nbxmpp.NS_PUBKEY_PUBKEY)
con.RegisterHandler('iq', self._PubkeyResultCB, 'result',
nbxmpp.NS_PUBKEY_PUBKEY)

View File

@ -170,7 +170,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
def generate(self): def generate(self):
self.id_ = self.stanza.getID() self.id_ = self.stanza.getID()
self.fjid = self.conn._ft_get_from(self.stanza) self.fjid = self.conn.get_module('Bytestream')._ft_get_from(self.stanza)
self.jid = app.get_jid_without_resource(self.fjid) self.jid = app.get_jid_without_resource(self.fjid)
if self.jingle_content: if self.jingle_content:
secu = self.jingle_content.getTag('security') secu = self.jingle_content.getTag('security')
@ -201,7 +201,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
if self.jingle_content.getAttr('creator') == 'initiator': if self.jingle_content.getAttr('creator') == 'initiator':
file_tag = desc.getTag('file') file_tag = desc.getTag('file')
self.file_props.sender = self.fjid self.file_props.sender = self.fjid
self.file_props.receiver = self.conn._ft_get_our_jid() self.file_props.receiver = self.conn.get_module('Bytestream')._ft_get_our_jid()
else: else:
file_tag = desc.getTag('file') file_tag = desc.getTag('file')
h = file_tag.getTag('hash') h = file_tag.getTag('hash')
@ -212,7 +212,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
file_info = self.conn.get_module('Jingle').get_file_info( file_info = self.conn.get_module('Jingle').get_file_info(
pjid, hash_=h, name=n, account=self.conn.name) pjid, hash_=h, name=n, account=self.conn.name)
self.file_props.file_name = file_info['file-name'] self.file_props.file_name = file_info['file-name']
self.file_props.sender = self.conn._ft_get_our_jid() self.file_props.sender = self.conn.get_module('Bytestream')._ft_get_our_jid()
self.file_props.receiver = self.fjid self.file_props.receiver = self.fjid
self.file_props.type_ = 's' self.file_props.type_ = 's'
for child in file_tag.getChildren(): for child in file_tag.getChildren():
@ -236,7 +236,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
self.file_props.transport_sid = self.file_props.sid self.file_props.transport_sid = self.file_props.sid
profile = si.getAttr('profile') profile = si.getAttr('profile')
if profile != nbxmpp.NS_FILE: if profile != nbxmpp.NS_FILE:
self.conn.send_file_rejection(self.file_props, code='400', self.conn.get_module('Bytestream').send_file_rejection(self.file_props, code='400',
typ='profile') typ='profile')
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
feature_tag = si.getTag('feature', namespace=nbxmpp.NS_FEATURE) feature_tag = si.getTag('feature', namespace=nbxmpp.NS_FEATURE)
@ -254,7 +254,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
nbxmpp.NS_IBB in values: nbxmpp.NS_IBB in values:
break break
else: else:
self.conn.send_file_rejection(self.file_props, code='400', self.conn.get_module('Bytestream').send_file_rejection(self.file_props, code='400',
typ='stream') typ='stream')
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
file_tag = si.getTag('file') file_tag = si.getTag('file')
@ -269,7 +269,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
if mime_type is not None: if mime_type is not None:
self.file_props.mime_type = mime_type self.file_props.mime_type = mime_type
self.file_props.sender = self.fjid self.file_props.sender = self.fjid
self.file_props.receiver = self.conn._ft_get_our_jid() self.file_props.receiver = self.conn.get_module('Bytestream')._ft_get_our_jid()
self.file_props.request_id = self.id_ self.file_props.request_id = self.id_
file_desc_tag = file_tag.getTag('desc') file_desc_tag = file_tag.getTag('desc')
if file_desc_tag is not None: if file_desc_tag is not None:

View File

@ -305,7 +305,7 @@ class JingleTransportSocks5(JingleTransport):
priority = (2**16) * type_preference priority = (2**16) * type_preference
proxy_cand = [] proxy_cand = []
socks5conn = self.connection socks5conn = self.connection
proxyhosts = socks5conn._get_file_transfer_proxies_from_config(self.file_props) proxyhosts = socks5conn.get_module('Bytestream')._get_file_transfer_proxies_from_config(self.file_props)
if proxyhosts: if proxyhosts:
self.file_props.proxyhosts = proxyhosts self.file_props.proxyhosts = proxyhosts

View File

@ -76,6 +76,7 @@ MODULES = [
'announce', 'announce',
'ibb', 'ibb',
'jingle', 'jingle',
'bytestream',
] ]
_imported_modules = [] # type: List[tuple] _imported_modules = [] # type: List[tuple]

View File

@ -28,6 +28,7 @@ import socket
import logging import logging
import nbxmpp import nbxmpp
from nbxmpp.structs import StanzaHandler
from gi.repository import GLib from gi.repository import GLib
from gajim.common import app from gajim.common import app
@ -35,9 +36,10 @@ from gajim.common import helpers
from gajim.common import jingle_xtls from gajim.common import jingle_xtls
from gajim.common.file_props import FilesProp from gajim.common.file_props import FilesProp
from gajim.common.socks5 import Socks5SenderClient from gajim.common.socks5 import Socks5SenderClient
from gajim.common.modules.base import BaseModule
log = logging.getLogger('gajim.c.p.bytestream') log = logging.getLogger('gajim.c.m.bytestream')
def is_transfer_paused(file_props): def is_transfer_paused(file_props):
if file_props.stopped: if file_props.stopped:
@ -71,33 +73,61 @@ def is_transfer_stopped(file_props):
return True return True
class ConnectionBytestream: class Bytestream(BaseModule):
def __init__(self, con):
BaseModule.__init__(self, con)
def pass_bytestream_disco(self, from_, identities, features, data, node): self.handlers = [
StanzaHandler(name='iq',
typ='result',
ns=nbxmpp.NS_BYTESTREAM,
callback=self._bytestreamResultCB),
StanzaHandler(name='iq',
typ='error',
ns=nbxmpp.NS_BYTESTREAM,
callback=self._bytestreamErrorCB),
StanzaHandler(name='iq',
typ='set',
ns=nbxmpp.NS_BYTESTREAM,
callback=self._bytestreamSetCB),
StanzaHandler(name='iq',
typ='result',
callback=self._ResultCB),
]
def pass_disco(self, from_, _identities, features, _data, _node):
if nbxmpp.NS_BYTESTREAM not in features: if nbxmpp.NS_BYTESTREAM not in features:
return return
if app.config.get_per('accounts', self.name, 'use_ft_proxies'): if app.config.get_per('accounts', self._account, 'use_ft_proxies'):
log.info('Discovered proxy: %s', from_) log.info('Discovered proxy: %s', from_)
our_fjid = self.get_own_jid() our_fjid = self._con.get_own_jid()
testit = app.config.get_per( testit = app.config.get_per(
'accounts', self.name, 'test_ft_proxies_on_startup') 'accounts', self._account, 'test_ft_proxies_on_startup')
app.proxy65_manager.resolve( app.proxy65_manager.resolve(
from_, self.connection, str(our_fjid), from_, self._con.connection, str(our_fjid),
default=self.name, testit=testit) default=self._account, testit=testit)
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
def _ft_get_our_jid(self): def _ft_get_our_jid(self):
our_jid = app.get_jid_from_account(self.name) if self._account == 'Local':
resource = self.server_resource return app.get_jid_from_account(self._account)
our_jid = app.get_jid_from_account(self._account)
resource = self._con.server_resource
return our_jid + '/' + resource return our_jid + '/' + resource
def _ft_get_receiver_jid(self, file_props): def _ft_get_receiver_jid(self, file_props):
if self._account == 'Local':
return file_props.receiver.jid
return file_props.receiver.jid + '/' + file_props.receiver.resource return file_props.receiver.jid + '/' + file_props.receiver.resource
def _ft_get_from(self, iq_obj): def _ft_get_from(self, iq_obj):
if self._account == 'Local':
return iq_obj.getFrom()
return helpers.get_full_jid_from_iq(iq_obj) return helpers.get_full_jid_from_iq(iq_obj)
def _ft_get_streamhost_jid_attr(self, streamhost): def _ft_get_streamhost_jid_attr(self, streamhost):
if self._account == 'Local':
return streamhost.getAttr('jid')
return helpers.parse_jid(streamhost.getAttr('jid')) return helpers.parse_jid(streamhost.getAttr('jid'))
def send_file_approval(self, file_props): def send_file_approval(self, file_props):
@ -105,13 +135,13 @@ class ConnectionBytestream:
Send iq, confirming that we want to download the file Send iq, confirming that we want to download the file
""" """
# user response to ConfirmationDialog may come after we've disconneted # user response to ConfirmationDialog may come after we've disconneted
if not self.connection or self.connected < 2: if not self._con.connection or self._con.connected < 2:
return return
# file transfer initiated by a jingle session # file transfer initiated by a jingle session
log.info("send_file_approval: jingle session accept") log.info("send_file_approval: jingle session accept")
session = self.get_module('Jingle').get_jingle_session( session = self._con.get_module('Jingle').get_jingle_session(
file_props.sender, file_props.sid) file_props.sender, file_props.sid)
if not session: if not session:
return return
@ -129,8 +159,8 @@ class ConnectionBytestream:
if not jingle_xtls.check_cert( if not jingle_xtls.check_cert(
app.get_jid_without_resource(file_props.sender), app.get_jid_without_resource(file_props.sender),
fingerprint): fingerprint):
id_ = jingle_xtls.send_cert_request(self, id_ = jingle_xtls.send_cert_request(
file_props.sender) self._con, file_props.sender)
jingle_xtls.key_exchange_pend(id_, jingle_xtls.key_exchange_pend(id_,
content.on_cert_received, []) content.on_cert_received, [])
return return
@ -146,7 +176,7 @@ class ConnectionBytestream:
invalid stream or 'profile' for invalid profile invalid stream or 'profile' for invalid profile
""" """
# user response to ConfirmationDialog may come after we've disconnected # user response to ConfirmationDialog may come after we've disconnected
if not self.connection or self.connected < 2: if not self._con.connection or self._con.connected < 2:
return return
if file_props.sid in self._sessions: if file_props.sid in self._sessions:
@ -154,14 +184,11 @@ class ConnectionBytestream:
jingle.cancel_session() jingle.cancel_session()
return return
class ConnectionSocks5Bytestream(ConnectionBytestream):
def send_success_connect_reply(self, streamhost): def send_success_connect_reply(self, streamhost):
""" """
Send reply to the initiator of FT that we made a connection Send reply to the initiator of FT that we made a connection
""" """
if not self.connection or self.connected < 2: if not self._con.connection or self._con.connected < 2:
return return
if streamhost is None: if streamhost is None:
return None return None
@ -171,7 +198,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
query = iq.setTag('query', namespace=nbxmpp.NS_BYTESTREAM) query = iq.setTag('query', namespace=nbxmpp.NS_BYTESTREAM)
stream_tag = query.setTag('streamhost-used') stream_tag = query.setTag('streamhost-used')
stream_tag.setAttr('jid', streamhost['jid']) stream_tag.setAttr('jid', streamhost['jid'])
self.connection.send(iq) self._con.connection.send(iq)
def stop_all_active_file_transfers(self, contact): def stop_all_active_file_transfers(self, contact):
""" """
@ -187,7 +214,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
from gajim.common.connection_handlers_events import \ from gajim.common.connection_handlers_events import \
FileRequestErrorEvent FileRequestErrorEvent
app.nec.push_incoming_event(FileRequestErrorEvent(None, app.nec.push_incoming_event(FileRequestErrorEvent(None,
conn=self, jid=contact.jid, file_props=file_props, conn=self._con, jid=contact.jid, file_props=file_props,
error_msg='')) error_msg=''))
sender_jid = file_props.sender sender_jid = file_props.sender
if contact.get_full_jid() == sender_jid: if contact.get_full_jid() == sender_jid:
@ -222,7 +249,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
""" """
Send iq for the present streamhosts and proxies Send iq for the present streamhosts and proxies
""" """
if not self.connection or self.connected < 2: if not self._con.connection or self._con.connected < 2:
return return
receiver = file_props.receiver receiver = file_props.receiver
sender = file_props.sender sender = file_props.sender
@ -236,7 +263,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
if not listener: if not listener:
file_props.error = -5 file_props.error = -5
from gajim.common.connection_handlers_events import FileRequestErrorEvent from gajim.common.connection_handlers_events import FileRequestErrorEvent
app.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, app.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self._con,
jid=receiver, file_props=file_props, error_msg='')) jid=receiver, file_props=file_props, error_msg=''))
self._connect_error(file_props.sid, error='not-acceptable', self._connect_error(file_props.sid, error='not-acceptable',
error_type='modify') error_type='modify')
@ -262,10 +289,10 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
streamhost.setAttr('jid', sender) streamhost.setAttr('jid', sender)
def _add_local_ips_as_streamhosts_to_query(self, query, file_props): def _add_local_ips_as_streamhosts_to_query(self, query, file_props):
if not app.config.get_per('accounts', self.name, 'ft_send_local_ips'): if not app.config.get_per('accounts', self._account, 'ft_send_local_ips'):
return return
try: try:
my_ips = [self.peerhost[0]] # The ip we're connected to server with my_ips = [self._con.peerhost[0]] # The ip we're connected to server with
# all IPs from local DNS # all IPs from local DNS
for addr in socket.getaddrinfo(socket.gethostname(), None): for addr in socket.getaddrinfo(socket.gethostname(), None):
if not addr[4][0] in my_ips and not addr[4][0].startswith('127') and not addr[4][0] == '::1': if not addr[4][0] in my_ips and not addr[4][0].startswith('127') and not addr[4][0] == '::1':
@ -292,16 +319,16 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
def _add_upnp_igd_as_streamhost_to_query(self, query, file_props, iq): def _add_upnp_igd_as_streamhost_to_query(self, query, file_props, iq):
if not app.is_installed('UPNP'): if not app.is_installed('UPNP'):
self.connection.send(iq) self._con.connection.send(iq)
return return
my_ip = self.peerhost[0] my_ip = self._con.peerhost[0]
# check if we are connected with an IPv4 address # check if we are connected with an IPv4 address
try: try:
socket.inet_aton(my_ip) socket.inet_aton(my_ip)
except socket.error: except socket.error:
self.connection.send(iq) self._con.connection.send(iq)
return return
def ip_is_local(ip): def ip_is_local(ip):
@ -351,12 +378,12 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
else: else:
self._add_streamhosts_to_query(query, file_props.sender, self._add_streamhosts_to_query(query, file_props.sender,
ext_port, [ext_ip]) ext_port, [ext_ip])
self.connection.send(iq) self._con.connection.send(iq)
cleanup_gupnp() cleanup_gupnp()
def fail(s, error, proto, ext_ip, local_ip, local_port, desc): def fail(s, error, proto, ext_ip, local_ip, local_port, desc):
log.debug('Got GUPnP-IGD error') log.debug('Got GUPnP-IGD error')
self.connection.send(iq) self._con.connection.send(iq)
cleanup_gupnp() cleanup_gupnp()
def no_upnp_reply(): def no_upnp_reply():
@ -364,7 +391,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
# stop trying to use it # stop trying to use it
app.disable_dependency('UPNP') app.disable_dependency('UPNP')
self.no_gupnp_reply_id = 0 self.no_gupnp_reply_id = 0
self.connection.send(iq) self._con.connection.send(iq)
cleanup_gupnp() cleanup_gupnp()
return False return False
@ -389,16 +416,16 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
proxyhost['port'], [proxyhost['host']]) proxyhost['port'], [proxyhost['host']])
def _get_file_transfer_proxies_from_config(self, file_props): def _get_file_transfer_proxies_from_config(self, file_props):
configured_proxies = app.config.get_per('accounts', self.name, configured_proxies = app.config.get_per('accounts', self._account,
'file_transfer_proxies') 'file_transfer_proxies')
shall_use_proxies = app.config.get_per('accounts', self.name, shall_use_proxies = app.config.get_per('accounts', self._account,
'use_ft_proxies') 'use_ft_proxies')
if shall_use_proxies: if shall_use_proxies:
proxyhost_dicts = [] proxyhost_dicts = []
proxies = [] proxies = []
if configured_proxies: if configured_proxies:
proxies = [item.strip() for item in configured_proxies.split(',')] proxies = [item.strip() for item in configured_proxies.split(',')]
default_proxy = app.proxy65_manager.get_default_for_name(self.name) default_proxy = app.proxy65_manager.get_default_for_name(self._account)
if default_proxy: if default_proxy:
# add/move default proxy at top of the others # add/move default proxy at top of the others
if default_proxy in proxies: if default_proxy in proxies:
@ -406,7 +433,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
proxies.insert(0, default_proxy) proxies.insert(0, default_proxy)
for proxy in proxies: for proxy in proxies:
(host, _port, jid) = app.proxy65_manager.get_proxy(proxy, self.name) (host, _port, jid) = app.proxy65_manager.get_proxy(proxy, self._account)
if not host: if not host:
continue continue
host_dict = { host_dict = {
@ -436,9 +463,9 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
Called when there is an error establishing BS connection, or when Called when there is an error establishing BS connection, or when
connection is rejected connection is rejected
""" """
if not self.connection or self.connected < 2: if not self._con.connection or self._con.connected < 2:
return return
file_props = FilesProp.getFileProp(self.name, sid) file_props = FilesProp.getFileProp(self._account, sid)
if file_props is None: if file_props is None:
log.error('can not send iq error on failed transfer') log.error('can not send iq error on failed transfer')
return return
@ -451,22 +478,22 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
err = iq.setTag('error') err = iq.setTag('error')
err.setAttr('type', error_type) err.setAttr('type', error_type)
err.setTag(error, namespace=nbxmpp.NS_STANZAS) err.setTag(error, namespace=nbxmpp.NS_STANZAS)
self.connection.send(iq) self._con.connection.send(iq)
if msg: if msg:
self.disconnect_transfer(file_props) self.disconnect_transfer(file_props)
file_props.error = -3 file_props.error = -3
from gajim.common.connection_handlers_events import \ from gajim.common.connection_handlers_events import \
FileRequestErrorEvent FileRequestErrorEvent
app.nec.push_incoming_event(FileRequestErrorEvent(None, app.nec.push_incoming_event(FileRequestErrorEvent(None,
conn=self, jid=to, file_props=file_props, error_msg=msg)) conn=self._con, jid=to, file_props=file_props, error_msg=msg))
def _proxy_auth_ok(self, proxy): def _proxy_auth_ok(self, proxy):
""" """
Called after authentication to proxy server Called after authentication to proxy server
""" """
if not self.connection or self.connected < 2: if not self._con.connection or self._con.connected < 2:
return return
file_props = FilesProp.getFileProp(self.name, proxy['sid']) file_props = FilesProp.getFileProp(self._account, proxy['sid'])
iq = nbxmpp.Iq(to=proxy['initiator'], typ='set') iq = nbxmpp.Iq(to=proxy['initiator'], typ='set')
auth_id = "au_" + proxy['sid'] auth_id = "au_" + proxy['sid']
iq.setID(auth_id) iq.setID(auth_id)
@ -475,7 +502,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
activate = query.setTag('activate') activate = query.setTag('activate')
activate.setData(file_props.proxy_receiver) activate.setData(file_props.proxy_receiver)
iq.setID(auth_id) iq.setID(auth_id)
self.connection.send(iq) self._con.connection.send(iq)
# register xmpppy handlers for bytestream and FT stanzas # register xmpppy handlers for bytestream and FT stanzas
def _bytestreamErrorCB(self, con, iq_obj): def _bytestreamErrorCB(self, con, iq_obj):
@ -490,7 +517,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
return return
file_props.error = -4 file_props.error = -4
from gajim.common.connection_handlers_events import FileRequestErrorEvent from gajim.common.connection_handlers_events import FileRequestErrorEvent
app.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, app.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self._con,
jid=jid, file_props=file_props, error_msg='')) jid=jid, file_props=file_props, error_msg=''))
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
@ -499,7 +526,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
id_ = iq_obj.getAttr('id') id_ = iq_obj.getAttr('id')
query = iq_obj.getTag('query') query = iq_obj.getTag('query')
sid = query.getAttr('sid') sid = query.getAttr('sid')
file_props = FilesProp.getFileProp(self.name, sid) file_props = FilesProp.getFileProp(self._account, sid)
streamhosts = [] streamhosts = []
for item in query.getChildren(): for item in query.getChildren():
if item.getName() == 'streamhost': if item.getName() == 'streamhost':
@ -527,7 +554,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
file_props.streamhosts.extend(streamhosts) file_props.streamhosts.extend(streamhosts)
else: else:
file_props.streamhosts = streamhosts file_props.streamhosts = streamhosts
app.socks5queue.connect_to_hosts(self.name, sid, app.socks5queue.connect_to_hosts(self._account, sid,
self.send_success_connect_reply, None) self.send_success_connect_reply, None)
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
else: else:
@ -539,7 +566,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
self._connect_error(sid, 'item-not-found', 'cancel', self._connect_error(sid, 'item-not-found', 'cancel',
msg='Could not connect to given hosts') msg='Could not connect to given hosts')
if file_props.type_ == 'r': if file_props.type_ == 'r':
app.socks5queue.connect_to_hosts(self.name, sid, app.socks5queue.connect_to_hosts(self._account, sid,
self.send_success_connect_reply, _connection_error) self.send_success_connect_reply, _connection_error)
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
@ -554,7 +581,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
return return
frm = self._ft_get_from(iq_obj) frm = self._ft_get_from(iq_obj)
id_ = real_id[3:] id_ = real_id[3:]
file_props = FilesProp.getFilePropByTransportSid(self.name, id_) file_props = FilesProp.getFilePropByTransportSid(self._account, id_)
if file_props.streamhost_used: if file_props.streamhost_used:
for host in file_props.proxyhosts: for host in file_props.proxyhosts:
if host['initiator'] == frm and 'idx' in host: if host['initiator'] == frm and 'idx' in host:
@ -572,7 +599,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
except Exception: # this bytestream result is not what we need except Exception: # this bytestream result is not what we need
pass pass
id_ = real_id[3:] id_ = real_id[3:]
file_props = FilesProp.getFileProp(self.name, id_) file_props = FilesProp.getFileProp(self._account, id_)
if file_props is None: if file_props is None:
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
if streamhost is None: if streamhost is None:
@ -596,7 +623,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
if file_props.stopped: if file_props.stopped:
self.remove_transfer(file_props) self.remove_transfer(file_props)
else: else:
app.socks5queue.send_file(file_props, self.name, 'server') app.socks5queue.send_file(file_props, self._account, 'server')
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
proxy = None proxy = None
@ -618,7 +645,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
port=int(proxy['port']), fingerprint=None, port=int(proxy['port']), fingerprint=None,
connected=False, file_props=file_props) connected=False, file_props=file_props)
sender.streamhost = proxy sender.streamhost = proxy
app.socks5queue.add_sockobj(self.name, sender) app.socks5queue.add_sockobj(self._account, sender)
proxy['idx'] = sender.queue_idx proxy['idx'] = sender.queue_idx
app.socks5queue.on_success[file_props.sid] = self._proxy_auth_ok app.socks5queue.on_success[file_props.sid] = self._proxy_auth_ok
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
@ -626,21 +653,10 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
if file_props.stopped: if file_props.stopped:
self.remove_transfer(file_props) self.remove_transfer(file_props)
else: else:
app.socks5queue.send_file(file_props, self.name, 'server') app.socks5queue.send_file(file_props, self._account, 'server')
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
class ConnectionSocks5BytestreamZeroconf(ConnectionSocks5Bytestream): def get_instance(*args, **kwargs):
return Bytestream(*args, **kwargs), 'Bytestream'
def _ft_get_from(self, iq_obj):
return iq_obj.getFrom()
def _ft_get_our_jid(self):
return app.get_jid_from_account(self.name)
def _ft_get_receiver_jid(self, file_props):
return file_props.receiver.jid
def _ft_get_streamhost_jid_attr(self, streamhost):
return streamhost.getAttr('jid')

View File

@ -162,7 +162,7 @@ class Discovery(BaseModule):
try: try:
self._con.get_module('MUC').pass_disco(from_, *args) self._con.get_module('MUC').pass_disco(from_, *args)
self._con.get_module('HTTPUpload').pass_disco(from_, *args) self._con.get_module('HTTPUpload').pass_disco(from_, *args)
self._con.pass_bytestream_disco(from_, *args) self._con.get_module('Bytestream').pass_disco(from_, *args)
except nbxmpp.NodeProcessed: except nbxmpp.NodeProcessed:
pass pass

View File

@ -53,7 +53,7 @@ class Iq(BaseModule):
jid=properties.jid.getBare(), jid=properties.jid.getBare(),
file_props=file_props, file_props=file_props,
error_msg=properties.error.message)) error_msg=properties.error.message))
self._con.disconnect_transfer(file_props) self._con.get_module('Bytestream').disconnect_transfer(file_props)
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
if properties.error.type == Error.ITEM_NOT_FOUND: if properties.error.type == Error.ITEM_NOT_FOUND:
@ -65,7 +65,7 @@ class Iq(BaseModule):
account=self._account, account=self._account,
jid=str(properties.jid), jid=str(properties.jid),
file_props=file_props)) file_props=file_props))
self._con.disconnect_transfer(file_props) self._con.get_module('Bytestream').disconnect_transfer(file_props)
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
app.nec.push_incoming_event( app.nec.push_incoming_event(

View File

@ -35,6 +35,7 @@ from nbxmpp.structs import StanzaHandler
from gajim.common import helpers from gajim.common import helpers
from gajim.common import app from gajim.common import app
from gajim.common import jingle_xtls
from gajim.common.modules.base import BaseModule from gajim.common.modules.base import BaseModule
from gajim.common.jingle_session import JingleSession from gajim.common.jingle_session import JingleSession
@ -63,6 +64,14 @@ class Jingle(BaseModule):
typ='set', typ='set',
ns=nbxmpp.NS_JINGLE, ns=nbxmpp.NS_JINGLE,
callback=self._on_jingle_iq), callback=self._on_jingle_iq),
StanzaHandler(name='iq',
typ='get',
ns=nbxmpp.NS_PUBKEY_PUBKEY,
callback=self._on_pubkey_request),
StanzaHandler(name='iq',
typ='result',
ns=nbxmpp.NS_PUBKEY_PUBKEY,
callback=self._pubkey_result_received),
] ]
# dictionary: sessionid => JingleSession object # dictionary: sessionid => JingleSession object
@ -84,7 +93,19 @@ class Jingle(BaseModule):
self._sessions[sid].callbacks = [] self._sessions[sid].callbacks = []
del self._sessions[sid] del self._sessions[sid]
def _on_jingle_iq(self, con, stanza): def _on_pubkey_request(self, con, stanza, _properties):
jid_from = helpers.get_full_jid_from_iq(stanza)
self._log.info('Pubkey request from %s', jid_from)
sid = stanza.getAttr('id')
jingle_xtls.send_cert(con, jid_from, sid)
raise nbxmpp.NodeProcessed
def _pubkey_result_received(self, con, stanza, _properties):
jid_from = helpers.get_full_jid_from_iq(stanza)
self._log.info('Pubkey result from %s', jid_from)
jingle_xtls.handle_new_cert(con, stanza, jid_from)
def _on_jingle_iq(self, con, stanza, properties):
""" """
The jingle stanza dispatcher The jingle stanza dispatcher

View File

@ -201,7 +201,7 @@ class Presence(BaseModule):
if properties.type.is_unavailable: if properties.type.is_unavailable:
# TODO: This causes problems when another # TODO: This causes problems when another
# resource signs off! # resource signs off!
self._con.stop_all_active_file_transfers(contact) self._con.get_module('Bytestream').stop_all_active_file_transfers(contact)
self._log_presence(properties) self._log_presence(properties)
@staticmethod @staticmethod

View File

@ -1,3 +0,0 @@
"""
Implementations of specific XMPP protocols and XEPs
"""

View File

@ -327,12 +327,6 @@ class P2PClient(IdleObject):
self.RegisterHandler(*StanzaHandler(name='message', self.RegisterHandler(*StanzaHandler(name='message',
callback=self._caller._messageCB)) callback=self._caller._messageCB))
self.RegisterHandler('iq', self._caller._bytestreamSetCB, 'set',
nbxmpp.NS_BYTESTREAM)
self.RegisterHandler('iq', self._caller._bytestreamResultCB, 'result',
nbxmpp.NS_BYTESTREAM)
self.RegisterHandler('iq', self._caller._bytestreamErrorCB, 'error',
nbxmpp.NS_BYTESTREAM)
self._caller._register_new_handlers(self) self._caller._register_new_handlers(self)

View File

@ -26,7 +26,6 @@ import nbxmpp
from gajim.common import app from gajim.common import app
from gajim.common.protocol.bytestream import ConnectionSocks5BytestreamZeroconf
from gajim.common import connection_handlers from gajim.common import connection_handlers
from gajim.common.i18n import _ from gajim.common.i18n import _
from gajim.common.helpers import AdditionalDataDict from gajim.common.helpers import AdditionalDataDict
@ -56,10 +55,8 @@ class DecryptedMessageReceivedEvent(NetworkIncomingEvent):
class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf, class ConnectionHandlersZeroconf(connection_handlers.ConnectionHandlersBase):
connection_handlers.ConnectionHandlersBase):
def __init__(self): def __init__(self):
ConnectionSocks5BytestreamZeroconf.__init__(self)
connection_handlers.ConnectionHandlersBase.__init__(self) connection_handlers.ConnectionHandlersBase.__init__(self)
def _messageCB(self, con, stanza, properties): def _messageCB(self, con, stanza, properties):

View File

@ -233,7 +233,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
if event.ptype == 'unavailable': if event.ptype == 'unavailable':
# TODO: This causes problems when another # TODO: This causes problems when another
# resource signs off! # resource signs off!
self.stop_all_active_file_transfers(contact) self.get_module('Bytestream').stop_all_active_file_transfers(contact)
def _on_name_conflictCB(self, alt_name): def _on_name_conflictCB(self, alt_name):
self.disconnect() self.disconnect()

View File

@ -36,7 +36,7 @@ from gajim.common import app
from gajim.common import helpers from gajim.common import helpers
from gajim.common.i18n import _ from gajim.common.i18n import _
from gajim.common.file_props import FilesProp from gajim.common.file_props import FilesProp
from gajim.common.protocol.bytestream import (is_transfer_active, is_transfer_paused, from gajim.common.modules.bytestream import (is_transfer_active, is_transfer_paused,
is_transfer_stopped) is_transfer_stopped)
from gajim.gtk.dialogs import HigDialog from gajim.gtk.dialogs import HigDialog
@ -363,7 +363,7 @@ class FileTransfersWindow:
file_props.file_name = file_path file_props.file_name = file_path
file_props.type_ = 'r' file_props.type_ = 'r'
self.add_transfer(account, contact, file_props) self.add_transfer(account, contact, file_props)
app.connections[account].send_file_approval(file_props) app.connections[account].get_module('Bytestream').send_file_approval(file_props)
def on_file_request_accepted(self, account, contact, file_props): def on_file_request_accepted(self, account, contact, file_props):
def on_ok(account, contact, file_props, file_path): def on_ok(account, contact, file_props, file_path):
@ -410,7 +410,7 @@ class FileTransfersWindow:
con = app.connections[account] con = app.connections[account]
accept_cb = partial(on_ok, account, contact, file_props) accept_cb = partial(on_ok, account, contact, file_props)
cancel_cb = partial(con.send_file_rejection, file_props) cancel_cb = partial(con.get_module('Bytestream').send_file_rejection, file_props)
FileSaveDialog(accept_cb, FileSaveDialog(accept_cb,
cancel_cb, cancel_cb,
path=app.config.get('last_save_dir'), path=app.config.get('last_save_dir'),
@ -439,7 +439,7 @@ class FileTransfersWindow:
self.on_file_request_accepted(account, contact, file_props) self.on_file_request_accepted(account, contact, file_props)
def on_response_cancel(account, file_props): def on_response_cancel(account, file_props):
app.connections[account].send_file_rejection(file_props) app.connections[account].get_module('Bytestream').send_file_rejection(file_props)
dialog = NonModalConfirmationDialog(prim_text, sec_text, dialog = NonModalConfirmationDialog(prim_text, sec_text,
on_response_ok=(on_response_ok, account, contact, file_props), on_response_ok=(on_response_ok, account, contact, file_props),
@ -552,7 +552,7 @@ class FileTransfersWindow:
account = file_props.tt_account account = file_props.tt_account
if account in app.connections: if account in app.connections:
# there is a connection to the account # there is a connection to the account
app.connections[account].remove_transfer(file_props) app.connections[account].get_module('Bytestream').remove_transfer(file_props)
if file_props.type_ == 'r': # we receive a file if file_props.type_ == 'r': # we receive a file
other = file_props.sender other = file_props.sender
else: # we send a file else: # we send a file
@ -882,7 +882,7 @@ class FileTransfersWindow:
# Check if we are in a IBB transfer # Check if we are in a IBB transfer
if file_props.direction: if file_props.direction:
con.get_module('IBB').send_close(file_props) con.get_module('IBB').send_close(file_props)
con.disconnect_transfer(file_props) con.get_module('Bytestream').disconnect_transfer(file_props)
self.set_status(file_props, 'stop') self.set_status(file_props, 'stop')
def on_notify_ft_complete_checkbox_toggled(self, widget): def on_notify_ft_complete_checkbox_toggled(self, widget):

View File

@ -2435,7 +2435,7 @@ class RosterWindow:
on_continue3(message, pep_dict) on_continue3(message, pep_dict)
return return
# check if there is an active file transfer # check if there is an active file transfer
from gajim.common.protocol.bytestream import is_transfer_active from gajim.common.modules.bytestream import is_transfer_active
files_props = app.interface.instances['file_transfers'].\ files_props = app.interface.instances['file_transfers'].\
files_props files_props
transfer_active = False transfer_active = False