add an identifier to trackers, for use by the ui's (this should hopefully fix the problem for removing trackers with "invisible" trackers)
This commit is contained in:
parent
7af6abcee1
commit
6138daec3f
|
@ -295,6 +295,8 @@ typedef struct
|
|||
int leecherCount;
|
||||
int downloadCount;
|
||||
int downloaderCount;
|
||||
|
||||
uint32_t identifier;
|
||||
|
||||
/* sent as the "key" argument in tracker requests
|
||||
* to verify us if our IP address changes.
|
||||
|
@ -319,12 +321,14 @@ generateKeyParam( char * msg, size_t msglen )
|
|||
static tr_tracker_item*
|
||||
trackerNew( tr_announcer * announcer,
|
||||
const char * announce,
|
||||
const char * scrape )
|
||||
const char * scrape,
|
||||
uint32_t identifier )
|
||||
{
|
||||
tr_tracker_item * tracker = tr_new0( tr_tracker_item, 1 );
|
||||
tracker->host = getHost( announcer, announce );
|
||||
tracker->announce = tr_strdup( announce );
|
||||
tracker->scrape = tr_strdup( scrape );
|
||||
tracker->identifier = identifier;
|
||||
generateKeyParam( tracker->key_param, KEYLEN );
|
||||
tracker->seederCount = -1;
|
||||
tracker->leecherCount = -1;
|
||||
|
@ -448,9 +452,10 @@ static void
|
|||
tierAddTracker( tr_announcer * announcer,
|
||||
tr_tier * tier,
|
||||
const char * announce,
|
||||
const char * scrape )
|
||||
const char * scrape,
|
||||
uint32_t identifier )
|
||||
{
|
||||
tr_tracker_item * tracker = trackerNew( announcer, announce, scrape );
|
||||
tr_tracker_item * tracker = trackerNew( announcer, announce, scrape, identifier );
|
||||
|
||||
tr_ptrArrayAppend( &tier->trackers, tracker );
|
||||
dbgmsg( tier, "adding tracker %s", announce );
|
||||
|
@ -771,7 +776,7 @@ addTorrentToTier( tr_announcer * announcer, tr_torrent_tiers * tiers, tr_torrent
|
|||
tr_ptrArrayAppend( &tiers->tiers, tier );
|
||||
}
|
||||
|
||||
tierAddTracker( announcer, tier, info->announce, info->scrape );
|
||||
tierAddTracker( announcer, tier, info->announce, info->scrape, info->identifier );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1749,6 +1754,7 @@ tr_announcerStats( const tr_torrent * torrent,
|
|||
const tr_tracker_item * tracker = tr_ptrArrayNth( (tr_ptrArray*)&tier->trackers, j );
|
||||
tr_tracker_stat * st = ret + out++;
|
||||
|
||||
st->identifier = tracker->identifier;
|
||||
tr_strlcpy( st->host, tracker->host->name, sizeof( st->host ) );
|
||||
tr_strlcpy( st->announce, tracker->announce, sizeof( st->announce ) );
|
||||
st->tier = i + 1;
|
||||
|
|
|
@ -271,13 +271,13 @@ getannounce( tr_info * inf, tr_benc * meta )
|
|||
int n;
|
||||
int i, j, validTiers;
|
||||
const int numTiers = tr_bencListSize( tiers );
|
||||
uint32_t trackerId = 0;
|
||||
|
||||
n = 0;
|
||||
for( i = 0; i < numTiers; ++i )
|
||||
n += tr_bencListSize( tr_bencListChild( tiers, i ) );
|
||||
|
||||
trackers = tr_new0( tr_tracker_info, n );
|
||||
trackerCount = 0;
|
||||
|
||||
for( i = 0, validTiers = 0; i < numTiers; ++i )
|
||||
{
|
||||
|
@ -291,12 +291,14 @@ getannounce( tr_info * inf, tr_benc * meta )
|
|||
char * url = tr_strstrip( tr_strdup( str ) );
|
||||
if( tr_httpIsValidURL( url ) )
|
||||
{
|
||||
tr_tracker_info * t = trackers + trackerCount++;
|
||||
tr_tracker_info * t = trackers + trackerCount;
|
||||
t->tier = validTiers;
|
||||
t->announce = tr_strdup( url );
|
||||
t->scrape = tr_convertAnnounceToScrape( url );
|
||||
t->identifier = trackerCount;
|
||||
|
||||
anyAdded = TRUE;
|
||||
++trackerCount;
|
||||
}
|
||||
tr_free( url );
|
||||
}
|
||||
|
@ -324,7 +326,9 @@ getannounce( tr_info * inf, tr_benc * meta )
|
|||
trackers = tr_new0( tr_tracker_info, 1 );
|
||||
trackers[trackerCount].tier = 0;
|
||||
trackers[trackerCount].announce = tr_strdup( url );
|
||||
trackers[trackerCount++].scrape = tr_convertAnnounceToScrape( url );
|
||||
trackers[trackerCount].scrape = tr_convertAnnounceToScrape( url );
|
||||
trackers[trackerCount].identifier = 0;
|
||||
trackerCount++;
|
||||
/*fprintf( stderr, "single announce: [%s]\n", url );*/
|
||||
}
|
||||
tr_free( url );
|
||||
|
@ -596,6 +600,7 @@ tr_metainfoSetFromMagnet( tr_info * inf, const tr_magnet_info * m )
|
|||
inf->trackers[i].tier = i;
|
||||
inf->trackers[i].announce = tr_strdup( url );
|
||||
inf->trackers[i].scrape = tr_convertAnnounceToScrape( url );
|
||||
inf->trackers[i].identifier = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -363,6 +363,7 @@ addTrackers( const tr_info * info,
|
|||
tr_bencDictAddStr( d, "announce", t->announce );
|
||||
tr_bencDictAddStr( d, "scrape", t->scrape );
|
||||
tr_bencDictAddInt( d, "tier", t->tier );
|
||||
tr_bencDictAddInt( d, "id", t->identifier );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1200,16 +1200,17 @@ char* tr_torrentGetMagnetLink( const tr_torrent * tor );
|
|||
***
|
||||
**/
|
||||
|
||||
|
||||
/** @brief a part of tr_info that represents a single tracker */
|
||||
typedef struct tr_tracker_info
|
||||
{
|
||||
int tier;
|
||||
char * announce;
|
||||
char * scrape;
|
||||
int tier;
|
||||
char * announce;
|
||||
char * scrape;
|
||||
uint32_t identifier; /* used to match to a tr_tracker_stat */
|
||||
}
|
||||
tr_tracker_info;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Modify a torrent's tracker list.
|
||||
*
|
||||
|
@ -1458,6 +1459,9 @@ typedef struct
|
|||
|
||||
/* which tier this tracker is in */
|
||||
int tier;
|
||||
|
||||
/* used to match to a tr_tracker_info */
|
||||
uint32_t identifier;
|
||||
}
|
||||
tr_tracker_stat;
|
||||
|
||||
|
|
|
@ -1741,11 +1741,9 @@ typedef enum
|
|||
|
||||
- (void) removeTrackers
|
||||
{
|
||||
NSMutableIndexSet * removeIndexes = [NSMutableIndexSet indexSet];
|
||||
NSMutableIndexSet * removeIdentifiers = [NSMutableIndexSet indexSet];
|
||||
|
||||
NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes];
|
||||
NSLog(@"%@", fTrackers);
|
||||
NSLog(@"selected: %@", selectedIndexes);
|
||||
BOOL groupSelected = NO;
|
||||
for (NSUInteger i = 0, trackerIndex = 0; i < [fTrackers count]; ++i)
|
||||
{
|
||||
|
@ -1758,26 +1756,23 @@ typedef enum
|
|||
else
|
||||
{
|
||||
if (groupSelected || [selectedIndexes containsIndex: i])
|
||||
{
|
||||
[removeIndexes addIndex: trackerIndex];
|
||||
NSLog(@"adding for remove %d (%d): %@", trackerIndex, i, [fTrackers objectAtIndex: i]);
|
||||
}
|
||||
[removeIdentifiers addIndex: [(TrackerNode *)[fTrackers objectAtIndex: i] identifier]];
|
||||
++trackerIndex;
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"%@", removeIndexes);
|
||||
NSLog(@"%@", removeIdentifiers);
|
||||
|
||||
NSAssert([removeIndexes count] > 0, @"Trying to remove no trackers.");
|
||||
NSAssert([removeIdentifiers count] > 0, @"Trying to remove no trackers.");
|
||||
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveTrackers"])
|
||||
{
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
|
||||
if ([removeIndexes count] > 1)
|
||||
if ([removeIdentifiers count] > 1)
|
||||
{
|
||||
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
|
||||
"Remove trackers alert -> title"), [removeIndexes count]]];
|
||||
"Remove trackers alert -> title"), [removeIdentifiers count]]];
|
||||
[alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
|
||||
" This cannot be undone.", "Remove trackers alert -> message")];
|
||||
}
|
||||
|
@ -1803,7 +1798,7 @@ typedef enum
|
|||
}
|
||||
|
||||
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
||||
[torrent removeTrackersAtIndexes: removeIndexes];
|
||||
[torrent removeTrackersWithIdentifiers: removeIdentifiers];
|
||||
|
||||
//reset table with either new or old value
|
||||
[fTrackers release];
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
- (NSMutableArray *) allTrackerStats;
|
||||
- (NSArray *) allTrackersFlat; //used by GroupRules
|
||||
- (BOOL) addTrackerToNewTier: (NSString *) tracker;
|
||||
- (void) removeTrackersAtIndexes: (NSIndexSet *) removeIndexes;
|
||||
- (void) removeTrackersWithIdentifiers: (NSIndexSet *) removeIdentifiers;
|
||||
|
||||
- (NSString *) comment;
|
||||
- (NSString *) creator;
|
||||
|
|
|
@ -587,7 +587,6 @@ int trashDataFile(const char * filename)
|
|||
{
|
||||
int count;
|
||||
tr_tracker_stat * stats = tr_torrentTrackers(fHandle, &count);
|
||||
NSLog(@"count from tr_torrentTrackers: %d", count);
|
||||
|
||||
NSMutableArray * trackers = [NSMutableArray arrayWithCapacity: (count > 0 ? count + stats[count-1].tier : 0)];
|
||||
|
||||
|
@ -629,11 +628,15 @@ int trashDataFile(const char * filename)
|
|||
//recreate the tracker structure
|
||||
const int oldTrackerCount = fInfo->trackerCount;
|
||||
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, oldTrackerCount+1);
|
||||
for (NSInteger i=0; i < oldTrackerCount; ++i)
|
||||
for (NSUInteger i=0; i < oldTrackerCount; ++i)
|
||||
{
|
||||
trackerStructs[i] = fInfo->trackers[i];
|
||||
trackerStructs[i].identifier = i;
|
||||
}
|
||||
|
||||
trackerStructs[oldTrackerCount].announce = (char *)[tracker UTF8String];
|
||||
trackerStructs[oldTrackerCount].tier = trackerStructs[oldTrackerCount-1].tier + 1;
|
||||
trackerStructs[oldTrackerCount].identifier = trackerStructs[oldTrackerCount-1].identifier + 1;
|
||||
|
||||
const BOOL success = tr_torrentSetAnnounceList(fHandle, trackerStructs, oldTrackerCount+1);
|
||||
tr_free(trackerStructs);
|
||||
|
@ -641,22 +644,19 @@ int trashDataFile(const char * filename)
|
|||
return success;
|
||||
}
|
||||
|
||||
- (void) removeTrackersAtIndexes: (NSIndexSet *) removeIndexes
|
||||
- (void) removeTrackersWithIdentifiers: (NSIndexSet *) removeIdentifiers
|
||||
{
|
||||
NSAssert([removeIndexes lastIndex] < fInfo->trackerCount, @"Trying to remove trackers outside the tracker count.");
|
||||
|
||||
NSMutableIndexSet * indexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, fInfo->trackerCount)];
|
||||
[indexes removeIndexes: removeIndexes];
|
||||
|
||||
//recreate the tracker structure
|
||||
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, [indexes count]);
|
||||
NSLog(@"count from fInfo: %d", fInfo->trackerCount);
|
||||
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, fInfo->trackerCount);
|
||||
|
||||
int newCount = 0;
|
||||
for (NSUInteger oldIndex = [indexes firstIndex]; oldIndex != NSNotFound; oldIndex = [indexes indexGreaterThanIndex: oldIndex])
|
||||
NSUInteger newCount = 0;
|
||||
for (NSUInteger i = 0; i < fInfo->trackerCount; i++)
|
||||
{
|
||||
NSLog(@"oldIndex: %d %s", oldIndex, fInfo->trackers[oldIndex].announce);
|
||||
trackerStructs[newCount++] = fInfo->trackers[oldIndex];
|
||||
if (![removeIdentifiers containsIndex: fInfo->trackers[i].identifier])
|
||||
{
|
||||
trackerStructs[newCount] = fInfo->trackers[i];
|
||||
trackerStructs[newCount].identifier = newCount++;
|
||||
}
|
||||
}
|
||||
|
||||
const BOOL success = tr_torrentSetAnnounceList(fHandle, trackerStructs, newCount);
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
|
||||
- (NSInteger) tier;
|
||||
|
||||
- (NSUInteger) identifier;
|
||||
|
||||
- (NSInteger) totalSeeders;
|
||||
- (NSInteger) totalLeechers;
|
||||
- (NSInteger) totalDownloaded;
|
||||
|
|
|
@ -64,6 +64,11 @@
|
|||
return fStat.tier;
|
||||
}
|
||||
|
||||
- (NSUInteger) identifier
|
||||
{
|
||||
return fStat.identifier;
|
||||
}
|
||||
|
||||
- (NSInteger) totalSeeders
|
||||
{
|
||||
return fStat.seederCount;
|
||||
|
|
Loading…
Reference in New Issue