Changeset 9902


Ignore:
Timestamp:
Jan 10, 2010, 2:34:00 AM (12 years ago)
Author:
livings124
Message:

add an identifier to trackers, for use by the ui's (this should hopefully fix the problem for removing trackers with "invisible" trackers)

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r9868 r9902  
    296296    int downloadCount;
    297297    int downloaderCount;
     298   
     299    uint32_t identifier;
    298300
    299301    /* sent as the "key" argument in tracker requests
     
    320322trackerNew( tr_announcer  * announcer,
    321323            const char    * announce,
    322             const char    * scrape )
     324            const char    * scrape,
     325            uint32_t      identifier )
    323326{
    324327    tr_tracker_item * tracker = tr_new0( tr_tracker_item, 1  );
     
    326329    tracker->announce = tr_strdup( announce );
    327330    tracker->scrape = tr_strdup( scrape );
     331    tracker->identifier = identifier;
    328332    generateKeyParam( tracker->key_param, KEYLEN );
    329333    tracker->seederCount = -1;
     
    449453                tr_tier      * tier,
    450454                const char   * announce,
    451                 const char   * scrape )
    452 {
    453     tr_tracker_item * tracker = trackerNew( announcer, announce, scrape );
     455                const char   * scrape,
     456                uint32_t     identifier )
     457{
     458    tr_tracker_item * tracker = trackerNew( announcer, announce, scrape, identifier );
    454459
    455460    tr_ptrArrayAppend( &tier->trackers, tracker );
     
    772777            }
    773778
    774             tierAddTracker( announcer, tier, info->announce, info->scrape );
     779            tierAddTracker( announcer, tier, info->announce, info->scrape, info->identifier );
    775780        }
    776781    }
     
    17501755            tr_tracker_stat * st = ret + out++;
    17511756
     1757            st->identifier = tracker->identifier;
    17521758            tr_strlcpy( st->host, tracker->host->name, sizeof( st->host ) );
    17531759            tr_strlcpy( st->announce, tracker->announce, sizeof( st->announce ) );
  • trunk/libtransmission/metainfo.c

    r9868 r9902  
    272272        int       i, j, validTiers;
    273273        const int numTiers = tr_bencListSize( tiers );
     274        uint32_t  trackerId = 0;
    274275
    275276        n = 0;
     
    278279
    279280        trackers = tr_new0( tr_tracker_info, n );
    280         trackerCount = 0;
    281281
    282282        for( i = 0, validTiers = 0; i < numTiers; ++i )
     
    292292                    if( tr_httpIsValidURL( url ) )
    293293                    {
    294                         tr_tracker_info * t = trackers + trackerCount++;
     294                        tr_tracker_info * t = trackers + trackerCount;
    295295                        t->tier = validTiers;
    296296                        t->announce = tr_strdup( url );
    297297                        t->scrape = tr_convertAnnounceToScrape( url );
     298                        t->identifier = trackerCount;
    298299
    299300                        anyAdded = TRUE;
     301                        ++trackerCount;
    300302                    }
    301303                    tr_free( url );
     
    325327            trackers[trackerCount].tier = 0;
    326328            trackers[trackerCount].announce = tr_strdup( url );
    327             trackers[trackerCount++].scrape = tr_convertAnnounceToScrape( url );
     329            trackers[trackerCount].scrape = tr_convertAnnounceToScrape( url );
     330            trackers[trackerCount].identifier = 0;
     331            trackerCount++;
    328332            /*fprintf( stderr, "single announce: [%s]\n", url );*/
    329333        }
     
    597601            inf->trackers[i].announce = tr_strdup( url );
    598602            inf->trackers[i].scrape = tr_convertAnnounceToScrape( url );
     603            inf->trackers[i].identifier = i;
    599604        }
    600605    }
  • trunk/libtransmission/rpcimpl.c

    r9868 r9902  
    364364        tr_bencDictAddStr( d, "scrape", t->scrape );
    365365        tr_bencDictAddInt( d, "tier", t->tier );
     366        tr_bencDictAddInt( d, "id", t->identifier );
    366367    }
    367368}
  • trunk/libtransmission/transmission.h

    r9891 r9902  
    12011201**/
    12021202
     1203
    12031204/** @brief a part of tr_info that represents a single tracker */
    12041205typedef struct tr_tracker_info
    12051206{
    1206     int     tier;
    1207     char *  announce;
    1208     char *  scrape;
     1207    int      tier;
     1208    char *   announce;
     1209    char *   scrape;
     1210    uint32_t identifier; /* used to match to a tr_tracker_stat */
    12091211}
    12101212tr_tracker_info;
    1211 
    12121213
    12131214/**
     
    14591460    /* which tier this tracker is in */
    14601461    int tier;
     1462   
     1463    /* used to match to a tr_tracker_info */
     1464    uint32_t identifier;
    14611465}
    14621466tr_tracker_stat;
  • trunk/macosx/InfoWindowController.m

    r9896 r9902  
    17421742- (void) removeTrackers
    17431743{
    1744     NSMutableIndexSet * removeIndexes = [NSMutableIndexSet indexSet];
     1744    NSMutableIndexSet * removeIdentifiers = [NSMutableIndexSet indexSet];
    17451745   
    17461746    NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes];
    1747     NSLog(@"%@", fTrackers);
    1748     NSLog(@"selected: %@", selectedIndexes);
    17491747    BOOL groupSelected = NO;
    17501748    for (NSUInteger i = 0, trackerIndex = 0; i < [fTrackers count]; ++i)
     
    17591757        {
    17601758            if (groupSelected || [selectedIndexes containsIndex: i])
    1761             {
    1762                 [removeIndexes addIndex: trackerIndex];
    1763                 NSLog(@"adding for remove %d (%d): %@", trackerIndex, i, [fTrackers objectAtIndex: i]);
    1764             }
     1759                [removeIdentifiers addIndex: [(TrackerNode *)[fTrackers objectAtIndex: i] identifier]];
    17651760            ++trackerIndex;
    17661761        }
    17671762    }
    17681763   
    1769     NSLog(@"%@", removeIndexes);
    1770    
    1771     NSAssert([removeIndexes count] > 0, @"Trying to remove no trackers.");
     1764    NSLog(@"%@", removeIdentifiers);
     1765   
     1766    NSAssert([removeIdentifiers count] > 0, @"Trying to remove no trackers.");
    17721767   
    17731768    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveTrackers"])
     
    17751770        NSAlert * alert = [[NSAlert alloc] init];
    17761771       
    1777         if ([removeIndexes count] > 1)
     1772        if ([removeIdentifiers count] > 1)
    17781773        {
    17791774            [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
    1780                                                                 "Remove trackers alert -> title"), [removeIndexes count]]];
     1775                                                                "Remove trackers alert -> title"), [removeIdentifiers count]]];
    17811776            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
    17821777                                        " This cannot be undone.", "Remove trackers alert -> message")];
     
    18041799   
    18051800    Torrent * torrent = [fTorrents objectAtIndex: 0];
    1806     [torrent removeTrackersAtIndexes: removeIndexes];
     1801    [torrent removeTrackersWithIdentifiers: removeIdentifiers];
    18071802   
    18081803    //reset table with either new or old value
  • trunk/macosx/Torrent.h

    r9852 r9902  
    132132- (NSArray *) allTrackersFlat; //used by GroupRules
    133133- (BOOL) addTrackerToNewTier: (NSString *) tracker;
    134 - (void) removeTrackersAtIndexes: (NSIndexSet *) removeIndexes;
     134- (void) removeTrackersWithIdentifiers: (NSIndexSet *) removeIdentifiers;
    135135
    136136- (NSString *) comment;
  • trunk/macosx/Torrent.m

    r9897 r9902  
    588588    int count;
    589589    tr_tracker_stat * stats = tr_torrentTrackers(fHandle, &count);
    590     NSLog(@"count from tr_torrentTrackers: %d", count);
    591590   
    592591    NSMutableArray * trackers = [NSMutableArray arrayWithCapacity: (count > 0 ? count + stats[count-1].tier : 0)];
     
    630629    const int oldTrackerCount = fInfo->trackerCount;
    631630    tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, oldTrackerCount+1);
    632     for (NSInteger i=0; i < oldTrackerCount; ++i)
     631    for (NSUInteger i=0; i < oldTrackerCount; ++i)
     632    {
    633633        trackerStructs[i] = fInfo->trackers[i];
     634        trackerStructs[i].identifier = i;
     635    }
    634636   
    635637    trackerStructs[oldTrackerCount].announce = (char *)[tracker UTF8String];
    636638    trackerStructs[oldTrackerCount].tier = trackerStructs[oldTrackerCount-1].tier + 1;
     639    trackerStructs[oldTrackerCount].identifier = trackerStructs[oldTrackerCount-1].identifier + 1;
    637640   
    638641    const BOOL success = tr_torrentSetAnnounceList(fHandle, trackerStructs, oldTrackerCount+1);
     
    642645}
    643646
    644 - (void) removeTrackersAtIndexes: (NSIndexSet *) removeIndexes
    645 {
    646     NSAssert([removeIndexes lastIndex] < fInfo->trackerCount, @"Trying to remove trackers outside the tracker count.");
    647    
    648     NSMutableIndexSet * indexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, fInfo->trackerCount)];
    649     [indexes removeIndexes: removeIndexes];
    650    
     647- (void) removeTrackersWithIdentifiers: (NSIndexSet *) removeIdentifiers
     648{
    651649    //recreate the tracker structure
    652     tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, [indexes count]);
    653     NSLog(@"count from fInfo: %d", fInfo->trackerCount);
    654    
    655     int newCount = 0;
    656     for (NSUInteger oldIndex = [indexes firstIndex]; oldIndex != NSNotFound; oldIndex = [indexes indexGreaterThanIndex: oldIndex])
    657     {
    658         NSLog(@"oldIndex: %d %s", oldIndex, fInfo->trackers[oldIndex].announce);
    659         trackerStructs[newCount++] = fInfo->trackers[oldIndex];
     650    tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, fInfo->trackerCount);
     651   
     652    NSUInteger newCount = 0;
     653    for (NSUInteger i = 0; i < fInfo->trackerCount; i++)
     654    {
     655        if (![removeIdentifiers containsIndex: fInfo->trackers[i].identifier])
     656        {
     657            trackerStructs[newCount] = fInfo->trackers[i];
     658            trackerStructs[newCount].identifier = newCount++;
     659        }
    660660    }
    661661   
  • trunk/macosx/TrackerNode.h

    r9844 r9902  
    3838- (NSInteger) tier;
    3939
     40- (NSUInteger) identifier;
     41
    4042- (NSInteger) totalSeeders;
    4143- (NSInteger) totalLeechers;
  • trunk/macosx/TrackerNode.m

    r9896 r9902  
    6363{
    6464    return fStat.tier;
     65}
     66
     67- (NSUInteger) identifier
     68{
     69    return fStat.identifier;
    6570}
    6671
Note: See TracChangeset for help on using the changeset viewer.