Changeset 2234


Ignore:
Timestamp:
Jun 29, 2007, 5:24:14 PM (15 years ago)
Author:
charles
Message:

fix some ugliness from last night's hackfest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer.c

    r2233 r2234  
    851851tr_torrentSwiftPulse ( tr_torrent_t * tor )
    852852{
     853    /* Preferred # of seconds for the request queue's turnaround time.
     854       This is just an arbitrary number. */
     855    const int queueTimeSec = 5;
     856    const int blockSizeKiB = tor->blockSize / 1024;
     857    int deadbeatCount = 0;
    853858    int i;
    854     int deadbeatCount = 0;
    855859    tr_peer_t ** deadbeats;
    856860
     
    859863    for( i=0; i<tor->peerCount; ++i )
    860864    {
    861         /* preferred # of seconds for the request queue's turnaround time.
    862            this is just an arbitrary number. */
    863         const int queueTime = 5;
    864         int j;
     865        double outboundSpeedKiBs;
     866        double inboundSpeedKiBs;
     867        int j, size;
    865868        tr_peer_t * peer = tor->peers[ i ];
    866869
     
    868871            continue;
    869872
    870         /* decide how deep the request queue should be */
    871         peer->outRequestMax = queueTime * tr_rcRate(peer->download) / tor->blockSize;
    872         peer->inRequestMax += 2; /* room to grow */
    873 
    874         /* make room for new requests */
     873        /* decide how many blocks we'll concurrently ask this peer for */
     874        outboundSpeedKiBs = tr_rcRate(peer->upload);
     875        size = queueTimeSec * outboundSpeedKiBs / blockSizeKiB;
     876        if( size < 4 ) /* don't let it get TOO small */
     877            size = 4;
     878        size += 4; /* and always leave room to grow */
     879        peer->inRequestMax = size;
     880        if( peer->inRequestAlloc < peer->inRequestMax ) {
     881            peer->inRequestAlloc = peer->inRequestMax;
     882            peer->inRequests = tr_renew( tr_request_t, peer->inRequests, peer->inRequestAlloc );
     883        }
     884
     885        /* decide how many blocks we'll concurrently let the peer ask us for */
     886        inboundSpeedKiBs = tr_rcRate(peer->download);
     887        size = queueTimeSec * inboundSpeedKiBs / blockSizeKiB;
     888        if( size < 4 ) /* don't let it get TOO small */
     889            size = 4;
     890        size += 4; /* and always leave room to grow */
     891        peer->outRequestMax = size;
    875892        if( peer->outRequestAlloc < peer->outRequestMax ) {
    876893            peer->outRequestAlloc = peer->outRequestMax;
    877894            peer->outRequests = tr_renew( tr_request_t, peer->outRequests, peer->outRequestAlloc );
    878895        }
    879 
    880         /* decide how deep the request queue should be */
    881         peer->inRequestMax = queueTime * tr_rcRate(peer->download) / (tor->blockSize/1024);
    882         peer->inRequestMax += 2; /* room to grow */
    883 
    884         /* make room for new requests */
    885         if( peer->inRequestAlloc < peer->inRequestMax ) {
    886             peer->inRequestAlloc = peer->inRequestMax;
    887             peer->inRequests = tr_renew( tr_request_t, peer->inRequests, peer->inRequestAlloc );
    888         }
    889 
    890         /* queue shrank... notify completion that we won't be sending those requests */
    891         for( j=peer->inRequestMax; j<peer->inRequestCount; ++j ) {
    892             tr_request_t * r = &peer->inRequests[j];
    893             tr_cpDownloaderRem( tor->completion, tr_block(r->index,r->begin) );
    894         }
    895     }
    896 
    897     deadbeats = tr_calloc( tor->peerCount, sizeof(tr_peer_t*) );
     896    }
     897
     898    deadbeats = g_new( tr_peer_t*, tor->peerCount );
     899    deadbeatCount = 0;
    898900    for( i=0; i<tor->peerCount; ++i ) {
    899901        tr_peer_t * peer = tor->peers[ i ];
     
    919921    }
    920922
    921     free( deadbeats );
     923    tr_free( deadbeats );
    922924
    923925    tr_torrentWriterUnlock( tor );
Note: See TracChangeset for help on using the changeset viewer.