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 = []
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
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()
# 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 = {