Changeset 12022


Ignore:
Timestamp:
Feb 24, 2011, 2:35:45 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) #4035 "In seed state, transmission disconnect from leechers" -- fixed.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-common.h

    r12002 r12022  
    6262    TR_PEER_CLIENT_GOT_HAVE_NONE,
    6363    TR_PEER_PEER_GOT_DATA,
    64     TR_PEER_PEER_PROGRESS,
    6564    TR_PEER_ERROR
    6665}
     
    7574    uint32_t              offset;       /* for GOT_BLOCK */
    7675    uint32_t              length;       /* for GOT_BLOCK + GOT_DATA */
    77     float                 progress;     /* for PEER_PROGRESS */
    7876    int                   err;          /* errno for GOT_ERROR */
    7977    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
     93
    9294#ifdef WIN32
    9395 #define EMSGSIZE WSAEMSGSIZE
  • trunk/libtransmission/peer-mgr.c

    r12019 r12022  
    100100};
    101101
    102 const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0.0f, 0, FALSE, 0 };
     102const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, FALSE, 0 };
    103103
    104104/**
     
    646646}
    647647
    648 static void
    649 atomSetSeed( struct peer_atom * atom )
    650 {
    651     atomSetSeedProbability( atom, 100 );
    652 }
    653 
    654648static inline tr_bool
    655649atomIsSeed( const struct peer_atom * atom )
     
    657651    return atom->seedProbability == 100;
    658652}
     653
     654static void
     655atomSetSeed( const Torrent * t, struct peer_atom * atom )
     656{
     657    if( !atomIsSeed( atom ) )
     658    {
     659        tordbg( t, "marking peer %s as a seed", tr_atomAddrStr( atom ) );
     660
     661        atomSetSeedProbability( atom, 100 );
     662    }
     663}
     664
    659665
    660666tr_bool
     
    17001706        }
    17011707
    1702         case TR_PEER_PEER_PROGRESS:
    1703         {
    1704             if( peer )
    1705             {
    1706                 struct peer_atom * atom = peer->atom;
    1707                 if( e->progress >= 1.0 ) {
    1708                     tordbg( t, "marking peer %s as a seed", tr_atomAddrStr( atom ) );
    1709                     atomSetSeed( atom );
    1710                 }
    1711             }
    1712             break;
    1713         }
    1714 
    17151708        case TR_PEER_CLIENT_GOT_BLOCK:
    17161709        {
     
    21102103
    21112104    while( it != end )
    2112         atomSetSeed( *it++ );
     2105        atomSetSeed( t, *it++ );
    21132106}
    21142107
     
    24412434    stopTorrent( tor->torrentPeers );
    24422435    torrentFree( tor->torrentPeers );
     2436}
     2437
     2438void
     2439tr_peerUpdateProgress( tr_torrent * tor, tr_peer * peer )
     2440{
     2441    const tr_bitset * have = &peer->have; 
     2442
     2443    if( have->haveAll )
     2444    {
     2445        peer->progress = 1.0;
     2446    }
     2447    else if( have->haveNone )
     2448    {
     2449        peer->progress = 0.0;
     2450    }
     2451    else
     2452    {
     2453        const float trueCount = tr_bitfieldCountTrueBits( &have->bitfield );
     2454
     2455        if( tr_torrentHasMetadata( tor ) )
     2456            peer->progress = trueCount / tor->info.pieceCount;
     2457        else /* without pieceCount, this result is only a best guess... */
     2458            peer->progress = trueCount / ( have->bitfield.bitCount + 1 );
     2459    }
     2460
     2461    if( peer->progress >= 1.0 )
     2462        atomSetSeed( tor->torrentPeers, peer->atom );
     2463}
     2464
     2465void
     2466tr_peerMgrOnTorrentGotMetainfo( tr_torrent * tor )
     2467{
     2468    int i;
     2469    const int peerCount = tr_ptrArraySize( &tor->torrentPeers->peers );
     2470    tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &tor->torrentPeers->peers );
     2471 
     2472    /* some peer_msgs' progress fields may not be accurate if we
     2473       didn't have the metadata before now... so refresh them all... */
     2474    for( i=0; i<peerCount; ++i )
     2475        tr_peerUpdateProgress( tor, peers[i] );
    24432476}
    24442477
  • trunk/libtransmission/peer-mgr.h

    r12013 r12022  
    232232struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
    233233
     234void tr_peerMgrOnTorrentGotMetainfo( tr_torrent * tor );
     235
    234236void tr_peerMgrOnBlocklistChanged( tr_peerMgr * manager );
    235237
  • trunk/libtransmission/peer-msgs.c

    r12013 r12022  
    457457
    458458static void
    459 firePeerProgress( tr_peermsgs * msgs )
    460 {
    461     tr_peer_event e = TR_PEER_EVENT_INIT;
    462     e.eventType = TR_PEER_PEER_PROGRESS;
    463     e.progress = msgs->peer->progress;
    464     publish( msgs, &e );
    465 }
    466 
    467 static void
    468459fireGotBlock( tr_peermsgs * msgs, const struct peer_request * req )
    469460{
     
    12091200updatePeerProgress( tr_peermsgs * msgs )
    12101201{
    1211     msgs->peer->progress = tr_bitsetPercent( &msgs->peer->have );
    1212     dbgmsg( msgs, "peer progress is %f", msgs->peer->progress );
     1202    tr_peerUpdateProgress( msgs->torrent, msgs->peer );
     1203
    12131204    updateFastSet( msgs );
    12141205    updateInterest( msgs );
    1215     firePeerProgress( msgs );
    12161206}
    12171207
  • trunk/libtransmission/torrent.c

    r12012 r12022  
    753753    torrentInitFromInfo( tor );
    754754
     755    tr_peerMgrOnTorrentGotMetainfo( tor );
     756
    755757    tr_torrentFireMetadataCompleted( tor );
    756758}
Note: See TracChangeset for help on using the changeset viewer.