1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

(trunk libT) "tr_torrentSetAnnounceList() should not trigger reannounces to trackers" -- implemented in trunk for 1.90

This commit is contained in:
Charles Kerr 2010-02-13 21:58:38 +00:00
parent 48f3316926
commit 057b80a9f9

View file

@ -353,27 +353,27 @@ typedef struct
tr_ptrArray trackers; /* tr_tracker_item */ tr_ptrArray trackers; /* tr_tracker_item */
tr_tracker_item * currentTracker; tr_tracker_item * currentTracker;
int currentTrackerIndex;
tr_torrent * tor; tr_torrent * tor;
time_t lastScrapeTime; time_t scrapeAt;
time_t lastAnnounceTime;
time_t lastScrapeStartTime; time_t lastScrapeStartTime;
time_t lastAnnounceStartTime; time_t lastScrapeTime;
tr_bool lastScrapeSucceeded; tr_bool lastScrapeSucceeded;
time_t announceAt;
time_t manualAnnounceAllowedAt;
time_t lastAnnounceStartTime;
time_t lastAnnounceTime;
tr_bool lastAnnounceSucceeded; tr_bool lastAnnounceSucceeded;
tr_bool lastAnnounceTimedOut; tr_bool lastAnnounceTimedOut;
time_t scrapeAt;
time_t manualAnnounceAllowedAt;
time_t announceAt;
tr_ptrArray announceEvents; /* const char* */ tr_ptrArray announceEvents; /* const char* */
/* unique lookup key */ /* unique lookup key */
int key; int key;
int currentTrackerIndex;
int scrapeIntervalSec; int scrapeIntervalSec;
int announceIntervalSec; int announceIntervalSec;
int announceMinIntervalSec; int announceMinIntervalSec;
@ -420,6 +420,29 @@ tierFree( void * vtier )
tr_free( tier ); tr_free( tier );
} }
static void
tierCopyAttributes( tr_tier * t, const tr_tier * o )
{
int i, n;
tr_tier bak;
assert( t != NULL );
assert( o != NULL );
assert( t != o );
bak = *t;
*t = *o;
t->tor = bak.tor;
t->trackers = bak.trackers;
t->announceEvents = bak.announceEvents;
t->currentTracker = bak.currentTracker;
t->currentTrackerIndex = bak.currentTrackerIndex;
tr_ptrArrayClear( &t->announceEvents );
for( i=0, n=tr_ptrArraySize(&o->announceEvents); i<n; ++i )
tr_ptrArrayAppend( &t->announceEvents, tr_ptrArrayNth((tr_ptrArray*)&o->announceEvents,i) );
}
static void static void
tierIncrementTracker( tr_tier * tier ) tierIncrementTracker( tr_tier * tier )
{ {
@ -481,13 +504,6 @@ tiersNew( void )
return tiers; return tiers;
} }
static void
tiersClear( tr_torrent_tiers * tiers )
{
tr_ptrArrayDestruct( &tiers->tiers, tierFree );
tiers->tiers = TR_PTR_ARRAY_INIT;
}
static void static void
tiersFree( tr_torrent_tiers * tiers ) tiersFree( tr_torrent_tiers * tiers )
{ {
@ -794,15 +810,60 @@ tr_announcerAddTorrent( tr_announcer * announcer, tr_torrent * tor )
void void
tr_announcerResetTorrent( tr_announcer * announcer, tr_torrent * tor ) tr_announcerResetTorrent( tr_announcer * announcer, tr_torrent * tor )
{ {
tr_ptrArray oldTiers = TR_PTR_ARRAY_INIT;
/* if we had tiers already, make a backup of them */
if( tor->tiers != NULL ) if( tor->tiers != NULL )
{ {
tiersClear( tor->tiers ); oldTiers = tor->tiers->tiers;
tor->tiers->tiers = TR_PTR_ARRAY_INIT;
}
/* create the new tier/tracker structs */
addTorrentToTier( announcer, tor->tiers, tor ); addTorrentToTier( announcer, tor->tiers, tor );
/* if we had tiers already, merge their state into the new structs */
if( !tr_ptrArrayEmpty( &oldTiers ) )
{
int i, in;
for( i=0, in=tr_ptrArraySize(&oldTiers); i<in; ++i )
{
int j, jn;
const tr_tier * o = tr_ptrArrayNth( &oldTiers, i );
if( o->currentTracker == NULL )
continue;
for( j=0, jn=tr_ptrArraySize(&tor->tiers->tiers); j<jn; ++j )
{
int k, kn;
tr_tier * t = tr_ptrArrayNth(&tor->tiers->tiers,j);
for( k=0, kn=tr_ptrArraySize(&t->trackers); k<kn; ++k )
{
tr_tracker_item * item = tr_ptrArrayNth(&t->trackers,k);
if( strcmp( o->currentTracker->announce, item->announce ) )
continue;
tierCopyAttributes( t, o );
t->currentTracker = item;
t->currentTrackerIndex = k;
dbgmsg( t, "attributes copied to tier %d, tracker %d"
"from tier %d, tracker %d",
i, o->currentTrackerIndex, j, k );
}
}
}
}
else
{
/* start the torrent, if applicable */
if( tor->isRunning ) if( tor->isRunning )
tr_announcerTorrentStarted( tor ); tr_announcerTorrentStarted( tor );
} }
/* cleanup */
tr_ptrArrayDestruct( &oldTiers, tierFree );
} }
tr_publisher_tag tr_publisher_tag