fix issue with changing enable_dht causing segfault

enabling and disabling DHT no longer requires a restart
This commit is contained in:
Andrew Resch 2007-06-11 21:37:39 +00:00
parent 7c5af812c5
commit 0072fe6c6f
2 changed files with 18 additions and 12 deletions

View File

@ -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):

View File

@ -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()