]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Added a shutdown method to the khasmir DHT.
authorCameron Dale <camrdale@gmail.com>
Wed, 2 Jan 2008 19:48:37 +0000 (11:48 -0800)
committerCameron Dale <camrdale@gmail.com>
Wed, 2 Jan 2008 19:48:37 +0000 (11:48 -0800)
apt_dht_Khashmir/actions.py
apt_dht_Khashmir/khashmir.py

index a3a6fc84e5d6ac1f836a4fd9deb1984790c58a75..088bc0f2a6476b1a59643c681fbc3304f87d7940 100644 (file)
@@ -271,3 +271,9 @@ class KeyExpirer:
         s = "delete from kv where time < '%s';" % self.cut
         c.execute(s)
         self.next_expire = reactor.callLater(self.config['KE_DELAY'], self.doExpire)
+        
+    def shutdown(self):
+        try:
+            self.next_expire.cancel()
+        except:
+            pass
index dd2bf3076399db57251f87975e4d9a12db0c244d..1baffa17dc25072e47198f903de8e8a9fe26783d 100644 (file)
@@ -242,6 +242,16 @@ class KhashmirBase(protocol.Factory):
         num_contacts = reduce(lambda a, b: a + len(b.l), self.table.buckets, 0)
         num_nodes = self.config['K'] * (2**(len(self.table.buckets) - 1))
         return (num_contacts, num_nodes)
+    
+    def shutdown(self):
+        """Closes the port and cancels pending later calls."""
+        self.listenport.stopListening()
+        try:
+            self.next_checkpoint.cancel()
+        except:
+            pass
+        self.expirer.shutdown()
+        self.store.close()
 
     def krpc_ping(self, id, _krpc_sender):
         sender = {'id' : id}
@@ -376,26 +386,8 @@ class SimpleTests(unittest.TestCase):
         self.b = Khashmir(d)
         
     def tearDown(self):
-        self.a.listenport.stopListening()
-        self.b.listenport.stopListening()
-        try:
-            self.a.next_checkpoint.cancel()
-        except:
-            pass
-        try:
-            self.b.next_checkpoint.cancel()
-        except:
-            pass
-        try:
-            self.a.expirer.next_expire.cancel()
-        except:
-            pass
-        try:
-            self.b.expirer.next_expire.cancel()
-        except:
-            pass
-        self.a.store.close()
-        self.b.store.close()
+        self.a.shutdown()
+        self.b.shutdown()
         os.unlink(self.a.db)
         os.unlink(self.b.db)
 
@@ -492,16 +484,7 @@ class MultiTest(unittest.TestCase):
 
     def tearDown(self):
         for i in self.l:
-            i.listenport.stopListening()
-            try:
-                i.next_checkpoint.cancel()
-            except:
-                pass
-            try:
-                i.expirer.next_expire.cancel()
-            except:
-                pass
-            i.store.close()
+            i.shutdown()
             os.unlink(i.db)
             
         reactor.iterate()