libeech

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

commit d8cb67c19cd23514c75e2697b7da2389d03d5c10
parent 5a9abb4e87943ab271a1ac7b4531665a13fd3ef0
Author: z3bra <contactatz3bradotorg>
Date:   Fri Nov  3 17:28:18 +0100

pwphsrecv(): receive handshake from peer

Diffstat:
libeech.c | 14++++++++++++++
libeech.h | 3++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/libeech.c b/libeech.c @@ -31,6 +31,7 @@ static int peercnt(struct peer *); /* handle peer wire protocol (PWP) messages */ ssize_t pwphs(struct torrent *, struct peer *); +ssize_t pwphsrecv(struct peer *); static char * peerid() @@ -260,6 +261,19 @@ pwphs(struct torrent *t, struct peer *p) return send(p->fd, m, 68, MSG_NOSIGNAL); } +ssize_t +pwphsrecv(struct peer *p) +{ + ssize_t r; + + /* read message length, sent as 4 bytes integer */ + p->buflen = 0; + while (p->buflen < 68 && (r = recv(p->fd, p->buf, 68, 0)) > 0) + p->buflen += r; + + return p->buflen; +} + int glch_loadtorrent(struct torrent *t, char *b, size_t s) { diff --git a/libeech.h b/libeech.h @@ -22,7 +22,8 @@ struct peer { int state; int port; char host[HOST_NAME_MAX]; - int (*connect)(char *, int); + char buf[MSGSIZ]; + long buflen; struct peer *next; };