tCorrectly set bitfield, and actually send it - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e4776677ff079bc800b63a77587528bae051067b
 (DIR) parent ac6b3082a4dcd6694b7171658356d7bb917f1097
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Wed,  4 Jul 2018 08:53:34 +0200
       
       Correctly set bitfield, and actually send it
       
       Diffstat:
         M libeech.c                           |       5 ++++-
         M libeech.h                           |       4 ++--
       
       2 files changed, 6 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -511,6 +511,9 @@ pwptxbf(struct torrent *t, struct peer *p)
                /* Message type */
                m[4] = BITFIELD;
        
       +        /* Bitfield */
       +        memcpy(m+5, t->bf, l);
       +
                return pwpsend(p, m, l + 5);
        }
        
       t@@ -800,7 +803,7 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s)
                t->npiece = t->sz / t->psz + !!(t->sz % t->psz);
                bekstr(&t->info, "pieces", 6, &v);
                memcpy(t->ph, v.off, v.end - v.off);
       -        memset(t->bf, 0, t->npiece / 8 + 1);
       +        memset(t->bf, 0, PCENUM / 8);
        
                for (i = 0; i < t->npiece; i++) {
                        if (readpiece(t, &piece, i) > 0 && !chkpiece(t, &piece, i))
 (DIR) diff --git a/libeech.h b/libeech.h
       t@@ -24,8 +24,8 @@ struct piece {
                int n;
                ssize_t sz;
                char blks[PCESIZ];
       -        char bf[PCESIZ / BLKSIZ];
       -        char rq[PCESIZ / BLKSIZ];
       +        char bf[PCENUM / 8];
       +        char rq[PCENUM / 8];
        };
        
        struct peer {