]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt-p2p.py
Increase the stored value redundancy to 6.
[quix0rs-apt-p2p.git] / apt-p2p.py
index 687320473f8065e81b6c575a4d7e9244ae39c1d9..911dfce162bfd55d0cbc19097a77ee00a285a77a 100644 (file)
@@ -1,23 +1,23 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 
 
-# Load apt-p2p application
-#
-# There are two ways apt-p2p can be started:
-#  1. twistd -y apt-p2p
-#     - twistd will load this file and execute the app
-#       in 'application' variable
-#  2. from command line
-#     - __name__ will be '__main__'
+"""Load the apt-p2p application.
+
+There are two ways apt-p2p can be started:
+  1. twistd -y apt-p2p
+     - twistd will load this file and execute the app
+       in 'application' variable
+  2. from command line
+     - __name__ will be '__main__'
+"""
 
 import pwd,sys
 
 from twisted.application import service, internet, app, strports
 from twisted.internet import reactor
 from twisted.python import usage, log
 
 import pwd,sys
 
 from twisted.application import service, internet, app, strports
 from twisted.internet import reactor
 from twisted.python import usage, log
-from twisted.web2 import channel
 
 from apt_p2p.apt_p2p_conf import config, version, DEFAULT_CONFIG_FILES
 
 from apt_p2p.apt_p2p_conf import config, version, DEFAULT_CONFIG_FILES
-from apt_p2p.interfaces import IDHT
+from apt_p2p.interfaces import IDHT, IDHTStatsFactory
 
 config_file = ''
 
 
 config_file = ''
 
@@ -54,31 +54,37 @@ if __name__ == '__main__':
 log.msg("Loading config files: '%s'" % "', '".join(DEFAULT_CONFIG_FILES + [config_file]))
 config_read = config.read(DEFAULT_CONFIG_FILES + [config_file])
 log.msg("Successfully loaded config files: '%s'" % "', '".join(config_read))
 log.msg("Loading config files: '%s'" % "', '".join(DEFAULT_CONFIG_FILES + [config_file]))
 config_read = config.read(DEFAULT_CONFIG_FILES + [config_file])
 log.msg("Successfully loaded config files: '%s'" % "', '".join(config_read))
-if config.has_option('DEFAULT', 'username') and config.get('DEFAULT', 'username'):
-    uid,gid = pwd.getpwnam(config.get('DEFAULT', 'username'))[2:4]
-else:
+try:
+    uid,gid = pwd.getpwnam(config.get('DEFAULT', 'USERNAME'))[2:4]
+except:
     uid,gid = None,None
 
     uid,gid = None,None
 
-log.msg('Starting application')
+log.msg('Starting application with uid/gid %r/%r' % (uid, gid))
 application = service.Application("apt-p2p", uid, gid)
 #print service.IProcess(application).processName
 #service.IProcess(application).processName = 'apt-p2p'
 
 application = service.Application("apt-p2p", uid, gid)
 #print service.IProcess(application).processName
 #service.IProcess(application).processName = 'apt-p2p'
 
-log.msg('Starting DHT')
 DHT = __import__(config.get('DEFAULT', 'DHT')+'.DHT', globals(), locals(), ['DHT'])
 assert IDHT.implementedBy(DHT.DHT), "You must provide a DHT implementation that implements the IDHT interface."
 DHT = __import__(config.get('DEFAULT', 'DHT')+'.DHT', globals(), locals(), ['DHT'])
 assert IDHT.implementedBy(DHT.DHT), "You must provide a DHT implementation that implements the IDHT interface."
-myDHT = DHT.DHT()
 
 if not config.getboolean('DEFAULT', 'DHT-only'):
     log.msg('Starting main application server')
     from apt_p2p.apt_p2p import AptP2P
 
 if not config.getboolean('DEFAULT', 'DHT-only'):
     log.msg('Starting main application server')
     from apt_p2p.apt_p2p import AptP2P
-    myapp = AptP2P(myDHT)
-    factory = myapp.getHTTPFactory()
+    factory = AptP2P(DHT.DHT)
     s = strports.service('tcp:'+config.get('DEFAULT', 'port'), factory)
     s.setServiceParent(application)
 else:
     s = strports.service('tcp:'+config.get('DEFAULT', 'port'), factory)
     s.setServiceParent(application)
 else:
-    myDHT.loadConfig(config, config.get('DEFAULT', 'DHT'))
-    myDHT.join()
+    log.msg('Starting the DHT')
+    myDHT = DHT.DHT()
+    
+    if IDHTStatsFactory.implementedBy(DHT.DHT):
+        log.msg("Starting the DHT's HTTP stats displayer")
+        factory = myDHT.getStatsFactory()
+        s = strports.service('tcp:'+config.get('DEFAULT', 'port'), factory)
+        s.setServiceParent(application)
+        
+    reactor.callLater(0, myDHT.loadConfig, config, config.get('DEFAULT', 'DHT'))
+    reactor.callLater(0, myDHT.join)
 
 if __name__ == '__main__':
     # Run on command line
 
 if __name__ == '__main__':
     # Run on command line