Changeset 7238


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

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

Location:
trunk/libtransmission
Files:
9 edited

Legend:

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

    r7234 r7238  
    4949    TR_PEER_ERROR,
    5050    TR_PEER_CANCEL,
     51    TR_PEER_UPLOAD_ONLY,
    5152    TR_PEER_NEED_REQ
    5253}
     
    6263    int              err;          /* errno for GOT_ERROR */
    6364    int              wasPieceData; /* for GOT_DATA */
     65    tr_bool          uploadOnly;   /* for UPLOAD_ONLY */
    6466}
    6567tr_peer_event;
  • 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
  • trunk/libtransmission/peer-msgs.c

    r7237 r7238  
    514514**/
    515515
    516 static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0 };
     516static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
    517517
    518518static void
     
    538538
    539539static void
     540fireUploadOnly( tr_peermsgs * msgs, tr_bool uploadOnly )
     541{
     542    tr_peer_event e = blankEvent;
     543    e.eventType = TR_PEER_UPLOAD_ONLY;
     544    e.uploadOnly = uploadOnly;
     545    publish( msgs, &e );
     546}
     547
     548static void
    540549fireNeedReq( tr_peermsgs * msgs )
    541550{
    542551    tr_peer_event e = blankEvent;
    543 
    544552    e.eventType = TR_PEER_NEED_REQ;
    545553    publish( msgs, &e );
     
    10871095
    10881096    tr_bencInitDict( &val, 4 );
    1089     tr_bencDictAddInt( &val, "e",
    1090                        msgs->session->encryptionMode != TR_CLEAR_PREFERRED );
     1097    tr_bencDictAddInt( &val, "e", msgs->session->encryptionMode != TR_CLEAR_PREFERRED );
    10911098    tr_bencDictAddInt( &val, "p", tr_sessionGetPeerPort( msgs->session ) );
     1099    tr_bencDictAddInt( &val, "upload_only", tr_torrentIsSeed( msgs->torrent ) );
    10921100    tr_bencDictAddStr( &val, "v", TR_NAME " " USERAGENT_PREFIX );
    10931101    m  = tr_bencDictAddDict( &val, "m", 1 );
     
    11451153        }
    11461154    }
     1155
     1156    /* look for upload_only (BEP 21) */
     1157    if( tr_bencDictFindInt( &val, "upload_only", &i ) )
     1158        fireUploadOnly( msgs, i!=0 );
    11471159
    11481160    /* get peer's listening port */
  • trunk/libtransmission/rpcimpl.c

    r7132 r7238  
    292292    else if( !strcmp( key, "downloadedEver" ) )
    293293        tr_bencDictAddInt( d, key, st->downloadedEver );
     294    else if( !strcmp( key, "downloaders" ) )
     295        tr_bencDictAddInt( d, key, st->downloaders );
    294296    else if( !strcmp( key, "downloadLimitMode" ) )
    295297        tr_bencDictAddInt( d, key, tr_torrentGetSpeedMode( tor, TR_DOWN ) );
  • trunk/libtransmission/torrent.c

    r7235 r7238  
    784784    s->scrapeURL   = ti ? ti->scrape   : NULL;
    785785    tr_trackerStat( tc, s );
     786
    786787    tr_trackerGetCounts( tc, &s->timesCompleted,
    787                          &s->leechers,
    788                          &s->seeders );
     788                             &s->leechers,
     789                             &s->seeders,
     790                             &s->downloaders );
     791
    789792    tr_peerMgrTorrentStats( tor->session->peerMgr,
    790793                            tor->info.hash,
  • trunk/libtransmission/tracker.c

    r7235 r7238  
    109109    int       timesDownloaded;
    110110    int       seederCount;
     111    int       downloaderCount;
    111112    int       leecherCount;
    112113    char *    trackerID;
     
    539540                  const void * response,
    540541                  size_t       responseLen,
    541                   void *      torrent_hash )
     542                  void       * torrent_hash )
    542543{
    543544    int          success = FALSE;
     
    584585                    t->timesDownloaded = itmp;
    585586
     587                if( ( tr_bencDictFindInt( tordict, "downloaders", &itmp ) ) )
     588                    t->downloaderCount = itmp;
     589
    586590                if( tr_bencDictFindDict( tordict, "flags", &flags ) )
    587                     if( ( tr_bencDictFindInt( flags, "min_request_interval",
    588                                               &itmp ) ) )
     591                    if( ( tr_bencDictFindInt( flags, "min_request_interval", &itmp ) ) )
    589592                        t->scrapeIntervalSec = i;
    590593
     
    652655    TR_REQ_COMPLETED,
    653656    TR_REQ_STOPPED,
     657    TR_REQ_PAUSED,     /* BEP 21 */
    654658    TR_REQ_REANNOUNCE,
    655     TR_REQ_SCRAPE,
    656     TR_REQ_COUNT
     659    TR_REQ_SCRAPE
    657660};
    658661
     
    713716
    714717static struct tr_tracker_request*
    715 createRequest(                 tr_session * session,
    716                                tr_tracker * tracker,
    717                            int reqtype )
    718 {
    719     static const char*          strings[] =
    720     { "started", "completed", "stopped", "", "err" };
    721     const tr_torrent *          torrent = tr_torrentFindFromHash(
    722         session, tracker->hash );
    723     const tr_tracker_info *     address = getCurrentAddressFromTorrent(
    724         tracker, torrent );
    725     const int                   isStopping = reqtype == TR_REQ_STOPPED;
     718createRequest( tr_session * session,
     719               tr_tracker * tracker,
     720               int          reqtype )
     721{
     722    static const char* strings[] = { "started", "completed", "stopped", "paused", "", "err" };
     723    const tr_torrent * torrent = tr_torrentFindFromHash( session, tracker->hash );
     724    const tr_tracker_info * address = getCurrentAddressFromTorrent( tracker, torrent );
     725    int isStopping;
    726726    struct tr_tracker_request * req;
    727     struct evbuffer *           url;
     727    struct evbuffer * url;
     728
     729    /* BEP 21: In order to tell the tracker that a peer is a partial seed, it MUST send
     730     * an event=paused parameter in every announce while it is a partial seed. */
     731    if( tr_cpGetStatus( torrent->completion ) == TR_PARTIAL_SEED )
     732        reqtype = TR_REQ_PAUSED;
     733
     734    isStopping = reqtype == TR_REQ_STOPPED;
    728735
    729736    url = evbuffer_new( );
     
    981988    t->timesDownloaded          = -1;
    982989    t->seederCount              = -1;
     990    t->downloaderCount          = -1;
    983991    t->leecherCount             = -1;
    984992    t->lastAnnounceResponse     = -1;
     
    10611069void
    10621070tr_trackerGetCounts( const tr_tracker * t,
    1063                      int *              setme_completedCount,
    1064                      int *              setme_leecherCount,
    1065                      int *              setme_seederCount )
     1071                     int              * setme_completedCount,
     1072                     int              * setme_leecherCount,
     1073                     int              * setme_seederCount,
     1074                     int              * setme_downloaderCount )
    10661075{
    10671076    if( setme_completedCount )
     
    10731082    if( setme_seederCount )
    10741083        *setme_seederCount = t->seederCount;
     1084
     1085    if( setme_downloaderCount )
     1086        *setme_downloaderCount = t->downloaderCount;
    10751087}
    10761088
  • trunk/libtransmission/tracker.h

    r7235 r7238  
    9898                                             int * setme_completedCount,
    9999                                             int * setme_leecherCount,
    100                                              int * setme_seederCount );
     100                                             int * setme_seederCount,
     101                                             int * setme_downloaderCount );
    101102
    102103#endif
  • trunk/libtransmission/transmission.h

    r7231 r7238  
    13241324    int    leechers;
    13251325
     1326    /** Number of downloaders that the tracker says this torrent has.
     1327        This is a new key introduced in BEP 21 and may not be supported by some trackers.
     1328        If the tracker doesn't support this key, the value here will be -1. */
     1329    int    downloaders;
     1330
    13261331    /** Number of finished downloads that the tracker says torrent has */
    13271332    int    timesCompleted;
  • trunk/libtransmission/webseed.c

    r7173 r7238  
    5252***/
    5353
    54 static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0 };
     54static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
    5555
    5656static void
Note: See TracChangeset for help on using the changeset viewer.