From 925b712a25f84ef20887cd575c86fb9ab2cfa3e5 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Sun, 16 Dec 2007 18:39:43 -0800 Subject: [PATCH] Added the DHT starting to the application. --- apt-dht.py | 16 +++++++++++----- apt_dht/apt_dht.py | 3 ++- apt_dht/apt_dht_conf.py | 9 +++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apt-dht.py b/apt-dht.py index 73c3dde..9684f57 100644 --- a/apt-dht.py +++ b/apt-dht.py @@ -16,8 +16,8 @@ from twisted.internet import reactor from twisted.python import usage, log from twisted.web2 import channel -from apt_dht.apt_dht import AptDHT from apt_dht.apt_dht_conf import config, version +from apt_dht.interfaces import IDHT config_file = [] @@ -54,10 +54,16 @@ application = service.Application("apt-dht", uid, gid) print service.IProcess(application).processName service.IProcess(application).processName = 'apt-dht' -myapp = AptDHT() -site = myapp.getSite() -s = strports.service('tcp:'+config.defaults()['port'], channel.HTTPFactory(site)) -s.setServiceParent(application) +DHT = __import__(config.get('DEFAULT', 'DHT'), globals(), locals(), ['DHT']) +assert(IDHT.implementedBy(DHT.DHT), "You must provide a DHT implementation that implements the IDHT interface.") +myDHT = DHT.DHT() + +if not config.getboolean('DEFAULT', 'DHT-only'): + from apt_dht.apt_dht import AptDHT + myapp = AptDHT(myDHT) + site = myapp.getSite() + s = strports.service('tcp:'+config.defaults()['port'], channel.HTTPFactory(site)) + s.setServiceParent(application) if __name__ == '__main__': # Run on command line diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py index 642c3f7..5897de5 100644 --- a/apt_dht/apt_dht.py +++ b/apt_dht/apt_dht.py @@ -8,7 +8,8 @@ from HTTPServer import TopLevel from MirrorManager import MirrorManager class AptDHT: - def __init__(self): + def __init__(self, dht): + self.dht = dht self.http_server = TopLevel(config.defaults()['cache_dir'], self) self.http_site = server.Site(self.http_server) self.peers = PeerManager() diff --git a/apt_dht/apt_dht_conf.py b/apt_dht/apt_dht_conf.py index 626f0ff..038819e 100644 --- a/apt_dht/apt_dht_conf.py +++ b/apt_dht/apt_dht_conf.py @@ -28,8 +28,13 @@ DEFAULTS = { # User name to try and run as 'username': '', - # Which DHT implementation to use - 'DHT': 'apt_dht_Khashmir', + # Which DHT implementation to use. + # It must be possile to do "from import DHT" to get a class that + # implements the IDHT interface. + 'DHT': 'apt_dht_Khashmir.DHT', + + # Whether to only run the DHT (for providing a login node) + 'DHT-only': 'no', } DHT_DEFAULTS = { -- 2.39.5