next-share: add peer connection limit
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Tue, 21 Sep 2010 08:39:14 +0000 (10:39 +0200)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Tue, 21 Sep 2010 08:39:14 +0000 (10:39 +0200)
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

index 0f7594c..a000f51 100644 (file)
@@ -42,6 +42,9 @@ def usage():
     print "\t--upload-limit <up-speed-limit>"
     print "\t-u <up-speed-limit>\tupload speed limitation in KB/s"
     print "\t\t\t\t(default is no upload limit)"
+    print "\t--max-connections <num-connections>"
+    print "\t-n <num-connections>\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)