tSet bitfield on startup - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 80845b4a09b0032d352fb34678e09d03e6f2400c
(DIR) parent a3feb8c50165995ebc29431f7ec15ada67ddb92f
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Sun, 25 Feb 2018 06:28:18 -0500
Set bitfield on startup
Diffstat:
M libeech.c | 4 +++-
M libeech.h | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -500,11 +500,13 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s)
bekstr(&t->info, "pieces", 6, &v);
memcpy(t->ph, v.off, v.end - v.off);
t->pieces = malloc(t->npiece * sizeof(*t->pieces));
+ t->bf = malloc(t->npiece / 8 + 1);
+ memset(t->bf, 0, t->npiece / 8 + 1);
for (i = 0; i < t->npiece; i++) {
readpiece(t, &t->pieces[i], i);
if (!chkpiece(t, &t->pieces[i], i)) {
- /* things to do when chksum is valid */
+ setbit(t->bf, i);
}
}
(DIR) diff --git a/libeech.h b/libeech.h
t@@ -45,6 +45,7 @@ struct torrent {
char ih[20];
char tr[PATH_MAX];
char *ph;
+ char *bf;
struct be be;
struct be info;
struct peer *peers;