libeech

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

commit a9b0348be67fa7baacce53c098b659e7e24b0268
parent b16c6fa5a688b03a0488129f4351475b9751d5bc
Author: z3bra <contactatz3bradotorg>
Date:   Fri Oct 20 08:49:11 +0200

Get rid of loadinfohash by saving the 'info' key data

Diffstat:
libeech.c | 19++++---------------
libeech.h | 1+
2 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -16,7 +16,6 @@ static char * peerid(); 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 *); @@ -62,19 +61,6 @@ 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) @@ -108,9 +94,12 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s) if (beinit(&t->be, b, s) < 0) return -1; + if (bekv(&t->be, "info", 4, &t->info) < 0) + return -1; + loadpeerid(t); loadtracker(t); - loadinfohash(t); + sha1(t->info.start, t->info.end - t->info.start, t->ih); t->ul = 0; t->dl = 0; diff --git a/libeech.h b/libeech.h @@ -27,6 +27,7 @@ struct torrent { char ih[20]; char tr[PATH_MAX]; struct be be; + struct be info; long sz; long dl; long ul;