Changeset 2982


Ignore:
Timestamp:
Sep 6, 2007, 9:00:39 PM (15 years ago)
Author:
charles
Message:

requests

Location:
branches/encryption/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/list.c

    r2942 r2982  
    137137    }
    138138}
     139
     140int
     141tr_list_size( const tr_list * list )
     142{
     143    int ret = 0;
     144
     145    while( list )
     146    {
     147        ++list;
     148        list = list->next;
     149    }
     150
     151    return ret;
     152}
  • branches/encryption/libtransmission/list.h

    r2942 r2982  
    2424typedef int (*TrListCompareFunc)(const void * a, const void * b);
    2525typedef void (*TrListForeachFunc)(void *);
     26
     27int         tr_list_size           ( const tr_list    * list );
    2628
    2729void        tr_list_free           ( tr_list         ** list );
  • branches/encryption/libtransmission/peer-msgs.c

    r2978 r2982  
    4444#define PEX_INTERVAL (MINUTES_TO_MSEC(1))
    4545
     46/* the most requests we'll batch up for this peer */
     47#define MAX_OUT_REQUESTS 10
     48
    4649enum
    4750{
     
    112115    struct evbuffer * inBlock;     /* the block we're currently receiving */
    113116    tr_list * peerAskedFor;
    114     tr_list * outPieces;
     117    tr_list * clientAskedFor;
    115118
    116119    tr_timer_tag pulseTag;
     
    213216        tr_peerIoWriteBytes( peer->io, peer->outMessages, &bt_msgid, 1 );
    214217    }
     218}
     219
     220/**
     221***
     222**/
     223
     224int
     225tr_peerMsgsAddRequest( tr_peermsgs * peer,
     226                       uint32_t      index,
     227                       uint32_t      begin,
     228                       uint32_t      length )
     229{
     230    int ret =-1;
     231
     232    if( tr_list_size(peer->clientAskedFor) < MAX_OUT_REQUESTS )
     233    {
     234        const uint8_t bt_msgid = BT_REQUEST;
     235        const uint32_t len = sizeof(uint8_t) + 3 * sizeof(uint32_t);
     236        struct peer_request * req = tr_new( peer_request, 1 );
     237
     238        tr_peerIoWriteUint32( peer->io, peer->outMessages, len );
     239        tr_peerIoWriteBytes( peer->io, peer->outMessages, &bt_msgid, 1 );
     240        tr_peerIoWriteUint32( peer->io, peer->outMessages, index );
     241        tr_peerIoWriteUint32( peer->io, peer->outMessages, begin );
     242        tr_peerIoWriteUint32( peer->io, peer->outMessages, length );
     243        fprintf( stderr, "peer %p: requesting a block from piece %u, begin %u, length %u\n",
     244                         peer, (unsigned int)index, (unsigned int)begin, (unsigned int)length );
     245
     246        req->index = index;
     247        req->begin = begin;
     248        req->length = length;
     249        tr_list_append( &peer->clientAskedFor, req );
     250
     251        ret = 0;
     252    }
     253
     254    return ret;
    215255}
    216256
     
    497537}
    498538
     539static int
     540weAskedForThisBlock( const tr_peermsgs * peer, uint32_t index, uint32_t offset, uint32_t
     541
    499542static void
    500543gotBlock( tr_peermsgs * peer, int index, int offset, struct evbuffer * inbuf )
     
    513556        return;
    514557    }
     558
     559cc
     560struct peer_request
     561{
     562    uint32_t index;
     563    uint32_t offset;
     564    uint32_t length;
     565};
     566
     567
     568        tr_list_append( &peer->clientAskedFor, req );
     569
     570ccc
     571    --peer->outReqCount;
    515572
    516573    /* write to disk */
  • branches/encryption/libtransmission/peer-msgs.h

    r2968 r2982  
    2626void         tr_peerMsgsFree( tr_peermsgs* );
    2727
     28int          tr_peerMsgsAddRequest( tr_peermsgs * peer,
     29                                    uint32_t      index,
     30                                    uint32_t      begin,
     31                                    uint32_t      length );
     32
     33
    2834#endif
Note: See TracChangeset for help on using the changeset viewer.