libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit 92e07b92638cf8d3884da8aa60724057e2a6545f
parent 15d5a438034b9722da96ae6264b34dbb9641f1ba
Author: z3bra <contactatz3bradotorg>
Date:   Sat Jun 30 01:27:13 +0200

Add handlers for simple messages

Diffstat:
libeech.c | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -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; }