Changeset 3959


Ignore:
Timestamp:
Nov 25, 2007, 5:06:37 PM (15 years ago)
Author:
charles
Message:

fix clientIsSnubbedBy() to work correctly when we're a seed. fix peer-mgr.c shear between trunk and 0.9x

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.9x/libtransmission/peer-mgr.c

    r3954 r3959  
    1212
    1313#include <assert.h>
    14 #include <string.h> /* memcpy, memcmp */
     14#include <string.h> /* memcpy, memcmp, strstr */
    1515#include <stdlib.h> /* qsort */
    1616#include <stdio.h> /* printf */
     
    9898    /* how many peers to unchoke per-torrent. */
    9999    /* FIXME: make this user-configurable? */
    100     NUM_UNCHOKED_PEERS_PER_TORRENT = 20, /* arbitrary */
     100    NUM_UNCHOKED_PEERS_PER_TORRENT = 10, /* arbitrary */
    101101
    102102    /* set this too high and there will be a lot of churn.
     
    14831483    tr_peer * peer;
    14841484    int rate;
    1485     int preferred;
    1486     int doUnchoke;
     1485    uint8_t preferred;
     1486    uint8_t preferred_t;
     1487    uint8_t doUnchoke;
    14871488};
    14881489
     
    14921493    const struct ChokeData * a = va;
    14931494    const struct ChokeData * b = vb;
    1494 
    1495     /* primary key: larger speeds */
    1496     if( a->rate > b->rate )
    1497         return -1;
    1498     if ( a->rate < b->rate )
    1499         return 1;
    1500 
    1501     /* secondary key: perferred peers */
    1502     if( a->preferred != b->preferred )
    1503         return a->preferred ? -1 : 1;
    1504 
     1495    if( a->rate > b->rate ) return -1;
     1496    if( a->rate < b->rate ) return 1;
     1497    if( a->preferred_t != b->preferred_t ) return a->preferred_t ? -1 : 1;
     1498    if( a->preferred   != b->preferred   ) return a->preferred   ? -1 : 1;
    15051499    return 0;
    15061500}
    15071501
    15081502static int
    1509 clientIsSnubbedBy( const tr_peer * peer )
     1503clientIsSnubbedBy( const tr_peer * peer, int clientIsSeed )
    15101504{
    15111505    assert( peer != NULL );
    15121506
    1513     return peer->peerSentPieceDataAt < (time(NULL) - SNUBBED_SEC);
     1507    return !clientIsSeed
     1508        && ( peer->peerSentPieceDataAt < (time(NULL) - SNUBBED_SEC ) );
    15141509}
    15151510
     
    15491544        node = &choke[size++];
    15501545        node->peer = peer;
    1551         node->preferred = peer->peerIsInterested && !clientIsSnubbedBy(peer);
     1546        node->preferred = peer->peerIsInterested && !clientIsSnubbedBy( peer, clientIsSeed );
     1547        node->preferred_t = node->preferred && peer->client && strstr( peer->client, "Transmission" );
    15521548        node->rate = getWeightedThroughput( peer, clientIsSeed );
    15531549    }
Note: See TracChangeset for help on using the changeset viewer.