tPermit requesting multiple pieces - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e308b69b6b819eed9e2e29cab389ce4879c61d8b
 (DIR) parent 115117034d00618ff235ffc27b60277035a0e759
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Thu,  5 Jul 2018 08:15:00 +0200
       
       Permit requesting multiple pieces
       
       Diffstat:
         M libeech.c                           |       6 +++++-
       
       1 file changed, 5 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -525,7 +525,10 @@ pwptxrq(struct torrent *t, struct peer *p)
                ssize_t bl;
        
                /* Find a missing piece we can get from the peer */
       -        for (i = 0; i >= t->npiece || (!bit(t->bf, i) && bit(p->bf, i)); i++);
       +        for (i = 0; i < t->npiece && (bit(t->bf, i) || !bit(p->bf, i)); i++);
       +
       +        if (i == t->npiece)
       +                return -1;
        
                p->piece.n = i;
                p->piece.sz = (i == t->npiece - 1) ? t->sz % t->psz : t->psz;
       t@@ -621,6 +624,7 @@ pwprxpc(struct torrent *t, struct peer *p, size_t sz, char *pl)
                        setbit(t->bf, p->piece.n);
                        for (b = t->peers; b; b = b->next)
                                pwptxhv(b, p->piece.n);
       +                p->piece.n = -1;
                }
        
                return 0;