tAdd handlers for simple messages - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 92e07b92638cf8d3884da8aa60724057e2a6545f
 (DIR) parent 15d5a438034b9722da96ae6264b34dbb9641f1ba
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Sat, 30 Jun 2018 01:27:13 +0200
       
       Add handlers for simple messages
       
       Diffstat:
         M libeech.c                           |      18 ++++++++++++++++--
       
       1 file changed, 16 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -478,9 +478,23 @@ pwprx(struct torrent *t, struct peer *p)
                        p->rxbufsz = 0;
                        p->state |= HANDSHAKERCVD;
                } else {
       -                if (!(p->rxbufsz = pwprecv(p)))
       -                        printf("Message ID: %d (%d bytes)\n", p->rxbuf[4], U32(p->rxbuf));
       +                if (!pwprecv(p)) {
       +                        switch (p->rxbuf[4]) {
       +                        case 0:
       +                                p->state |= AMCHOKING;
       +                                break;
       +                        case 1:
       +                                p->state &= ~(AMCHOKING);
       +                                break;
       +                        case 5:
       +                                memcpy(p->bf, p->rxbuf+4, p->rxbufsz - 5);
       +                                break;
       +                        }
       +                        p->rxbufsz = 0;
       +                        memset(p->rxbuf, 0, MSGSIZ);
       +                }
                }
       +
                return 0;
        }