From 83865180a29d7feba2a1f460abf17315562141c3 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 25 Oct 2011 14:55:24 +0200 Subject: [PATCH] torrent: calculate piece length depending on file size --- sys/src/cmd/ip/torrent.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/ip/torrent.c b/sys/src/cmd/ip/torrent.c index f4d8bc1de..9a24155c7 100644 --- a/sys/src/cmd/ip/torrent.c +++ b/sys/src/cmd/ip/torrent.c @@ -764,8 +764,12 @@ mktorrent(int fd, char *url) 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");