tpwphs(): send handshake to peer - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 5a9abb4e87943ab271a1ac7b4531665a13fd3ef0
(DIR) parent 733ceaa38e147aec1a34dcb7fb3d4135a3b452a8
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Fri, 3 Nov 2017 16:33:17 +0100
pwphs(): send handshake to peer
Diffstat:
M libeech.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -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()
{
t@@ -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)