From: Cameron Dale Date: Wed, 16 Jan 2008 03:26:29 +0000 (-0800) Subject: Supply a modified factory with increased pipelining and timeouts. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d1a2027b26e3791e7e05f1247f00c279ce46ce99;p=quix0rs-apt-p2p.git Supply a modified factory with increased pipelining and timeouts. --- 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'),