tFactorize handshake checks functions - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 84e77364f46895cec2614f767a013028611f9962
(DIR) parent e93c18236b4d74ace9d237ffaf1ec75b7c17ea72
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Sat, 10 Feb 2018 13:51:30 +0100
Factorize handshake checks functions
Diffstat:
M libeech.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -346,12 +346,14 @@ netloop(struct torrent *t, int timeout)
if (pfds.fds[i].revents & POLLIN) {
/* receive and verify handshake */
if (!(pfds.p[i]->state & HANDSHAKERCVD)) {
- if (pwphsrecv(pfds.p[i]) >= 68)
+ if (pwphsrecv(pfds.p[i]) >= 68 && !pwphsck(t, pfds.p[i]->buf, pfds.p[i]->buflen))
pfds.p[i]->state |= HANDSHAKERCVD;
- if (!pwphsck(t, pfds.p[i]->buf, pfds.p[i]->buflen))
- pfds.p[i]->state |= CONNECTED;
}
}
+
+ /* peer is now ready to exchange data */
+ if (pfds.p[i]->state & HANDSHAKESENT && pfds.p[i]->state & HANDSHAKERCVD)
+ pfds.p[i]->state |= CONNECTED|SEEDING|LEECHING|AMCHOKING;
}
return npeer;