libeech

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

commit cdd7c5d525296210093f84fc0407f6bb0012a7c3
parent 4d12ab42b1daabd2261e55ef66ca8d6f42d206a1
Author: z3bra <contactatz3bradotorg>
Date:   Sun Jul  1 12:54:45 +0200

Setup callback functions for received messages

Diffstat:
libeech.c | 86++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 70 insertions(+), 16 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -69,6 +69,14 @@ static ssize_t pwpst(struct peer *, int); static ssize_t pwpbf(struct torrent *, struct peer *); static ssize_t pwprq(struct torrent *, struct peer *); +static int pwprxst(struct peer *, int); +static int pwprxhv(struct peer *, size_t, char *); +static int pwprxbf(struct peer *, size_t, char *); +static int pwprxrq(struct torrent *, struct peer *, size_t, char *); +static int pwprxpc(struct torrent *, struct peer *, size_t, char *); + +static int pwprxcb(struct torrent *, struct peer *, int, size_t, char *); + static int pwptx(struct torrent *, struct peer *); static int pwprx(struct torrent *, struct peer *); @@ -509,6 +517,64 @@ pwprq(struct torrent *t, struct peer *p) } static int +pwprxst(struct peer *p, int type) +{ + return 0; +} + +static int +pwprxhv(struct peer *p, size_t sz, char *pl) +{ + return 0; +} + +static int +pwprxbf(struct peer *p, size_t sz, char *pl) +{ + return 0; +} + +static int +pwprxrq(struct torrent *t, struct peer *p, size_t sz, char *pl) +{ + return 0; +} + +static int +pwprxpc(struct torrent *t, struct peer *p, size_t sz, char *pl) +{ + return 0; +} + +static int +pwprxcb(struct torrent *t, struct peer *p, int type, size_t sz, char *pl) +{ + switch (type) { + case CHOKE: + case UNCHOKE: + case INTERESTED: + case UNINTERESTED: + pwprxst(p, type); + break; + case HAVE: + break; + case BITFIELD: + pwprxbf(p, sz, pl); + break; + case REQUEST: + pwprxrq(t, p, sz, pl); + break; + case PIECE: + pwprxpc(t, p, sz, pl); + break; + case CANCEL: + /* not handled */ + break; + } + return 0; +} + +static int pwptx(struct torrent *t, struct peer *p) { /* send handshake */ @@ -541,22 +607,10 @@ pwprx(struct torrent *t, struct peer *p) } p->rxbufsz = 0; p->state |= HANDSHAKERCVD; - } else { - 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); - } + } else if (!pwprecv(p)) { + pwprxcb(t, p, p->rxbuf[4], p->rxbufsz- 5, p->rxbuf+4); + memset(p->rxbuf, 0, MSGSIZ); + p->rxbufsz = 0; } return 0;