From e5c2ca305ef54fb6a546c83ca69f52df0d57b0d8 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Wed, 2 Jan 2008 13:52:59 -0800 Subject: [PATCH] Updated the DHT join and leave to check if a join is in progress. --- apt_dht_Khashmir/DHT.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apt_dht_Khashmir/DHT.py b/apt_dht_Khashmir/DHT.py index 1c4416b..80a322b 100644 --- a/apt_dht_Khashmir/DHT.py +++ b/apt_dht_Khashmir/DHT.py @@ -47,6 +47,8 @@ class DHT: """See L{apt_dht.interfaces.IDHT}.""" if self.config is None: raise DHTError, "configuration not loaded" + if self.joining: + raise DHTError, "a join is already in progress" self.khashmir = Khashmir(self.config, self.cache_dir) @@ -67,16 +69,23 @@ class DHT: if not self.joined: self.joined = True if len(result) > 0 or self.bootstrap_node: - self.joining.callback(result) + df = self.joining + self.joining = None + df.callback(result) else: - self.joining.errback(DHTError('could not find any nodes to bootstrap to')) + df = self.joining + self.joining = None + df.errback(DHTError('could not find any nodes to bootstrap to')) def leave(self): """See L{apt_dht.interfaces.IDHT}.""" if self.config is None: raise DHTError, "configuration not loaded" - if self.joined: + if self.joined or self.joining: + if self.joining: + self.joining.errback(DHTError('still joining when leave was called')) + self.joining = None self.joined = False self.khashmir.shutdown() -- 2.39.2