Changeset 5001


Ignore:
Timestamp:
Feb 10, 2008, 4:03:19 AM (14 years ago)
Author:
charles
Message:

#698: have' gets too far ahead of verified'

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r4840 r5001  
    260260}
    261261
     262int
     263tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece )
     264{
     265    assert( cp != NULL );
     266
     267    return tr_torPieceCountBlocks(cp->tor,piece) - cp->completeBlocks[piece];
     268}
     269
    262270/***
    263271****
  • trunk/libtransmission/completion.h

    r4404 r5001  
    5555void             tr_cpBlockBitfieldSet( tr_completion *, struct tr_bitfield * );
    5656float            tr_cpPercentBlocksInPiece( const tr_completion * cp, int piece );
     57int              tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece );
     58
    5759
    5860const struct tr_bitfield * tr_cpPieceBitfield( const tr_completion* );
  • trunk/libtransmission/peer-mgr.c

    r4856 r5001  
    548548}
    549549
     550static int
     551clientIsDownloadingFrom( const tr_peer * peer )
     552{
     553    return peer->clientIsInterested && !peer->clientIsChoked;
     554}
     555
     556static int
     557clientIsUploadingTo( const tr_peer * peer )
     558{
     559    return peer->peerIsInterested && !peer->peerIsChoked;
     560}
     561
    550562/***
    551563****  Refill
     
    555567{
    556568    tr_priority_t priority;
    557     int percentDone;
     569    int missingBlockCount;
    558570    uint16_t random;
    559571    uint32_t piece;
     
    568580    const struct tr_refill_piece * a = aIn;
    569581    const struct tr_refill_piece * b = bIn;
     582
     583    /* fewer missing pieces goes first */
     584    if( a->missingBlockCount != b->missingBlockCount )
     585        return a->missingBlockCount < b->missingBlockCount ? -1 : 1;
    570586   
    571587    /* if one piece has a higher priority, it goes first */
    572588    if( a->priority != b->priority )
    573589        return a->priority > b->priority ? -1 : 1;
    574 
    575     /* try to fill partial pieces */
    576     if( a->percentDone != b->percentDone )
    577         return a->percentDone > b->percentDone ? -1 : 1;
    578590   
    579591    /* if one *might be* fastallowed to us, get it first...
     
    646658            setme->fastAllowed = 0;
    647659            setme->random = tr_rand( UINT16_MAX );
    648             setme->percentDone = (int)( 100.0 * tr_cpPercentBlocksInPiece( tor->completion, piece ) );
     660            setme->missingBlockCount = tr_cpMissingBlocksInPiece( tor->completion, piece );
    649661
    650662            for( k=0; k<peerCount; ++k ) {
     
    762774}
    763775
     776static tr_peer**
     777getPeersUploadingToClient( Torrent * t, int * setmeCount )
     778{
     779    int i;
     780    int peerCount = 0;
     781    int retCount = 0;
     782    tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
     783    tr_peer ** ret = tr_new( tr_peer*, peerCount );
     784
     785    /* get a list of peers we're downloading from */
     786    for( i=0; i<peerCount; ++i )
     787        if( clientIsDownloadingFrom( peers[i] ) )
     788            ret[retCount++] = peers[i];
     789
     790    /* pick a different starting point each time so all peers
     791     * get a chance at the first blocks in the queue */
     792    if( retCount ) {
     793        tr_peer ** tmp = tr_new( tr_peer*, retCount );
     794        i = tr_rand( retCount );
     795        memcpy( tmp, ret, sizeof(tr_peer*) * retCount );
     796        memcpy( ret, tmp+i, sizeof(tr_peer*) * (retCount-i) );
     797        memcpy( ret+(retCount-i), tmp, sizeof(tr_peer*) * i );
     798        tr_free( tmp );
     799    }
     800
     801    *setmeCount = retCount;
     802    return ret;
     803}
     804
    764805static int
    765806refillPulse( void * vtorrent )
     
    782823
    783824    blocks = getPreferredBlocks( t, &blockCount );
    784     peers = getConnectedPeers( t, &peerCount );
     825    peers = getPeersUploadingToClient( t, &peerCount );
    785826
    786827    for( i=0; peerCount && i<blockCount; ++i )
    787828    {
     829        int j;
     830
    788831        const uint64_t block = blocks[i];
    789832        const uint32_t index = tr_torBlockPiece( tor, block );
    790833        const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize);
    791834        const uint32_t length = tr_torBlockCountBytes( tor, (int)block );
    792         int j;
     835
    793836        assert( _tr_block( tor, index, begin ) == (int)block );
    794837        assert( begin < (uint32_t)tr_torPieceCountBytes( tor, (int)index ) );
     
    14061449    managerUnlock( (tr_peerMgr*)manager );
    14071450    return ret;
    1408 }
    1409 
    1410 static int
    1411 clientIsDownloadingFrom( const tr_peer * peer )
    1412 {
    1413     return peer->clientIsInterested && !peer->clientIsChoked;
    1414 }
    1415 
    1416 static int
    1417 clientIsUploadingTo( const tr_peer * peer )
    1418 {
    1419     return peer->peerIsInterested && !peer->peerIsChoked;
    14201451}
    14211452
  • trunk/libtransmission/peer-msgs.c

    r4839 r5001  
    7777    MAX_FAST_ALLOWED_THRESHOLD = 10,        /* max threshold for allowing fast-pieces requests */
    7878
    79     REQUEST_TTL_SECS = 120
     79    QUEUED_REQUEST_TTL_SECS = 20,
     80
     81    SENT_REQUEST_TTL_SECS = 90
    8082
    8183};
     
    590592    for( l=msgs->clientWillAskFor; l!=NULL; l=l->next ) {
    591593        struct peer_request * req = l->data;
    592         if( req->time_requested + REQUEST_TTL_SECS < now )
     594        if( req->time_requested + QUEUED_REQUEST_TTL_SECS < now )
    593595            tr_list_prepend( &prune, req );
    594596    }
     
    598600    for( l=msgs->clientAskedFor; l!=NULL; l=l->next ) {
    599601        struct peer_request * req = l->data;
    600         if( req->time_requested + REQUEST_TTL_SECS < now )
     602        if( req->time_requested + SENT_REQUEST_TTL_SECS < now )
    601603            tr_list_prepend( &prune, req );
    602604    }
     
    15511553    msgs->info->rateToClient = tr_rcRate( msgs->info->rcToClient );
    15521554    msgs->info->rateToPeer = tr_rcRate( msgs->info->rcToPeer );
    1553     msgs->maxActiveRequests = MIN( 8 + (int)(msgs->info->rateToClient/5), 100 );
     1555    msgs->maxActiveRequests = MIN( 4 + (int)(msgs->info->rateToClient/4), 100 );
    15541556    msgs->minActiveRequests = msgs->maxActiveRequests / 3;
    15551557    return TRUE;
Note: See TracChangeset for help on using the changeset viewer.