From 876f176dda63e8b6bdd1c4c26d14e4bc3885eec4 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 10 Jan 2008 19:53:47 -0800 Subject: [PATCH] Adds downloaded hashed files to the DHT. --- apt_dht/apt_dht.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py index 9fc72ff..b4aaff0 100644 --- a/apt_dht/apt_dht.py +++ b/apt_dht/apt_dht.py @@ -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 -- 2.39.5