From: Cameron Dale Date: Mon, 31 Mar 2008 22:47:15 +0000 (-0700) Subject: Make the upload limit a config option. X-Git-Url: https://git.mxchange.org/?p=quix0rs-apt-p2p.git;a=commitdiff_plain;h=6d23f1559df1435172f1da25ae0f57ae11a24bde Make the upload limit a config option. --- diff --git a/apt-p2p.conf b/apt-p2p.conf index 9a12eed..249de43 100644 --- a/apt-p2p.conf +++ b/apt-p2p.conf @@ -17,7 +17,11 @@ # for uploads to other peers. If a port is not specified for the DHT, it will also # use this UDP port to listen for DHT requests. PORT = 9977 - + +# The rate to limit sending data to peers to, in KBytes/sec. +# Set this to 0 to not limit the upload bandwidth. +UPLOAD_LIMIT = 0 + # Directory to store the downloaded files in CACHE_DIR = /var/cache/apt-p2p @@ -26,7 +30,7 @@ CACHE_DIR = /var/cache/apt-p2p # for everybody to download # OTHER_DIRS = -# Whether it's OK to use an IP addres from a known local/private range +# Whether it's OK to use an IP address from a known local/private range LOCAL_OK = no # Unload the packages cache after an interval of inactivity this long. @@ -39,7 +43,7 @@ UNLOAD_PACKAGES_CACHE = 5m KEY_REFRESH = 57m # Which DHT implementation to use. -# It must be possile to do "from .DHT import DHT" to get a class that +# It must be possible to do "from .DHT import DHT" to get a class that # implements the IDHT interface. There should also be a similarly named # section below to specify the options for the DHT. DHT = apt_p2p_Khashmir diff --git a/apt_p2p/HTTPServer.py b/apt_p2p/HTTPServer.py index b12ca71..3a9a3a3 100644 --- a/apt_p2p/HTTPServer.py +++ b/apt_p2p/HTTPServer.py @@ -167,7 +167,7 @@ class TopLevel(resource.Resource): addSlash = True - def __init__(self, directory, db, manager): + def __init__(self, directory, db, manager, uploadLimit): """Initialize the instance. @type directory: L{twisted.python.filepath.FilePath} @@ -180,6 +180,9 @@ class TopLevel(resource.Resource): self.directory = directory self.db = db self.manager = manager + self.uploadLimit = None + if uploadLimit > 0: + self.uploadLimit = int(uploadLimit*1024) self.factory = None def getHTTPFactory(self): @@ -188,7 +191,7 @@ class TopLevel(resource.Resource): self.factory = channel.HTTPFactory(server.Site(self), **{'maxPipeline': 10, 'betweenRequestsTimeOut': 60}) - self.factory = ThrottlingFactory(self.factory, writeLimit = 30*1024) + self.factory = ThrottlingFactory(self.factory, writeLimit = self.uploadLimit) self.factory.protocol = UploadThrottlingProtocol return self.factory diff --git a/apt_p2p/apt_p2p.py b/apt_p2p/apt_p2p.py index 4a97d4c..887f136 100644 --- a/apt_p2p/apt_p2p.py +++ b/apt_p2p/apt_p2p.py @@ -70,14 +70,15 @@ class AptP2P: """ log.msg('Initializing the main apt_p2p application') self.dhtClass = dhtClass - self.cache_dir = FilePath(config.get('DEFAULT', 'cache_dir')) + self.cache_dir = FilePath(config.get('DEFAULT', 'CACHE_DIR')) if not self.cache_dir.child(download_dir).exists(): self.cache_dir.child(download_dir).makedirs() self.db = DB(self.cache_dir.child('apt-p2p.db')) self.dht = dhtClass() self.dht.loadConfig(config, config.get('DEFAULT', 'DHT')) self.dht.join().addCallbacks(self.joinComplete, self.joinError) - self.http_server = TopLevel(self.cache_dir.child(download_dir), self.db, self) + self.http_server = TopLevel(self.cache_dir.child(download_dir), self.db, self, + config.getint('DEFAULT', 'UPLOAD_LIMIT')) self.getHTTPFactory = self.http_server.getHTTPFactory self.peers = PeerManager() self.mirrors = MirrorManager(self.cache_dir, config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE')) diff --git a/apt_p2p/apt_p2p_conf.py b/apt_p2p/apt_p2p_conf.py index c4ecb93..e5c0f37 100644 --- a/apt_p2p/apt_p2p_conf.py +++ b/apt_p2p/apt_p2p_conf.py @@ -39,6 +39,10 @@ DEFAULTS = { # Port to listen on for all requests (TCP and UDP) 'PORT': '9977', + # The rate to limit sending data to peers to, in KBytes/sec. + # Set this to 0 to not limit the upload bandwidth. + 'UPLOAD_LIMIT': '0', + # Directory to store the downloaded files in 'CACHE_DIR': home + '/.apt-p2p/cache', @@ -50,7 +54,7 @@ DEFAULTS = { # User name to try and run as 'USERNAME': '', - # Whether it's OK to use an IP addres from a known local/private range + # Whether it's OK to use an IP address from a known local/private range 'LOCAL_OK': 'no', # Unload the packages cache after an interval of inactivity this long. @@ -63,7 +67,7 @@ DEFAULTS = { 'KEY_REFRESH': '57m', # Which DHT implementation to use. - # It must be possile to do "from .DHT import DHT" to get a class that + # It must be possible to do "from .DHT import DHT" to get a class that # implements the IDHT interface. 'DHT': 'apt_p2p_Khashmir', diff --git a/debian/apt-p2p.conf.sgml b/debian/apt-p2p.conf.sgml index 301ccb1..ce99137 100644 --- a/debian/apt-p2p.conf.sgml +++ b/debian/apt-p2p.conf.sgml @@ -93,6 +93,14 @@ (Default is 9977.) + + + + The speed to limit sending data to peers to, in KBytes/sec. + Set this to 0 to not limit the upload bandwidth. + (Default is 0) + + diff --git a/test.py b/test.py index 10ca2d6..3fb7057 100755 --- a/test.py +++ b/test.py @@ -318,6 +318,10 @@ apt_p2p_conf_template = """ # Port to listen on for all requests (TCP and UDP) PORT = %(PORT)s +# The rate to limit sending data to peers to, in KBytes/sec. +# Set this to 0 to not limit the upload bandwidth. +UPLOAD_LIMIT = 100 + # Directory to store the downloaded files in CACHE_DIR = %(CACHE_DIR)s