From 0072fe6c6f59984cbb6cc27aec18bc1aad624cbe Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 11 Jun 2007 21:37:39 +0000 Subject: [PATCH] fix issue with changing enable_dht causing segfault enabling and disabling DHT no longer requires a restart --- src/core.py | 28 +++++++++++++++++----------- src/interface.py | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/core.py b/src/core.py index 3984c47c8..46f828980 100644 --- a/src/core.py +++ b/src/core.py @@ -194,20 +194,18 @@ class Manager: # Saved torrent core_states. We do not poll the core in a costly manner, necessarily self.saved_core_torrent_file_infos = {} # unique_ID -> torrent_state + # Keeps track of DHT running state + self.dht_running = False # Load the preferences self.config = pref.Preferences(os.path.join(self.base_dir, PREFS_FILENAME)) + # Set the enable_dht PREF_FUNCTION + PREF_FUNCTIONS["enable_dht"] = self.set_DHT + # Apply preferences. Note that this is before any torrents are added self.apply_prefs() - # Apply DHT, if needed. Note that this is before any torrents are added - if self.get_pref('enable_dht'): - if not blank_slate: - deluge_core.start_DHT(os.path.join(self.base_dir, DHT_FILENAME)) - else: - deluge_core.start_DHT("") - # Unpickle the state, or create a new one if not blank_slate: try: @@ -247,9 +245,7 @@ class Manager: self.save_fastresume_data() # Stop DHT, if needed - if self.get_pref('enable_dht'): - print "Stopping DHT..." - deluge_core.stop_DHT(os.path.join(self.base_dir, DHT_FILENAME)) + self.set_DHT(False) # Shutdown torrent core print "Quitting the core..." @@ -349,7 +345,7 @@ class Manager: # Get additional data from our level ret['is_listening'] = deluge_core.is_listening() ret['port'] = deluge_core.listening_port() - if self.get_pref('enable_dht'): + if self.dht_running == True: ret['DHT_nodes'] = deluge_core.get_DHT_info() return ret @@ -716,6 +712,16 @@ class Manager: if PREF_FUNCTIONS[pref] is not None: PREF_FUNCTIONS[pref](self.get_pref(pref)) + def set_DHT(self, start=False): + if start == True: + print "Starting DHT..." + deluge_core.start_DHT(os.path.join(self.base_dir, DHT_FILENAME)) + self.dht_running = True + elif start == False and self.dht_running == True: + print "Stopping DHT..." + deluge_core.stop_DHT(os.path.join(self.base_dir, DHT_FILENAME)) + self.dht_running = False + # Calculations def calc_ratio(self, unique_ID, torrent_state): diff --git a/src/interface.py b/src/interface.py index d0ac14b9b..543357ecc 100644 --- a/src/interface.py +++ b/src/interface.py @@ -525,7 +525,7 @@ class DelugeGTK: else: self.preferences_dialog.show() self.apply_prefs() - self.config.save_to_file() + self.config.save() def show_plugin_dialog(self, arg=None): self.plugin_dialog.show()