shithub: riscv

Download patch

ref: 83865180a29d7feba2a1f460abf17315562141c3
parent: f8d5cc7230ee2cb7521d90599d525e205ad84fa6
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Tue Oct 25 10:55:24 EDT 2011

torrent: calculate piece length depending on file size

--- a/sys/src/cmd/ip/torrent.c
+++ b/sys/src/cmd/ip/torrent.c
@@ -764,8 +764,12 @@
 		werrstr("empty file");
 		return -1;
 	}
-	blocksize = 1024*1024;
-	npieces = (d->length + blocksize-1) / blocksize;
+	npieces = 1;
+	for(blocksize = 256*1024;;blocksize<<=1){
+		npieces = (d->length + blocksize-1) / blocksize;
+		if(npieces <= 8*1024 || blocksize >= 2*1024*1024)
+			break;
+	}
 	print("d");
 	print("8:announce%ld:%s", strlen(url), url);
 	print("4:info");