Ignore:
Timestamp:
Mar 8, 2010, 4:29:58 AM (12 years ago)
Author:
charles
Message:

(trunk) #2993 "'Downloaded' much greater than 'Have' or 'verified'" -- add new congestion-based throttle for 2.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r10325 r10332  
    675675**/
    676676
    677 static tr_bool
    678 isPieceInteresting( const tr_peermsgs * msgs,
    679                     tr_piece_index_t    piece )
    680 {
    681     const tr_torrent * torrent = msgs->torrent;
    682 
    683     return ( !torrent->info.pieces[piece].dnd )                  /* we want it */
    684           && ( !tr_cpPieceIsComplete( &torrent->completion, piece ) ) /* !have */
    685           && ( tr_bitsetHas( &msgs->peer->have, piece ) );      /* peer has it */
    686 }
    687 
    688 /* "interested" means we'll ask for piece data if they unchoke us */
    689 static tr_bool
    690 isPeerInteresting( const tr_peermsgs * msgs )
    691 {
    692     tr_piece_index_t    i;
    693     const tr_torrent *  torrent;
    694     const tr_bitfield * bitfield;
    695     const int           clientIsSeed = tr_torrentIsSeed( msgs->torrent );
    696 
    697     if( clientIsSeed )
    698         return FALSE;
    699 
    700     if( !tr_torrentIsPieceTransferAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )
    701         return FALSE;
    702 
    703     torrent = msgs->torrent;
    704     bitfield = tr_cpPieceBitfield( &torrent->completion );
    705 
    706     for( i = 0; i < torrent->info.pieceCount; ++i )
    707         if( isPieceInteresting( msgs, i ) )
    708             return TRUE;
    709 
    710     return FALSE;
    711 }
    712 
    713677static void
    714678sendInterest( tr_peermsgs * msgs, tr_bool clientIsInterested )
     
    729693
    730694static void
    731 updateInterest( tr_peermsgs * msgs )
    732 {
    733     const int i = isPeerInteresting( msgs );
    734 
    735     if( i != msgs->peer->clientIsInterested )
    736         sendInterest( msgs, i );
     695updateInterest( tr_peermsgs * msgs UNUSED )
     696{
     697    /* FIXME -- might need to poke the mgr on startup */
     698}
     699
     700void
     701tr_peerMsgsSetInterested( tr_peermsgs * msgs, int isInterested )
     702{
     703    assert( tr_isBool( isInterested ) );
     704
     705    if( isInterested != msgs->peer->clientIsInterested )
     706        sendInterest( msgs, isInterested );
    737707}
    738708
     
    838808{
    839809    struct peer_request req;
     810/*fprintf( stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n", (size_t)block, msgs->peer );*/
    840811    blockToReq( msgs->torrent, block, &req );
    841812    protocolSendCancel( msgs, &req );
     
    14691440            int i;
    14701441            struct peer_request r;
     1442            const uint64_t now_msec = tr_date( );
    14711443            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.index );
    14721444            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset );
    14731445            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length );
     1446            tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 );
     1447            tr_historyAdd( msgs->peer->cancelsSentToClient, now_msec, 1 );
    14741448            dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length );
    14751449
     
    19531927            else
    19541928            {
     1929                const uint64_t now_msec = tr_date( );
    19551930                dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length );
    19561931                EVBUFFER_LENGTH(out) += req.length;
     
    19591934                bytesWritten += EVBUFFER_LENGTH( out );
    19601935                msgs->clientSentAnythingAt = now;
     1936                tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 );
     1937                tr_historyAdd( msgs->peer->blocksSentToPeer, now_msec, 1 );
    19611938            }
    19621939
Note: See TracChangeset for help on using the changeset viewer.