Changeset 11209


Ignore:
Timestamp:
Sep 14, 2010, 6:23:48 AM (11 years ago)
Author:
Longinus00
Message:

switch trackerRemove and trackerReplace rpc calls to use tracker id instead of announce urls as identifiers

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r11205 r11209  
    12771277        tr_bool hasScraped;
    12781278        const char * host;
     1279        int64_t id;
    12791280        tr_bool isBackup;
    12801281        int64_t lastAnnouncePeerCount;
     
    13011302            tr_bencDictFindBool( t, "hasScraped", &hasScraped ) &&
    13021303            tr_bencDictFindStr ( t, "host", &host ) &&
     1304            tr_bencDictFindInt ( t, "id", &id ) &&
    13031305            tr_bencDictFindBool( t, "isBackup", &isBackup ) &&
    13041306            tr_bencDictFindInt ( t, "announceState", &announceState ) &&
     
    13241326
    13251327            printf( "\n" );
    1326             printf( "  Tracker #%d: %s\n", (int)(i+1), host );
     1328            printf( "  Tracker %d: %s\n", (int)(id), host );
    13271329            if( isBackup )
    13281330                printf( "  Backup on tier #%d\n", (int)tier );
     
    20362038                case 712:
    20372039                    {
    2038                         tr_benc * trackers = tr_bencDictAddDict( args, "trackerRemove", 1 );
    2039                         tr_bencDictAddInt( trackers, "id", atoi(optarg) );
     2040                        tr_benc * trackers = tr_bencDictAddList( args, "trackerRemove", 1 );
     2041                        tr_bencListAddInt( trackers, atoi(optarg) );
    20402042                        break;
    20412043                    }
  • trunk/extras/rpc-spec.txt

    r11194 r11209  
    106106   "seedRatioMode"       | number     which ratio to use.  See tr_ratiolimit
    107107   "trackerAdd"          | array      strings of announce URLs to add
    108    "trackerRemove"       | array      strings of announce URLs to remove
    109    "trackerReplace"      | array      pairs of old/new announce announce URLs
     108   "trackerRemove"       | array      ids of trackers to remove
     109   "trackerReplace"      | array      pairs of <trackerId/new announce URLs>
    110110   "uploadLimit"         | number     maximum upload speed (KBps)
    111111   "uploadLimited"       | boolean    true if "uploadLimit" is honored
     
    617617   10    | 2.10    | yes       | session-get    | new arg "cache-size"
    618618         |         | yes       | torrent-set    | new arg "trackerAdd"
    619          |         | yes       | torrent-set    | new arg "trackerEdit"
    620619         |         | yes       | torrent-set    | new arg "trackerRemove"
     620         |         | yes       | torrent-set    | new arg "trackerReplace"
    621621         |         | yes       | session-set    | new arg "idle-seeding-limit"
    622622         |         | yes       | session-set    | new arg "idle-seeding-limit-enabled"
  • trunk/libtransmission/rpcimpl.c

    r11194 r11209  
    848848
    849849static const char*
    850 replaceTrackerUrls( tr_torrent * tor, tr_benc * urls )
     850replaceTrackers( tr_torrent * tor, tr_benc * urls )
    851851{
    852852    int i;
     
    867867          ((pair[1] = tr_bencListChild(urls,i+1))))
    868868    {
    869         const char * oldval;
     869        int64_t pos;
    870870        const char * newval;
    871871
    872         if(    tr_bencGetStr( pair[0], &oldval )
     872        if(    tr_bencGetInt( pair[0], &pos )
    873873            && tr_bencGetStr( pair[1], &newval )
    874             && strcmp( oldval, newval )
    875874            && tr_urlIsValid( newval, -1 )
    876             && findAnnounceUrl( trackers, n, oldval, &i ) )
     875            && pos < n )
    877876        {
    878             tr_free( trackers[i].announce );
    879             trackers[i].announce = tr_strdup( newval );
     877            tr_free( trackers[pos].announce );
     878            trackers[pos].announce = tr_strdup( newval );
    880879            changed = TRUE;
    881880        }
     
    894893
    895894static const char*
    896 removeTrackerUrls( tr_torrent * tor, tr_benc * urls )
     895removeTrackers( tr_torrent * tor, tr_benc * ids )
    897896{
    898897    int i;
    899898    int n;
     899    int * tids;
     900    int t = 0;
    900901    tr_benc * val;
    901902    tr_tracker_info * trackers;
     
    906907    /* make a working copy of the existing announce list */
    907908    n = inf->trackerCount;
     909    tids = tr_new0( int, n );
    908910    trackers = tr_new0( tr_tracker_info, n );
    909911    copyTrackers( trackers, inf->trackers, n );
     
    911913    /* remove the ones specified in the urls list */
    912914    i = 0;
    913     while(( val = tr_bencListChild( urls, i++ )))
    914     {
    915         int pos;
    916         const char * url;
    917         if( tr_bencGetStr( val, &url ) && findAnnounceUrl( trackers, n, url, &pos ) )
    918         {
    919             tr_removeElementFromArray( trackers, pos, sizeof( tr_tracker_info ), n-- );
    920             changed = TRUE;
    921         }
     915    while(( val = tr_bencListChild( ids, i++ )))
     916    {
     917        int64_t pos;
     918        if( tr_bencGetInt( val, &pos ) && pos < n )
     919            tids[t++] = pos;
     920    }
     921
     922    /* sort trackerIds because tr_removeElementFromArray changes indices as it removes */
     923    qsort( tids, t, sizeof(int), compareInt );
     924
     925    /* remove from largest trackerId to smallest */
     926    while( t-- )
     927    {
     928        tr_removeElementFromArray( trackers, tids[t], sizeof( tr_tracker_info ), n-- );
     929        changed = TRUE;
    922930    }
    923931
     
    928936
    929937    freeTrackers( trackers, n );
     938    tr_free( tids );
    930939    return errmsg;
    931940}
     
    948957        double       d;
    949958        tr_benc *    files;
    950         tr_benc *    urls;
     959        tr_benc *    trackers;
    951960        tr_bool      boolVal;
    952961        tr_torrent * tor = torrents[i];
     
    985994        if( tr_bencDictFindInt( args_in, "seedRatioMode", &tmp ) )
    986995            tr_torrentSetRatioMode( tor, tmp );
    987         if( !errmsg && tr_bencDictFindList( args_in, "trackerAdd", &urls ) )
    988             errmsg = addTrackerUrls( tor, urls );
    989         if( !errmsg && tr_bencDictFindList( args_in, "trackerRemove", &urls ) )
    990             errmsg = removeTrackerUrls( tor, urls );
    991         if( !errmsg && tr_bencDictFindList( args_in, "trackerReplace", &urls ) )
    992             errmsg = replaceTrackerUrls( tor, urls );
     996        if( !errmsg && tr_bencDictFindList( args_in, "trackerAdd", &trackers ) )
     997            errmsg = addTrackerUrls( tor, trackers );
     998        if( !errmsg && tr_bencDictFindList( args_in, "trackerRemove", &trackers ) )
     999            errmsg = removeTrackers( tor, trackers );
     1000        if( !errmsg && tr_bencDictFindList( args_in, "trackerReplace", &trackers ) )
     1001            errmsg = replaceTrackers( tor, trackers );
    9931002        notify( session, TR_RPC_TORRENT_CHANGED, tor );
    9941003    }
  • trunk/libtransmission/utils.c

    r11182 r11209  
    12971297}
    12981298
    1299 static int
     1299int
    13001300compareInt( const void * va, const void * vb )
    13011301{
  • trunk/libtransmission/utils.h

    r11182 r11209  
    439439                     void * userData );
    440440
     441int compareInt( const void * va, const void * vb );
     442
    441443void tr_sha1_to_hex( char * out, const uint8_t * sha1 ) TR_GNUC_NONNULL(1,2);
    442444
  • trunk/qt/details.cc

    r11208 r11209  
    10361036        ids << trackerInfo.torrentId;
    10371037
    1038         QStringList urls;
    1039         urls << trackerInfo.st.announce;
    1040         urls << newval;
    1041 
    1042         mySession.torrentSet( ids, "trackerReplace", urls );
     1038        const QPair<int,QString> idUrl = qMakePair( trackerInfo.st.id, newval );
     1039
     1040        mySession.torrentSet( ids, "trackerReplace", idUrl );
    10431041        getNewData( );
    10441042    }
     
    10511049    QItemSelectionModel * selectionModel = myTrackerView->selectionModel( );
    10521050    QModelIndexList selectedRows = selectionModel->selectedRows( );
    1053     QMap<int,QStringList> torrentId_to_urls;
     1051    QMap<int,int> torrentId_to_trackerIds;
    10541052    foreach( QModelIndex i, selectedRows )
    10551053    {
    10561054        const TrackerInfo inf = myTrackerView->model()->data( i, TrackerModel::TrackerRole ).value<TrackerInfo>();
    1057         torrentId_to_urls[ inf.torrentId ].append( inf.st.announce );
     1055        torrentId_to_trackerIds.insertMulti( inf.torrentId, inf.st.id );
    10581056    }
    10591057
    10601058    // batch all of a tracker's torrents into one command
    1061     foreach( int id, torrentId_to_urls.keys( ) )
     1059    foreach( int id, torrentId_to_trackerIds.uniqueKeys( ) )
    10621060    {
    10631061        QSet<int> ids;
    10641062        ids << id;
    1065         mySession.torrentSet( ids, "trackerRemove", torrentId_to_urls.value( id ) );
    1066         getNewData( );
    1067     }
     1063        mySession.torrentSet( ids, "trackerRemove", torrentId_to_trackerIds.values( id ) );
     1064    }
     1065
     1066    selectionModel->clearSelection( );
     1067    getNewData( );
    10681068}
    10691069
  • trunk/qt/session.cc

    r11137 r11209  
    453453
    454454void
     455Session :: torrentSet( const QSet<int>& ids, const QString& key, const QPair<int,QString>& value )
     456{
     457    tr_benc top;
     458    tr_bencInitDict( &top, 2 );
     459    tr_bencDictAddStr( &top, "method", "torrent-set" );
     460    tr_benc * args( tr_bencDictAddDict( &top, "arguments", 2 ) );
     461    addOptionalIds( args, ids );
     462    tr_benc * list( tr_bencDictAddList( args, key.toUtf8().constData(), 2 ) );
     463    tr_bencListAddInt( list, value.first );
     464    tr_bencListAddStr( list, value.second.toUtf8().constData() );
     465    exec( &top );
     466    tr_bencFree( &top );
     467}
     468
     469void
    455470Session :: torrentSetLocation( const QSet<int>& ids, const QString& location, bool doMove )
    456471{
  • trunk/qt/session.h

    r11109 r11209  
    9898        void torrentSet( const QSet<int>& ids, const QString& key, const QList<int>& val );
    9999        void torrentSet( const QSet<int>& ids, const QString& key, const QStringList& val );
     100        void torrentSet( const QSet<int>& ids, const QString& key, const QPair<int,QString>& val);
    100101        void torrentSetLocation( const QSet<int>& ids, const QString& path, bool doMove );
    101102
Note: See TracChangeset for help on using the changeset viewer.