From 707023f2c220f46d373b0db083c32b4b528ce3a6 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Thu, 25 Oct 2018 12:34:55 +0200 Subject: [PATCH] Fixed issue with proxy settings --- Tribler/Core/Config/config.spec | 4 +-- Tribler/Core/Config/tribler_config.py | 13 +++++++--- .../Test/Core/Config/test_tribler_config.py | 14 +++++------ TriblerGUI/widgets/settingspage.py | 25 +++++++++++-------- run_tribler.py | 22 ++++++++++------ 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Tribler/Core/Config/config.spec b/Tribler/Core/Config/config.spec index a51ee41e8a4..a7beca27833 100644 --- a/Tribler/Core/Config/config.spec +++ b/Tribler/Core/Config/config.spec @@ -65,8 +65,8 @@ directory = string(default='') enabled = boolean(default=True) port = integer(min=-1, max=65536, default=-1) proxy_type = integer(min=0, max=5, default=0) -proxy_server = string_list(default=list('', '')) -proxy_auth = string_list(default=list('', '')) +proxy_server = string(default=':') +proxy_auth = string(default=':') max_connections_download = integer(default=-1) max_download_rate = integer(default=0) max_upload_rate = integer(default=0) diff --git a/Tribler/Core/Config/tribler_config.py b/Tribler/Core/Config/tribler_config.py index eb9b9bc90a7..b694cff8c40 100644 --- a/Tribler/Core/Config/tribler_config.py +++ b/Tribler/Core/Config/tribler_config.py @@ -316,13 +316,18 @@ def set_libtorrent_proxy_settings(self, proxy_type, server=None, auth=None): :param auth: (username, password) tuple or None """ self.config['libtorrent']['proxy_type'] = proxy_type - self.config['libtorrent']['proxy_server'] = server if proxy_type else None - self.config['libtorrent']['proxy_auth'] = auth if proxy_type in [3, 5] else None + self.config['libtorrent']['proxy_server'] = server if proxy_type else ':' + self.config['libtorrent']['proxy_auth'] = auth if proxy_type in [3, 5] else ':' def get_libtorrent_proxy_settings(self): + proxy_server = str(self.config['libtorrent']['proxy_server']) + proxy_server = proxy_server.split(':') if proxy_server else ['', ''] + + proxy_auth = str(self.config['libtorrent']['proxy_auth']) + proxy_auth = proxy_auth.split(':') if proxy_auth else ['', ''] + return (self.config['libtorrent']['proxy_type'], - self.config['libtorrent']['proxy_server'], - self.config['libtorrent']['proxy_auth']) + proxy_server, proxy_auth) def set_anon_proxy_settings(self, proxy_type, server=None, auth=None): """ diff --git a/Tribler/Test/Core/Config/test_tribler_config.py b/Tribler/Test/Core/Config/test_tribler_config.py index 59b07a7ffce..e40b5809b0e 100644 --- a/Tribler/Test/Core/Config/test_tribler_config.py +++ b/Tribler/Test/Core/Config/test_tribler_config.py @@ -58,19 +58,18 @@ def test_libtorrent_proxy_settings(self): """ Setting and getting of libtorrent proxy settings. """ - proxy_type, server, auth = 3, ("33.33.33.33", 22), 1 - self.tribler_config.set_libtorrent_proxy_settings(proxy_type, server, auth) - + proxy_type, server, auth = 3, ['33.33.33.33', '22'], ['user', 'pass'] + self.tribler_config.set_libtorrent_proxy_settings(proxy_type, ':'.join(server), ':'.join(auth)) self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings()[0], proxy_type) self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings()[1], server) self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings()[2], auth) # if the proxy type doesn't support authentication, auth setting should be saved as None proxy_type = 1 - self.tribler_config.set_libtorrent_proxy_settings(proxy_type, server, auth) + self.tribler_config.set_libtorrent_proxy_settings(proxy_type, ':'.join(server), ':'.join(auth)) self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings()[0], proxy_type) self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings()[1], server) - self.assertIsNone(self.tribler_config.get_libtorrent_proxy_settings()[2]) + self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings()[2], ['', '']) def test_anon_proxy_settings(self): proxy_type, server, auth = 3, ("33.33.33.33", [2222, 2223, 4443, 58848]), 1 @@ -195,8 +194,9 @@ def test_get_set_methods_libtorrent(self): self.assertEqual(self.tribler_config.get_libtorrent_port(), True) self.tribler_config.set_anon_listen_port(True) self.assertEqual(self.tribler_config.get_anon_listen_port(), True) - self.tribler_config.set_libtorrent_proxy_settings(3, True, False) - self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings(), (3, True, False)) + proxy_server, proxy_auth = ["localhost", "9090"], ["user", "pass"] + self.tribler_config.set_libtorrent_proxy_settings(3, ":".join(proxy_server), ":".join(proxy_auth)) + self.assertEqual(self.tribler_config.get_libtorrent_proxy_settings(), (3, proxy_server, proxy_auth)) self.tribler_config.set_anon_proxy_settings(0, None, None) self.assertEqual(self.tribler_config.get_anon_proxy_settings(), (0, (None, None), None)) self.tribler_config.set_anon_proxy_settings(3, ("TEST", [5]), ("TUN", "TPW")) diff --git a/TriblerGUI/widgets/settingspage.py b/TriblerGUI/widgets/settingspage.py index 1d9fe2f235f..4cc2c6c09c6 100644 --- a/TriblerGUI/widgets/settingspage.py +++ b/TriblerGUI/widgets/settingspage.py @@ -232,11 +232,13 @@ def initialize_with_settings(self, settings): # Connection settings self.window().lt_proxy_type_combobox.setCurrentIndex(settings['libtorrent']['proxy_type']) if settings['libtorrent']['proxy_server']: - self.window().lt_proxy_server_input.setText(settings['libtorrent']['proxy_server'][0]) - self.window().lt_proxy_port_input.setText("%s" % settings['libtorrent']['proxy_server'][1]) + proxy_server = settings['libtorrent']['proxy_server'].split(":") + self.window().lt_proxy_server_input.setText(proxy_server[0]) + self.window().lt_proxy_port_input.setText(proxy_server[1]) if settings['libtorrent']['proxy_auth']: - self.window().lt_proxy_username_input.setText(settings['libtorrent']['proxy_auth'][0]) - self.window().lt_proxy_password_input.setText(settings['libtorrent']['proxy_auth'][1]) + proxy_auth = settings['libtorrent']['proxy_auth'].split(":") + self.window().lt_proxy_username_input.setText(proxy_auth[0]) + self.window().lt_proxy_password_input.setText(proxy_auth[1]) self.window().lt_utp_checkbox.setChecked(settings['libtorrent']['utp']) max_conn_download = settings['libtorrent']['max_connections_download'] @@ -337,21 +339,24 @@ def save_settings(self): if self.window().lt_proxy_server_input.text() and len(self.window().lt_proxy_server_input.text()) > 0 and len( self.window().lt_proxy_port_input.text()) > 0: - settings_data['libtorrent']['proxy_server'] = [self.window().lt_proxy_server_input.text(), None] - settings_data['libtorrent']['proxy_server'][0] = self.window().lt_proxy_server_input.text() try: - settings_data['libtorrent']['proxy_server'][1] = int(self.window().lt_proxy_port_input.text()) + settings_data['libtorrent']['proxy_server'] = "%s:%s" % (self.window().lt_proxy_server_input.text(), + int(self.window().lt_proxy_port_input.text())) except ValueError: ConfirmationDialog.show_error(self.window(), "Invalid proxy port number", "You've entered an invalid format for the proxy port number. " "Please enter a whole number.") return + else: + settings_data['libtorrent']['proxy_server'] = ":" if len(self.window().lt_proxy_username_input.text()) > 0 and \ len(self.window().lt_proxy_password_input.text()) > 0: - settings_data['libtorrent']['proxy_auth'] = [None, None] - settings_data['libtorrent']['proxy_auth'][0] = self.window().lt_proxy_username_input.text() - settings_data['libtorrent']['proxy_auth'][1] = self.window().lt_proxy_password_input.text() + settings_data['libtorrent']['proxy_auth'] = "%s:%s" % (self.window().lt_proxy_username_input.text(), + self.window().lt_proxy_password_input.text()) + else: + settings_data['libtorrent']['proxy_auth'] = ":" + settings_data['libtorrent']['utp'] = self.window().lt_utp_checkbox.isChecked() try: diff --git a/run_tribler.py b/run_tribler.py index ea96d6224fb..9aad36ad91d 100644 --- a/run_tribler.py +++ b/run_tribler.py @@ -3,6 +3,8 @@ import logging.config import signal + +from Tribler.Core.exceptions import TriblerException from check_os import check_environment, check_free_space, error_and_exit, setup_gui_logging, \ should_kill_other_tribler_instances, enable_fault_handler, set_process_priority @@ -83,19 +85,19 @@ def start_tribler(): api_port = os.environ['CORE_API_PORT'] start_tribler_core(base_path, api_port) else: - enable_fault_handler() + try: + enable_fault_handler() - # Exit if we cant read/write files, etc. - check_environment() + # Exit if we cant read/write files, etc. + check_environment() - should_kill_other_tribler_instances() + should_kill_other_tribler_instances() - check_free_space() + check_free_space() - # Set up logging - setup_gui_logging() + # Set up logging + setup_gui_logging() - try: from TriblerGUI.tribler_app import TriblerApplication from TriblerGUI.tribler_window import TriblerWindow @@ -118,6 +120,10 @@ def start_tribler(): logging.exception(ie) error_and_exit("Import Error", "Import error: {0}".format(ie)) + except TriblerException as te: + logging.exception(te) + error_and_exit("Tribler Exception", "{0}".format(te)) + except SystemExit as se: logging.info("Shutting down Tribler") # Flush all the logs to make sure it is written to file before it exits