Don't add files to the DHT if a hash could not be found for them.
authorCameron Dale <camrdale@gmail.com>
Tue, 19 Feb 2008 00:03:18 +0000 (16:03 -0800)
committerCameron Dale <camrdale@gmail.com>
Tue, 19 Feb 2008 00:03:18 +0000 (16:03 -0800)
TODO
apt_dht/CacheManager.py
apt_dht/apt_dht.py

diff --git a/TODO b/TODO
index 5f9555b75acc1b733bf3a03383e848e20135552e..9cef5c7a2e2f8ff2a1326fdfdfddac2cce4119e5 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,11 +1,3 @@
-Files for which a hash cannot be found should not be added to the DHT.
-
-If the hash can't found, it stands to reason that other peers will not 
-be able to find the hash either. So adding those files to the DHT will 
-just clutter it with useless information. Examples include Release.gpg, 
-Release, Translation-de.bz2, and Contents.gz.
-
-
 Use python-debian for parsing RFC 822 files.
 
 There are already routines for parsing these files, so there is no need 
 Use python-debian for parsing RFC 822 files.
 
 There are already routines for parsing these files, so there is no need 
index 517a0090f9a0fb10ea2627672488fea456c0b988..c70cee257fda9e0b83be04a085ceb41ecd926b16 100644 (file)
@@ -211,7 +211,7 @@ class CacheManager:
             if self.scanning[0] == self.cache_dir:
                 url = 'http:/' + file.path[len(self.cache_dir.path):]
             self.db.storeFile(file, result.digest())
             if self.scanning[0] == self.cache_dir:
                 url = 'http:/' + file.path[len(self.cache_dir.path):]
             self.db.storeFile(file, result.digest())
-            df = self.manager.new_cached_file(file, result, url)
+            df = self.manager.new_cached_file(file, result, url, True)
             if df is None:
                 reactor.callLater(0, self._scanDirectories, None, walker)
             else:
             if df is None:
                 reactor.callLater(0, self._scanDirectories, None, walker)
             else:
index 9d0241d6b0f023861d0fc375aa362f4e250992d8..fd7b73d81ce5ba8053431578491dbc31a5424222 100644 (file)
@@ -152,15 +152,17 @@ class AptDHT:
             return getDefer
         return response
         
             return getDefer
         return response
         
-    def new_cached_file(self, file_path, hash, url = None):
+    def new_cached_file(self, file_path, hash, url = None, forceDHT = False):
         """Add a newly cached file to the DHT.
         
         If the file was downloaded, set url to the path it was downloaded for.
         """Add a newly cached file to the DHT.
         
         If the file was downloaded, set url to the path it was downloaded for.
+        Don't add a file to the DHT unless a hash was found for it
+        (but do add it anyway if forceDHT is True).
         """
         if url:
             self.mirrors.updatedFile(url, file_path)
         
         """
         if url:
             self.mirrors.updatedFile(url, file_path)
         
-        if self.my_addr and hash:
+        if self.my_addr and hash and (hash.expected() is not None or forceDHT):
             site = self.my_addr + ':' + str(config.getint('DEFAULT', 'PORT'))
             key = hash.norm(bits = config.getint(config.get('DEFAULT', 'DHT'), 'HASH_LENGTH'))
             storeDefer = self.dht.storeValue(key, site)
             site = self.my_addr + ':' + str(config.getint('DEFAULT', 'PORT'))
             key = hash.norm(bits = config.getint(config.get('DEFAULT', 'DHT'), 'HASH_LENGTH'))
             storeDefer = self.dht.storeValue(key, site)