torrentd

simple torrent daemon
git clone git://git.2f30.org/torrentd
Log | Files | Refs | LICENSE

commit 215e0c41bc61a27c66f743ab2c060f28164b4205
parent 315fddd11fdc92ba01c3d80a08dc0e33e81a5cff
Author: sin <sin@2f30.org>
Date:   Mon, 21 Dec 2015 20:20:18 +0000

Add t->totallen

Diffstat:
Mstorrent.h | 1+
Mtorrent.c | 8++++----
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/storrent.h b/storrent.h @@ -31,6 +31,7 @@ struct torrent { char *filename; struct file *files; size_t nfiles; + size_t totallen; uint8_t infohash[20]; long long piecelen; long long npieces; diff --git a/torrent.c b/torrent.c @@ -58,7 +58,7 @@ loadtorrent(char *f) struct torrent *t; struct ben *files, *file; struct ben *length, *path, *tmp, *a; - size_t i, j, pathlen, totallen = 0; + size_t i, j, pathlen; char *p; t = ecalloc(1, sizeof(*t)); @@ -158,7 +158,7 @@ loadtorrent(char *f) warnx("length is < 0 in %s", f); goto fail; } - totallen += length->i; + t->totallen += length->i; t->files[t->nfiles].len = length->i; if (!(path = dlookstr(file->v, "path"))) @@ -201,10 +201,10 @@ loadtorrent(char *f) t->files[0].len = length->i; t->files[0].path = t->filename; t->filename = strdup(""); - totallen = length->i; + t->totallen = length->i; } - t->npieces = (totallen + t->piecelen - 1) / t->piecelen; + t->npieces = (t->totallen + t->piecelen - 1) / t->piecelen; t->piecebm = newbit(t->npieces); calcinfohash(t);