libeech

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

commit 6b4860db6568bda6501332cb6134d1aeb0d9289c
parent 8bd983aaaf8eba4628785591c859d718300103a1
Author: z3bra <contactatz3bradotorg>
Date:   Sun Jul  1 13:02:26 +0200

Implement function pwphv() to send HAVE messages

Diffstat:
libeech.c | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -66,6 +66,7 @@ static ssize_t pwphsrecv(struct peer *); static int pwphsck(struct torrent *, char *, long); static ssize_t pwpst(struct peer *, int); +static ssize_t pwphv(struct peer *, int); static ssize_t pwpbf(struct torrent *, struct peer *); static ssize_t pwprq(struct torrent *, struct peer *); @@ -437,6 +438,31 @@ pwpst(struct peer *p, int t) } static ssize_t +pwphv(struct peer *p, int n) +{ + char m[MSGSIZ]; + ssize_t off = 0; + + memset(m, 0, 9); + /* Message length */ + m[off++] = (9 >> 24) & 0xff; + m[off++] = (9 >> 16) & 0xff; + m[off++] = (9 >> 8) & 0xff; + m[off++] = (9 >> 0) & 0xff; + + /* Message type */ + m[off++] = HAVE; + + /* Piece number */ + m[off++] = (n >> 24) & 0xff; + m[off++] = (n >> 16) & 0xff; + m[off++] = (n >> 8) & 0xff; + m[off++] = (n >> 0) & 0xff; + + return send(p->fd, m, 9, MSG_NOSIGNAL); +} + +static ssize_t pwpbf(struct torrent *t, struct peer *p) { char m[MSGSIZ];