Adds downloaded hashed files to the DHT.
authorCameron Dale <camrdale@gmail.com>
Fri, 11 Jan 2008 03:53:47 +0000 (19:53 -0800)
committerCameron Dale <camrdale@gmail.com>
Fri, 11 Jan 2008 03:53:47 +0000 (19:53 -0800)
apt_dht/apt_dht.py

index 9fc72ffedafe871cef7faed2967395adb2ce6de2..b4aaff0d0905a100fb68f514a58450894cdcde63 100644 (file)
@@ -1,5 +1,6 @@
 
 from binascii import b2a_hex
+from urlparse import urlunparse
 import os, re
 
 from twisted.internet import defer
@@ -191,3 +192,15 @@ class AptDHT:
         new_top = self.http_server.addDirectory(http_dir)
         url_path = '/' + new_top + url_path
         log.msg('now avaliable at %s: %s' % (url_path, url))
+
+        if self.my_addr:
+            site = self.my_addr + ':' + str(config.getint('DEFAULT', 'PORT'))
+            full_path = urlunparse(('http', site, url_path, None, None, None))
+            key = hash.norm(bits = config.getint(config.get('DEFAULT', 'DHT'), 'HASH_LENGTH'))
+            storeDefer = self.dht.storeValue(key, full_path)
+            storeDefer.addCallback(self.store_done, full_path)
+            storeDefer.addErrback(log.err)
+
+    def store_done(self, result, path):
+        log.msg('Added %s to the DHT: %r' % (path, result))
+        
\ No newline at end of file