tGet rid of loadinfohash by saving the 'info' key data - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a9b0348be67fa7baacce53c098b659e7e24b0268
 (DIR) parent b16c6fa5a688b03a0488129f4351475b9751d5bc
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Fri, 20 Oct 2017 08:49:11 +0200
       
       Get rid of loadinfohash by saving the 'info' key data
       
       Diffstat:
         M libeech.c                           |      19 ++++---------------
         M libeech.h                           |       1 +
       
       2 files changed, 5 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -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 *);
        
       t@@ -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)
       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;
 (DIR) diff --git a/libeech.h b/libeech.h
       t@@ -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;