Added the DHT starting to the application.
authorCameron Dale <camrdale@gmail.com>
Mon, 17 Dec 2007 02:39:43 +0000 (18:39 -0800)
committerCameron Dale <camrdale@gmail.com>
Mon, 17 Dec 2007 02:39:43 +0000 (18:39 -0800)
apt-dht.py
apt_dht/apt_dht.py
apt_dht/apt_dht_conf.py

index 73c3ddef66f9bb96381782abcf1416fcd581a094..9684f572eca4b6d1c5fd81dd23b10c5fa074b3a7 100644 (file)
@@ -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
index 642c3f7ee5e0986491860c25f25aa18b917d9221..5897de5ccba50e024e84b3f033dbb9cc5fa29734 100644 (file)
@@ -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()
index 626f0ffc32e394a580b1e122e5d38299319f9539..038819e0b4b422797aa803b4aa03fcb5f9aca52f 100644 (file)
@@ -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 <DHT> 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 = {