tpwphsrecv(): receive handshake from peer - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d8cb67c19cd23514c75e2697b7da2389d03d5c10
 (DIR) parent 5a9abb4e87943ab271a1ac7b4531665a13fd3ef0
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Fri,  3 Nov 2017 17:28:18 +0100
       
       pwphsrecv(): receive handshake from peer
       
       Diffstat:
         M libeech.c                           |      14 ++++++++++++++
         M libeech.h                           |       3 ++-
       
       2 files changed, 16 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -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()
       t@@ -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)
        {
 (DIR) diff --git a/libeech.h b/libeech.h
       t@@ -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;
        };