From d1a2027b26e3791e7e05f1247f00c279ce46ce99 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Tue, 15 Jan 2008 19:26:29 -0800 Subject: [PATCH] Supply a modified factory with increased pipelining and timeouts. --- apt-dht.py | 4 ++-- apt_dht/HTTPServer.py | 17 ++++++++++++----- apt_dht/apt_dht.py | 5 +---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apt-dht.py b/apt-dht.py index e5288b0..c8d0079 100644 --- a/apt-dht.py +++ b/apt-dht.py @@ -71,8 +71,8 @@ if not config.getboolean('DEFAULT', 'DHT-only'): 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')) diff --git a/apt_dht/HTTPServer.py b/apt_dht/HTTPServer.py index 616fc2d..38c7c09 100644 --- a/apt_dht/HTTPServer.py +++ b/apt_dht/HTTPServer.py @@ -44,6 +44,14 @@ class TopLevel(resource.Resource): 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 = {} @@ -75,16 +83,15 @@ class TopLevel(resource.Resource): 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) diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py index 749396b..aeda56b 100644 --- a/apt_dht/apt_dht.py +++ b/apt_dht/apt_dht.py @@ -31,16 +31,13 @@ class AptDHT: 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'), -- 2.39.5