tRemove useless factorization from glch_loadtorrent() - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 565c2cd5e1797bdab81b3f82bcc5af1033330aaf
(DIR) parent 5868460df17098197b391fac804998f67ef696cf
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Sun, 22 Oct 2017 10:28:45 +0200
Remove useless factorization from glch_loadtorrent()
Diffstat:
M libeech.c | 45 +++++++-------------------------
1 file changed, 9 insertions(+), 36 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -16,10 +16,6 @@ static char * peerid();
static long torrentsize(struct torrent *);
static int chktorrent(struct be *);
-/* Initialization of the torrent struct */
-static int loadtracker(struct torrent *);
-static int loadpeerid(struct torrent *);
-
static char *
peerid()
{
t@@ -62,33 +58,6 @@ torrentsize(struct torrent *t)
return sz;
}
-/* Retrieve the "announce" key */
-static int
-loadtracker(struct torrent *t)
-{
- struct be v;
-
- if (bekstr(&t->be, "announce", 8, &v) < 0)
- return -1;
-
- memcpy(t->tr, v.off, v.end - v.off);
- return 0;
-}
-
-/* Generate a random peer ID */
-static int
-loadpeerid(struct torrent *t)
-{
- char *sp;
-
- sp = peerid();
- if (!sp)
- return -1;
- memcpy(t->id, sp, 20);
- t->id[20] = 0;
- return 0;
-}
-
static int
chktorrent(struct be *b)
{
t@@ -140,19 +109,23 @@ chktorrent(struct be *b)
int
glch_loadtorrent(struct torrent *t, char *b, size_t s)
{
+ struct be v;
+
if (beinit(&t->be, b, s) < 0)
return -1;
if (chktorrent(&t->be) < 0)
return -1;
- if (bekv(&t->be, "info", 4, &t->info) < 0)
- return -1;
-
- loadpeerid(t);
- loadtracker(t);
+ bekv(&t->be, "info", 4, &t->info);
sha1(t->info.start, t->info.end - t->info.start, t->ih);
+ bekstr(&t->be, "announce", 8, &v);
+ memcpy(t->tr, v.off, v.end - v.off);
+
+ memcpy(t->id, peerid(), 20);
+ t->id[20] = 0;
+
t->ul = 0;
t->dl = 0;