From 0f111fc6881fa69f1bf5f04c6c07330af38875a6 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Tue, 21 Sep 2010 10:39:14 +0200 Subject: [PATCH] next-share: add peer connection limit Add -n (--max-connections) option to cmdlinedl.py to limit number of connecting peers. I've tested it as a downloader client and it works. --- instrumentation/next-share/BaseLib/Tools/cmdlinedl.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/instrumentation/next-share/BaseLib/Tools/cmdlinedl.py b/instrumentation/next-share/BaseLib/Tools/cmdlinedl.py index 0f7594c..a000f51 100644 --- a/instrumentation/next-share/BaseLib/Tools/cmdlinedl.py +++ b/instrumentation/next-share/BaseLib/Tools/cmdlinedl.py @@ -42,6 +42,9 @@ def usage(): print "\t--upload-limit " print "\t-u \tupload speed limitation in KB/s" print "\t\t\t\t(default is no upload limit)" + print "\t--max-connections " + print "\t-n \tmaximum number of peer connections" + print "\t\t\t\t(default is no peer connection limit)" print "\t--no-hash-check" print "\t-c\t\t\tdisable downloaded file hash checking" print "\t--peer-logging" @@ -98,7 +101,7 @@ def main(): try: # opts = a list of (option, value) pairs # args = the list of program arguments left after the option list was stripped - opts, args = getopt.getopt(sys.argv[1:], "hvclu:d:o:p:", ["help", "version", "no-hash-check", "peer-logging", "upload-limit=", "download-limit=", "output-dir=", "port="]) + opts, args = getopt.getopt(sys.argv[1:], "hvcln:u:d:o:p:", ["help", "version", "no-hash-check", "peer-logging", "max-connections=", "upload-limit=", "download-limit=", "output-dir=", "port="]) except getopt.GetoptError, err: print str(err) usage() @@ -107,6 +110,7 @@ def main(): # init to default values upload_limit = -1 download_limit = -1 + max_conns = -1 output_dir = os.getcwd() port = random.randint(10000, 65535) enable_hash_check = True @@ -123,6 +127,8 @@ def main(): download_limit = int(a) elif o in ("-u", "--upload-limit"): upload_limit = int(a) + elif o in ("-n", "--max-connections"): + max_conns = int(a) elif o in ("-v", "--version"): print_version() sys.exit(0) @@ -165,6 +171,8 @@ def main(): dscfg.set_max_speed(DOWNLOAD, download_limit) if upload_limit > 0: dscfg.set_max_speed(UPLOAD, upload_limit) + if max_conns > 0: + dscfg.set_max_conns(max_conns) if torrentfile_or_url.startswith("http") or torrentfile_or_url.startswith(P2PURL_SCHEME): tdef = TorrentDef.load_from_url(torrentfile_or_url) -- 2.20.1