tLoad infohash in torrent structure - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit b16c6fa5a688b03a0488129f4351475b9751d5bc
(DIR) parent f63985b044c1830c68418b81dfd33bb0d81fb08d
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Thu, 19 Oct 2017 17:05:41 +0200
Load infohash in torrent structure
Diffstat:
M libeech.c | 32 +++++++++++++++----------------
M libeech.h | 1 +
2 files changed, 16 insertions(+), 17 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -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 *);
t@@ -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)
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)
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;
(DIR) diff --git a/libeech.h b/libeech.h
t@@ -24,6 +24,7 @@ struct peer {
struct torrent {
char id[21];
+ char ih[20];
char tr[PATH_MAX];
struct be be;
long sz;