tSend bitfield right after handshake - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 4129efb6930f09c75b9c9037579149f538a038d6
 (DIR) parent 80845b4a09b0032d352fb34678e09d03e6f2400c
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Sun, 25 Feb 2018 07:30:44 -0500
       
       Send bitfield right after handshake
       
       Diffstat:
         M libeech.c                           |      31 +++++++++++++++++++++++++++++++
       
       1 file changed, 31 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -49,6 +49,8 @@ static ssize_t pwphs(struct torrent *, struct peer *);
        static ssize_t pwphsrecv(struct peer *);
        static int pwphsck(struct torrent *, char *, long);
        
       +static ssize_t pwpbf(struct torrent *, struct peer *);
       +
        static int pwptx(struct torrent *, struct peer *);
        static int pwprx(struct torrent *, struct peer *);
        
       t@@ -362,12 +364,41 @@ pwphsck(struct torrent *t, char *hs, long l)
                return 0;
        }
        
       +/*
       + * Standard PWP messages: [LENGTH][TYPE][PAYLOAD]
       + * Length: 4 bytes bigendian; Size of the type + payload
       + * Type is a single byte
       + * Payload is variable and is length - 1
       + */
       +
       +static ssize_t
       +pwpbf(struct torrent *t, struct peer *p)
       +{
       +        char m[MSGSIZ];
       +        ssize_t l, off = 0;
       +
       +        l = t->npiece / 8 + 1;
       +
       +        memset(m, 0, l + 5);
       +        /* Message length */
       +        m[off++] = ((l + 1) >> 24) & 0xff;
       +        m[off++] = ((l + 1) >> 16) & 0xff;
       +        m[off++] = ((l + 1) >> 8)  & 0xff;
       +        m[off++] = ((l + 1) >> 0)  & 0xff;
       +
       +        /* Message type */
       +        m[off++] = 5;
       +
       +        return send(p->fd, m, l + 5, MSG_NOSIGNAL);
       +}
       +
        static int
        pwptx(struct torrent *t, struct peer *p)
        {
                /* send handshake */
                if (!(p->state & HANDSHAKESENT)) {
                        pwphs(t, p);
       +                pwpbf(t, p);
                        p->state |= HANDSHAKESENT;
                }
                return 0;