log.msg('Starting main application server')
from apt_dht.apt_dht import AptDHT
myapp = AptDHT(myDHT)
- site = myapp.getSite()
- s = strports.service('tcp:'+config.get('DEFAULT', 'port'), channel.HTTPFactory(site))
+ factory = myapp.getHTTPFactory()
+ s = strports.service('tcp:'+config.get('DEFAULT', 'port'), factory)
s.setServiceParent(application)
else:
myDHT.loadConfig(config, config.get('DEFAULT', 'DHT'))
self.directory = directory
self.manager = manager
self.subdirs = {}
+ self.factory = None
+
+ def getHTTPFactory(self):
+ if self.factory is None:
+ self.factory = channel.HTTPFactory(server.Site(self),
+ **{'maxPipeline': 10,
+ 'betweenRequestsTimeOut': 60})
+ return self.factory
def setDirectories(self, dirs):
self.subdirs = {}
return FileDownloader(self.directory.path, self.manager), segments[0:]
else:
return self, ()
-
+
if __name__ == '__builtin__':
# Running from twistd -y
t = TopLevel('/home', None)
- t.addDirectory('/tmp')
- t.addDirectory('/var/log')
- site = server.Site(t)
+ t.setDirectories({'~1': '/tmp', '~2': '/var/log'})
+ factory = t.getHTTPFactory()
# Standard twisted application Boilerplate
from twisted.application import service, strports
application = service.Application("demoserver")
- s = strports.service('tcp:18080', channel.HTTPFactory(site))
+ s = strports.service('tcp:18080', factory)
s.setServiceParent(application)
self.dht.join().addCallbacks(self.joinComplete, self.joinError)
self.http_server = TopLevel(self.cache_dir.child(download_dir), self)
self.setDirectories = self.http_server.setDirectories
- self.http_site = server.Site(self.http_server)
+ self.getHTTPFactory = self.http_server.getHTTPFactory
self.peers = PeerManager()
self.mirrors = MirrorManager(self.cache_dir)
other_dirs = [FilePath(f) for f in config.getstringlist('DEFAULT', 'OTHER_DIRS')]
self.cache = CacheManager(self.cache_dir.child(download_dir), self.db, other_dirs, self)
self.my_addr = None
- def getSite(self):
- return self.http_site
-
def joinComplete(self, result):
self.my_addr = findMyIPAddr(result,
config.getint(config.get('DEFAULT', 'DHT'), 'PORT'),