From: Cameron Dale Date: Wed, 2 Jan 2008 21:52:59 +0000 (-0800) Subject: Updated the DHT join and leave to check if a join is in progress. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e5c2ca305ef54fb6a546c83ca69f52df0d57b0d8;p=quix0rs-apt-p2p.git Updated the DHT join and leave to check if a join is in progress. --- 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()