X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_dht%2Fapt_dht.py;h=f1732e5ee1cc55be2daf0a8aa1f5f3410e3ad7a8;hb=b68a1ebc0bbe79c8f9d3981ed83ef0ffcf201752;hp=9d0241d6b0f023861d0fc375aa362f4e250992d8;hpb=1461780708c6ce0562ec0a27062b13b32d7dc348;p=quix0rs-apt-p2p.git diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py index 9d0241d..f1732e5 100644 --- a/apt_dht/apt_dht.py +++ b/apt_dht/apt_dht.py @@ -152,15 +152,17 @@ class AptDHT: 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. + 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 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) @@ -169,5 +171,5 @@ class AptDHT: return None def store_done(self, result, hash): - log.msg('Added %s to the DHT: %r' % (hash, result)) + log.msg('Added %s to the DHT: %r' % (hash.hexdigest(), result)) \ No newline at end of file