From: Cameron Dale Date: Mon, 17 Dec 2007 02:39:43 +0000 (-0800) Subject: Added the DHT starting to the application. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=925b712a25f84ef20887cd575c86fb9ab2cfa3e5;p=quix0rs-apt-p2p.git Added the DHT starting to the application. --- 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 = {