Ignore:
Timestamp:
Dec 2, 2008, 7:46:51 PM (14 years ago)
Author:
charles
Message:

(libT) #1379: support "partial seeds" BEP 22

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r7236 r7238  
    9090**/
    9191
     92enum
     93{
     94    UPLOAD_ONLY_UKNOWN,
     95    UPLOAD_ONLY_YES,
     96    UPLOAD_ONLY_NO
     97};
     98
    9299/* We keep one of these for every peer we know about, whether
    93100 * it's connected or not, so the struct must be small.
     
    97104{
    98105    uint8_t     from;
    99     uint8_t     flags; /* these match the added_f flags */
    100     uint8_t     myflags; /* flags that aren't defined in added_f */
     106    uint8_t     flags;       /* these match the added_f flags */
     107    uint8_t     myflags;     /* flags that aren't defined in added_f */
     108    uint8_t     uploadOnly;  /* UPLOAD_ONLY_ */
     109    uint8_t     partialSeed;
    101110    tr_port     port;
    102111    uint16_t    numFails;
    103112    tr_address  addr;
    104     time_t      time; /* when the peer's connection status last changed */
     113    time_t      time;        /* when the peer's connection status last changed */
    105114    time_t      piece_data_time;
    106115};
     
    981990    switch( e->eventType )
    982991    {
     992        case TR_PEER_UPLOAD_ONLY:
     993            /* update our atom */
     994            if( peer ) {
     995                struct peer_atom * a = getExistingAtom( t, &peer->addr );
     996                a->uploadOnly = e->uploadOnly ? UPLOAD_ONLY_YES : UPLOAD_ONLY_NO;
     997            }
     998            break;
     999
    9831000        case TR_PEER_NEED_REQ:
    9841001            refillSoon( t );
     
    14591476        {
    14601477            const tr_peer * peer = peers[i];
     1478            const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1479
    14611480            walk->addr = peer->addr;
    14621481            walk->port = peer->port;
    14631482            walk->flags = 0;
    1464             if( peerPrefersCrypto( peer ) ) walk->flags |= ADDED_F_ENCRYPTION_FLAG;
    1465             if( peer->progress >= 1.0 ) walk->flags |= ADDED_F_SEED_FLAG;
     1483            if( peerPrefersCrypto( peer ) )
     1484                walk->flags |= ADDED_F_ENCRYPTION_FLAG;
     1485            if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ) )
     1486                walk->flags |= ADDED_F_SEED_FLAG;
    14661487        }
    14671488
     
    18851906    {
    18861907        tr_peer * peer = peers[i];
     1908        struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1909
    18871910        if( peer->progress >= 1.0 ) /* choke all seeds */
     1911        {
    18881912            tr_peerMsgsSetChoke( peer->msgs, TRUE );
    1889         else if( chokeAll )
     1913        }
     1914        else if( atom->uploadOnly == UPLOAD_ONLY_YES ) /* choke partial seeds */
     1915        {
    18901916            tr_peerMsgsSetChoke( peer->msgs, TRUE );
    1891         else {
     1917        }
     1918        else if( chokeAll ) /* choke everyone if we're not uploading */
     1919        {
     1920            tr_peerMsgsSetChoke( peer->msgs, TRUE );
     1921        }
     1922        else
     1923        {
    18921924            struct ChokeData * n = &choke[size++];
    18931925            n->peer         = peer;
     
    21762208
    21772209        /* no need to connect if we're both seeds... */
    2178         if( seed && ( atom->flags & ADDED_F_SEED_FLAG ) )
     2210        if( seed && ( ( atom->flags & ADDED_F_SEED_FLAG ) ||
     2211                      ( atom->uploadOnly == UPLOAD_ONLY_YES ) ) )
    21792212            continue;
    21802213
Note: See TracChangeset for help on using the changeset viewer.