tRestrict sending pieces to peers interested and not choking - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7e8d4120ee59ab30c1ebb9e3b42d324fd6136eec
 (DIR) parent c6bbaeb81ecc0d3493a3787971508b5d0a94132f
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Wed, 25 Mar 2020 11:46:31 +0100
       
       Restrict sending pieces to peers interested and not choking
       
       Diffstat:
         M libeech.c                           |      11 ++++++++++-
       
       1 file changed, 10 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -810,6 +810,13 @@ cb_request(struct torrent *t, struct peer *p, size_t sz, char *pl)
        {
                ssize_t i, bo, bl;
        
       +        /* only reply to requests if peer is interested and not choked */
       +        if (p->state & ISCHOKING)
       +                return -1;
       +
       +        if (!(p->state & ISINTERESTED))
       +                return -1;
       +
                i  = ntohl(U32(pl));
                bo = ntohl(U32(pl+4));
                bl = ntohl(U32(pl+8));
       t@@ -973,7 +980,9 @@ pwptx(struct torrent *t, struct peer *p)
                        /* send missing pieces as HAVE messages */
                        if (memcmp(t->bf, p->view, PCENUM / 8 + !!(PCENUM % 8)))
                                catchup(t, p);
       -                if (!(p->state & ISINTERESTED)) {
       +
       +                /* unchoke all interested peers when seeding */
       +                if (!(p->state & ISINTERESTED) && p->state & ISCHOKING) {
                                send_state(p, UNCHOKE);
                                p->state &= ~(ISCHOKING);
                        }