Changeset 1665


Ignore:
Timestamp:
Apr 5, 2007, 4:01:40 PM (15 years ago)
Author:
titer
Message:

Send 'cancel' messages when getting choked, in case the peer doesn't drop our previous requests as expected (one cause of overdownloading)

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peermessages.h

    r1600 r1665  
    335335 *
    336336 **********************************************************************/
    337 static void sendCancel( tr_torrent_t * tor, int block )
     337static void sendCancel( tr_peer_t * peer, int index, int begin,
     338                        int length )
     339{
     340    uint8_t * p;
     341    p = getMessagePointer( peer, 12, PEER_MSG_CANCEL );
     342
     343    TR_HTONL( index,  p     );
     344    TR_HTONL( begin,  p + 4 );
     345    TR_HTONL( length, p + 8 );
     346
     347    peer_dbg( "SEND cancel %d/%d (%d bytes)", index, begin, length );
     348}
     349
     350/***********************************************************************
     351 * broadcastCancel
     352 ***********************************************************************
     353 *
     354 **********************************************************************/
     355static void broadcastCancel( tr_torrent_t * tor, int index, int begin,
     356                             int length )
    338357{
    339358    int i, j;
    340     uint8_t * p;
    341359    tr_peer_t * peer;
    342360    tr_request_t * r;
     
    346364        peer = tor->peers[i];
    347365
    348         for( j = 1; j < peer->inRequestCount; j++ )
     366        for( j = 0; j < peer->inRequestCount; j++ )
    349367        {
    350368            r = &peer->inRequests[j];
    351369
    352             if( block != tr_block( r->index, r->begin ) )
     370            if( r->index != index || r->begin != begin ||
     371                r->length != length )
    353372            {
    354373                continue;
    355374            }
    356375
    357             p = getMessagePointer( peer, 12, PEER_MSG_CANCEL );
    358        
    359             /* Build the "cancel" message */
    360             TR_HTONL( r->index,  p     );
    361             TR_HTONL( r->begin,  p + 4 );
    362             TR_HTONL( r->length, p + 8 );
    363 
    364             peer_dbg( "SEND cancel %d/%d (%d bytes)",
    365                       r->index, r->begin, r->length );
     376            sendCancel( peer, index, begin, length );
    366377
    367378            (peer->inRequestCount)--;
     
    372383    }
    373384}
     385
     386
    374387
    375388/***********************************************************************
  • trunk/libtransmission/peerparse.h

    r1650 r1665  
    5555            r = &peer->inRequests[i];
    5656            tr_cpDownloaderRem( tor->completion, tr_block(r->index,r->begin) );
     57
     58            /* According to the spec, all requests are dropped when you
     59               are choked, however some clients seem to remember those
     60               the next time they unchoke you. Also, if you get quickly
     61               choked and unchoked while you are sending requests, you
     62               can't know when the other peer received them and how it
     63               handled it.
     64               This can cause us to receive blocks multiple times and
     65               overdownload, so we send 'cancel' messages to try and
     66               reduce that. */
     67            sendCancel( peer, r->index, r->begin, r->length );
    5768        }
    5869        peer->inRequestCount = 0;
     
    282293        /* Not in the list. Probably because of a cancel that arrived
    283294           too late */
     295        peer_dbg( "wasn't expecting this block" );
    284296    }
    285297}
     
    317329
    318330    updateRequests( tor, peer, index, begin );
    319     tor->downloadedCur += len;
     331    tor->downloadedCur += len - 8;
    320332
    321333    /* Sanity checks */
     
    344356    }
    345357    tr_cpBlockAdd( tor->completion, block );
    346     sendCancel( tor, block );
     358    broadcastCancel( tor, index, begin, len - 8 );
    347359
    348360    if( !tr_cpPieceHasAllBlocks( tor->completion, index ) )
Note: See TracChangeset for help on using the changeset viewer.