tSend INTERESTED message when leeching - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit a4a521c672ec7664c591e2fc30fde889300e9496
(DIR) parent 4616e4a455bc12ababe1bf987375cdfb89327654
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Fri, 29 Jun 2018 21:03:32 +0200
Send INTERESTED message when leeching
Diffstat:
M libeech.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -421,6 +421,22 @@ pwpbf(struct torrent *t, struct peer *p)
return send(p->fd, m, l + 5, MSG_NOSIGNAL);
}
+static ssize_t
+pwpinterest(struct peer *p, int interested)
+{
+ char m[MSGSIZ];
+
+ memset(m, 0, MSGSIZ);
+
+ /* Message length */
+ m[3] = 1;
+
+ /* Message type */
+ m[4] = interested ? 2 : 3;
+
+ return send(p->fd, m, 5, MSG_NOSIGNAL);
+}
+
static int
pwptx(struct torrent *t, struct peer *p)
{
t@@ -430,6 +446,12 @@ pwptx(struct torrent *t, struct peer *p)
pwpbf(t, p);
p->state |= HANDSHAKESENT;
}
+
+ if (p->state & LEECHING && !(p->state & AMINTERESTED)) {
+ pwpinterest(p, 1);
+ p->state |= AMINTERESTED;
+ }
+
return 0;
}