Changeset 7064


Ignore:
Timestamp:
Nov 7, 2008, 4:10:27 AM (10 years ago)
Author:
charles
Message:

#1429 (libT) cleaner handling of the special case where the upload or download speed limit is zero

Location:
trunk/libtransmission
Files:
4 edited

Legend:

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

    r7060 r7064  
    18921892    tr_peer **         peers = getConnectedPeers( t, &peerCount );
    18931893    struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
     1894    const int          chokeAll = !tr_torrentPieceTransferIsAllowed( t->tor, TR_CLIENT_TO_PEER );
    18941895
    18951896    assert( torrentIsLocked( t ) );
     
    19011902        if( peer->progress >= 1.0 ) /* choke all seeds */
    19021903            tr_peerMsgsSetChoke( peer->msgs, TRUE );
    1903         else
    1904         {
     1904        else if( chokeAll )
     1905            tr_peerMsgsSetChoke( peer->msgs, TRUE );
     1906        else {
    19051907            struct ChokeData * n = &choke[size++];
    19061908            n->peer         = peer;
     
    25042506    for( i = 0; i < torrentCount; ++i )
    25052507    {
    2506         Torrent *    t = torrents[i];
     2508        Torrent * t = torrents[i];
    25072509        const size_t used = countPeerBandwidth( t->peers, direction );
     2510        tr_speedlimit speedMode;
     2511
    25082512        countHandshakeBandwidth( t->outgoingHandshakes, direction );
    25092513
     
    25142518        allBytesUsed += used;
    25152519
     2520        /* if piece data is disallowed, don't bother limiting bandwidth --
     2521         * we won't be asking for, or sending out, any pieces */
     2522        if( !tr_torrentPieceTransferIsAllowed( t->tor, direction ) )
     2523            speedMode = TR_SPEEDLIMIT_UNLIMITED;
     2524        else
     2525            speedMode = tr_torrentGetSpeedMode( t->tor, direction );
     2526           
    25162527        /* process the torrent's peers based on its speed mode */
    2517         switch( tr_torrentGetSpeedMode( t->tor, direction ) )
     2528        switch( speedMode )
    25182529        {
    25192530            case TR_SPEEDLIMIT_UNLIMITED:
  • trunk/libtransmission/peer-msgs.c

    r7055 r7064  
    543543        return FALSE;
    544544
     545    if( !tr_torrentPieceTransferIsAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )
     546        return FALSE;
     547
    545548    torrent = msgs->torrent;
    546549    bitfield = tr_cpPieceBitfield( torrent->completion );
     
    810813        return;
    811814    if( msgs->info->clientIsChoked )
     815        return;
     816    if( !tr_torrentPieceTransferIsAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )
    812817        return;
    813818
  • trunk/libtransmission/torrent.c

    r7056 r7064  
    147147{
    148148    tr_speedlimit * limit = direction == TR_UP ? &tor->uploadLimitMode
    149                             : &tor->downloadLimitMode;
     149                                               : &tor->downloadLimitMode;
    150150
    151151    *limit = mode;
     
    157157{
    158158    return direction == TR_UP ? tor->uploadLimitMode
    159            : tor->downloadLimitMode;
     159                              : tor->downloadLimitMode;
    160160}
    161161
     
    193193            assert( 0 );
    194194    }
     195}
     196
     197int
     198tr_torrentPieceTransferIsAllowed( const tr_torrent  * tor,
     199                                  tr_direction        direction )
     200{
     201    int isEnabled = FALSE;
     202
     203    switch( tr_torrentGetSpeedMode( tor, direction ) )
     204    {
     205        case TR_SPEEDLIMIT_GLOBAL:
     206            isEnabled = tr_sessionGetSpeedLimit( tor->session, direction ) > 0;
     207            break;
     208
     209        case TR_SPEEDLIMIT_SINGLE:
     210            isEnabled = tr_torrentGetSpeedLimit( tor, direction ) > 0;
     211            break;
     212
     213        case TR_SPEEDLIMIT_UNLIMITED:
     214            isEnabled = TRUE;
     215            break;
     216
     217        default:
     218            assert( 0 && "unhandled speed mode" );
     219            break;
     220    }
     221
     222    return isEnabled;
    195223}
    196224
  • trunk/libtransmission/torrent.h

    r7055 r7064  
    8282int         tr_torrentAllowsPex( const tr_torrent * );
    8383
     84int         tr_torrentPieceTransferIsAllowed( const tr_torrent * torrent,
     85                                              tr_direction       direction );
     86
    8487/* get the index of this piece's first block */
    8588#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
Note: See TracChangeset for help on using the changeset viewer.