libeech

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

commit b16c6fa5a688b03a0488129f4351475b9751d5bc
parent f63985b044c1830c68418b81dfd33bb0d81fb08d
Author: z3bra <contactatz3bradotorg>
Date:   Thu Oct 19 17:05:41 +0200

Load infohash in torrent structure

Diffstat:
libeech.c | 32+++++++++++++++-----------------
libeech.h | 1+
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -13,10 +13,10 @@ /* helpers to retrieve attributes from metadata */ static char * peerid(); -static char * infohash(struct torrent *); static long torrentsize(struct torrent *); /* Initialization of the torrent struct */ +static int loadinfohash(struct torrent *); static int loadtracker(struct torrent *); static int loadpeerid(struct torrent *); @@ -36,22 +36,6 @@ peerid() return id; } -/* Calculate the SHA1 hash of the "info" key */ -static char * -infohash(struct torrent *t) -{ - char *sp; - struct be be; - static char hash[20]; - - if (bekv(&t->be, "info", 4, &be) < 0) - return NULL; - sp = be.off; - sha1(sp, be.end - be.start, hash); - - return hash; -} - /* Calculate full torrent size */ static long torrentsize(struct torrent *t) @@ -78,6 +62,19 @@ torrentsize(struct torrent *t) return sz; } +/* Calculate the SHA1 hash of the "info" key */ +static int +loadinfohash(struct torrent *t) +{ + struct be be; + + if (bekv(&t->be, "info", 4, &be) < 0) + return -1; + sha1(be.start, be.end - be.start, t->ih); + + return 0; +} + /* Retrieve the "announce" key */ static int loadtracker(struct torrent *t) @@ -113,6 +110,7 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s) loadpeerid(t); loadtracker(t); + loadinfohash(t); t->ul = 0; t->dl = 0; diff --git a/libeech.h b/libeech.h @@ -24,6 +24,7 @@ struct peer { struct torrent { char id[21]; + char ih[20]; char tr[PATH_MAX]; struct be be; long sz;