libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit 97095244b34d1cc1b0678b9dcd84908ae9388cb6
parent 802b7ec302e36a3e2bc57cae0d09114093181ecc
Author: z3bra <contactatz3bradotorg>
Date:   Sat Feb 10 13:54:56 +0100

Retrieve piece len, number and sha1 from torrent file

Diffstat:
libeech.c | 7+++++++
libeech.h | 3+++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -388,6 +388,13 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s) t->nfile = torrentfiles(t); t->peers = NULL; + /* pieces related values */ + t->psz = bekint(&t->info, "piece length", 12); + t->npiece = t->sz / t->psz + !!(t->sz % t->psz); + t->pieces = malloc(t->npiece * 20); + bekstr(&t->be, "pieces", 6, &v); + memcpy(t->pieces, v.off, v.end - v.off); + return 0; } diff --git a/libeech.h b/libeech.h @@ -38,11 +38,14 @@ struct torrent { char id[21]; char ih[20]; char tr[PATH_MAX]; + char *pieces; struct be be; struct be info; struct peer *peers; struct file *files; + long npiece; long nfile; + long psz; long sz; long dl; long ul;