Supply a modified factory with increased pipelining and timeouts.
authorCameron Dale <camrdale@gmail.com>
Wed, 16 Jan 2008 03:26:29 +0000 (19:26 -0800)
committerCameron Dale <camrdale@gmail.com>
Wed, 16 Jan 2008 03:26:29 +0000 (19:26 -0800)
apt-dht.py
apt_dht/HTTPServer.py
apt_dht/apt_dht.py

index e5288b0..c8d0079 100644 (file)
@@ -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'))
index 616fc2d..38c7c09 100644 (file)
@@ -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)
index 749396b..aeda56b 100644 (file)
@@ -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'),