Changeset 12030


Ignore:
Timestamp:
Feb 24, 2011, 3:33:50 PM (11 years ago)
Author:
jordan
Message:

(2.2x) backport 12022 for #4035 "In seed state, transmission disconnect from leechers"

Location:
branches/2.2x/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2x/libtransmission/peer-common.h

    r11709 r12030  
    6666    TR_PEER_CLIENT_GOT_REJ,
    6767    TR_PEER_PEER_GOT_DATA,
    68     TR_PEER_PEER_PROGRESS,
    6968    TR_PEER_ERROR
    7069}
     
    7776    uint32_t         offset;       /* for GOT_BLOCK */
    7877    uint32_t         length;       /* for GOT_BLOCK + GOT_DATA */
    79     float            progress;     /* for PEER_PROGRESS */
    8078    int              err;          /* errno for GOT_ERROR */
    8179    tr_bool          wasPieceData; /* for GOT_DATA */
     
    9088                               void                 * client_data );
    9189
     90/** Update the tr_peer.progress field based on the 'have' bitset. */
     91void tr_peerUpdateProgress( tr_torrent * tor, struct tr_peer * );
     92
    9293#ifdef WIN32
    9394 #define EMSGSIZE WSAEMSGSIZE
  • branches/2.2x/libtransmission/peer-mgr.c

    r12028 r12030  
    604604}
    605605
    606 static void
    607 atomSetSeed( struct peer_atom * atom )
    608 {
    609     atomSetSeedProbability( atom, 100 );
    610 }
    611 
    612606static inline tr_bool
    613607atomIsSeed( const struct peer_atom * atom )
     
    615609    return atom->seedProbability == 100;
    616610}
     611
     612static void
     613atomSetSeed( Torrent * t, struct peer_atom * atom )
     614{
     615    if( !atomIsSeed( atom ) )
     616    {
     617        tordbg( t, "marking peer %s as a seed", tr_atomAddrStr( atom ) );
     618
     619        atomSetSeedProbability( atom, 100 );
     620    }
     621}
     622
    617623
    618624tr_bool
     
    14141420        }
    14151421
    1416         case TR_PEER_PEER_PROGRESS:
    1417         {
    1418             if( peer )
    1419             {
    1420                 struct peer_atom * atom = peer->atom;
    1421                 if( e->progress >= 1.0 ) {
    1422                     tordbg( t, "marking peer %s as a seed", tr_atomAddrStr( atom ) );
    1423                     atomSetSeed( atom );
    1424                 }
    1425             }
    1426             break;
    1427         }
    1428 
    14291422        case TR_PEER_CLIENT_GOT_BLOCK:
    14301423        {
     
    15861579        if( from < a->fromBest )
    15871580            a->fromBest = from;
    1588        
     1581
    15891582        if( a->seedProbability == -1 )
    15901583            atomSetSeedProbability( a, seedProbability );
     
    17951788
    17961789    while( it != end )
    1797         atomSetSeed( *it++ );
     1790        atomSetSeed( t, *it++ );
    17981791}
    17991792
     
    21222115    stopTorrent( tor->torrentPeers );
    21232116    torrentDestructor( tor->torrentPeers );
     2117}
     2118
     2119void
     2120tr_peerUpdateProgress( tr_torrent * tor, tr_peer * peer )
     2121{
     2122    const tr_bitset * have = &peer->have;
     2123
     2124    if( have->haveAll )
     2125    {
     2126        peer->progress = 1.0;
     2127    }
     2128    else if( have->haveNone )
     2129    {
     2130        peer->progress = 0.0;
     2131    }
     2132    else
     2133    {
     2134        const float trueCount = tr_bitfieldCountTrueBits( &have->bitfield );
     2135
     2136        if( tr_torrentHasMetadata( tor ) )
     2137            peer->progress = trueCount / tor->info.pieceCount;
     2138        else /* without pieceCount, this result is only a best guess... */
     2139            peer->progress = trueCount / ( have->bitfield.bitCount + 1 );
     2140    }
     2141
     2142    if( peer->progress >= 1.0 )
     2143        atomSetSeed( tor->torrentPeers, peer->atom );
     2144}
     2145
     2146void
     2147tr_peerMgrOnTorrentGotMetainfo( tr_torrent * tor )
     2148{
     2149    int i;
     2150    const int peerCount = tr_ptrArraySize( &tor->torrentPeers->peers );
     2151    tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &tor->torrentPeers->peers );
     2152
     2153    /* some peer_msgs' progress fields may not be accurate if we
     2154       didn't have the metadata before now... so refresh them all... */
     2155    for( i=0; i<peerCount; ++i )
     2156        tr_peerUpdateProgress( tor, peers[i] );
    21242157}
    21252158
  • branches/2.2x/libtransmission/peer-mgr.h

    r11709 r12030  
    223223struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
    224224
     225void tr_peerMgrOnTorrentGotMetainfo( tr_torrent * tor );
     226
    225227void tr_peerMgrOnBlocklistChanged( tr_peerMgr * manager );
    226228
  • branches/2.2x/libtransmission/peer-msgs.c

    r11800 r12030  
    452452**/
    453453
    454 static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
     454static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0, 0, 0 };
    455455
    456456static void
     
    470470    e.eventType = TR_PEER_ERROR;
    471471    e.err = err;
    472     publish( msgs, &e );
    473 }
    474 
    475 static void
    476 firePeerProgress( tr_peermsgs * msgs )
    477 {
    478     tr_peer_event e = blankEvent;
    479     e.eventType = TR_PEER_PEER_PROGRESS;
    480     e.progress = msgs->peer->progress;
    481472    publish( msgs, &e );
    482473}
     
    11851176updatePeerProgress( tr_peermsgs * msgs )
    11861177{
    1187     msgs->peer->progress = tr_bitsetPercent( &msgs->peer->have );
    1188     dbgmsg( msgs, "peer progress is %f", msgs->peer->progress );
     1178    tr_peerUpdateProgress( msgs->torrent, msgs->peer );
     1179
    11891180    updateFastSet( msgs );
    11901181    updateInterest( msgs );
    1191     firePeerProgress( msgs );
    11921182}
    11931183
  • branches/2.2x/libtransmission/torrent.c

    r11844 r12030  
    745745    torrentInitFromInfo( tor );
    746746
     747    tr_peerMgrOnTorrentGotMetainfo( tor );
     748
    747749    tr_torrentFireMetadataCompleted( tor );
    748750}
  • branches/2.2x/libtransmission/webseed.c

    r11820 r12030  
    7878***/
    7979
    80 static const tr_peer_event blank_event = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
     80static const tr_peer_event blank_event = { 0, 0, 0, 0, 0, 0, 0 };
    8181
    8282static void
Note: See TracChangeset for help on using the changeset viewer.