]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
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 e5288b0a77b7be3731b101dbe572e5f14e1beb63..c8d007982cad455ca9e5dba42bcb601fee170072 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 616fc2df5b3b7ad21b8c9761919dc47525db470f..38c7c0912d7da63815e40638ca1cc0ca61e468a9 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 749396b3a36f9b3922c79af4c30bc487f5572594..aeda56bf2147930d2a9c03c57f38bd3296f64863 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'),