tRearrange pwp function in message type order - libeech - bittorrent library
 (HTM) git clone git://z3bra.org/libeech.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 4d12ab42b1daabd2261e55ef66ca8d6f42d206a1
 (DIR) parent e225e5d0cb91814ee69fa1ca0ed2d912791719fd
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Sun,  1 Jul 2018 12:53:49 +0200
       
       Rearrange pwp function in message type order
       
       Diffstat:
         M libeech.c                           |      34 ++++++++++++++++----------------
       
       1 file changed, 17 insertions(+), 17 deletions(-)
       ---
 (DIR) diff --git a/libeech.c b/libeech.c
       t@@ -65,8 +65,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 pwpst(struct peer *, int);
        static ssize_t pwpbf(struct torrent *, struct peer *);
       -static ssize_t pwpchst(struct peer *, int);
        static ssize_t pwprq(struct torrent *, struct peer *);
        
        static int pwptx(struct torrent *, struct peer *);
       t@@ -413,40 +413,40 @@ pwprecv(struct peer *p)
         */
        
        static ssize_t
       -pwpbf(struct torrent *t, struct peer *p)
       +pwpst(struct peer *p, int t)
        {
                char m[MSGSIZ];
       -        ssize_t l, off = 0;
        
       -        l = t->npiece / 8 + 1;
       +        memset(m, 0, 5);
        
       -        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;
       +        m[3] = 1;
        
                /* Message type */
       -        m[off++] = BITFIELD;
       +        m[4] = t;
        
       -        return send(p->fd, m, l + 5, MSG_NOSIGNAL);
       +        return send(p->fd, m, 5, MSG_NOSIGNAL);
        }
        
        static ssize_t
       -pwpchst(struct peer *p, int t)
       +pwpbf(struct torrent *t, struct peer *p)
        {
                char m[MSGSIZ];
       +        ssize_t l, off = 0;
        
       -        memset(m, 0, 5);
       +        l = t->npiece / 8 + 1;
        
       +        memset(m, 0, l + 5);
                /* Message length */
       -        m[3] = 1;
       +        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[4] = t;
       +        m[off++] = BITFIELD;
        
       -        return send(p->fd, m, 5, MSG_NOSIGNAL);
       +        return send(p->fd, m, l + 5, MSG_NOSIGNAL);
        }
        
        static ssize_t
       t@@ -519,7 +519,7 @@ pwptx(struct torrent *t, struct peer *p)
                }
        
                if ((p->state & LEECHING) && !(p->state & AMINTERESTED)) {
       -                pwpchst(p, INTERESTED);
       +                pwpst(p, INTERESTED);
                        p->state |= AMINTERESTED;
                }