libeech

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

commit 5a9abb4e87943ab271a1ac7b4531665a13fd3ef0
parent 733ceaa38e147aec1a34dcb7fb3d4135a3b452a8
Author: z3bra <contactatz3bradotorg>
Date:   Fri Nov  3 16:33:17 +0100

pwphs(): send handshake to peer

Diffstat:
libeech.c | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -29,6 +29,9 @@ static struct peer * getpeer(struct peer *, char *, int); static struct peer * delpeer(struct peer *, struct peer *); static int peercnt(struct peer *); +/* handle peer wire protocol (PWP) messages */ +ssize_t pwphs(struct torrent *, struct peer *); + static char * peerid() { @@ -243,6 +246,19 @@ peercnt(struct peer *pl) return (pl ? 1 : 0) + peercnt(pl->next); } +ssize_t +pwphs(struct torrent *t, struct peer *p) +{ + char m[68]; + + m[0] = 19; + memcpy(m + 1, "BitTorrent protocol", 19); + memset(m + 20, 0, 8); + memcpy(m + 28, t->ih, 20); + memcpy(m + 48, t->id, 20); + + return send(p->fd, m, 68, MSG_NOSIGNAL); +} int glch_loadtorrent(struct torrent *t, char *b, size_t s)