Changeset 2983


Ignore:
Timestamp:
Sep 7, 2007, 4:49:05 AM (15 years ago)
Author:
charles
Message:

a little more work on requests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/peer-msgs.c

    r2982 r2983  
    158158
    159159static int
    160 isInteresting( const tr_peermsgs * peer )
     160isPeerInteresting( const tr_peermsgs * peer )
    161161{
    162162    int i;
     
    190190updateInterest( tr_peermsgs * peer )
    191191{
    192     const int i = isInteresting( peer );
     192    const int i = isPeerInteresting( peer );
    193193    if( i != peer->info->clientIsInterested )
    194194        sendInterest( peer, i );
     
    225225tr_peerMsgsAddRequest( tr_peermsgs * peer,
    226226                       uint32_t      index,
    227                        uint32_t      begin,
     227                       uint32_t      offset,
    228228                       uint32_t      length )
    229229{
     
    234234        const uint8_t bt_msgid = BT_REQUEST;
    235235        const uint32_t len = sizeof(uint8_t) + 3 * sizeof(uint32_t);
    236         struct peer_request * req = tr_new( peer_request, 1 );
     236        struct peer_request * req = tr_new( struct peer_request, 1 );
    237237
    238238        tr_peerIoWriteUint32( peer->io, peer->outMessages, len );
    239239        tr_peerIoWriteBytes( peer->io, peer->outMessages, &bt_msgid, 1 );
    240240        tr_peerIoWriteUint32( peer->io, peer->outMessages, index );
    241         tr_peerIoWriteUint32( peer->io, peer->outMessages, begin );
     241        tr_peerIoWriteUint32( peer->io, peer->outMessages, offset );
    242242        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 );
     243        fprintf( stderr, "peer %p: requesting a block from piece %u, offset %u, length %u\n",
     244                         peer, (unsigned int)index, (unsigned int)offset, (unsigned int)length );
    245245
    246246        req->index = index;
    247         req->begin = begin;
     247        req->offset = offset;
    248248        req->length = length;
    249249        tr_list_append( &peer->clientAskedFor, req );
     
    538538
    539539static int
    540 weAskedForThisBlock( const tr_peermsgs * peer, uint32_t index, uint32_t offset, uint32_t
     540weAskedForThisBlock( const tr_peermsgs * peer, uint32_t index, uint32_t offset, uint32_t length )
     541{
     542    struct peer_request tmp;
     543    tmp.index = index;
     544    tmp.offset = offset;
     545    tmp.length = length;
     546
     547    return tr_list_find( peer->clientAskedFor, &tmp, peer_request_compare_func ) != NULL;
     548}
    541549
    542550static void
     
    556564        return;
    557565    }
    558 
    559 cc
    560 struct 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 
    570 ccc
    571     --peer->outReqCount;
     566    if( !weAskedForThisBlock( peer, index, offset, len ) ) {
     567        tr_dbg( "we didn't ask the peer for this message..." );
     568        return;
     569    }
    572570
    573571    /* write to disk */
     
    585583    tr_rcTransferred( tor->download, len );
    586584    tr_rcTransferred( tor->handle->download, len );
    587 
    588 //    broadcastCancel( tor, index, begin, len - 8 );
    589585}
    590586
Note: See TracChangeset for help on using the changeset viewer.