(trunk libT) tracker.c was using tr_benc's private fields

This commit is contained in:
Charles Kerr 2009-06-01 18:12:36 +00:00
parent 38ffac8bf6
commit f538b08fb3
3 changed files with 58 additions and 58 deletions

View File

@ -1456,8 +1456,8 @@ tr_bencDictSize( const tr_benc * dict )
return count;
}
static tr_bool
tr_bencDictChild( const tr_benc * dict, size_t n, const char ** key, const tr_benc ** val )
tr_bool
tr_bencDictChild( tr_benc * dict, size_t n, const char ** key, tr_benc ** val )
{
tr_bool success = 0;
@ -1486,10 +1486,10 @@ tr_bencMergeDicts( tr_benc * target, const tr_benc * source )
for( i=0; i<sourceCount; ++i )
{
const char * key;
const tr_benc * val;
tr_benc * val;
tr_benc * t;
if( tr_bencDictChild( source, i, &key, &val ) )
if( tr_bencDictChild( (tr_benc*)source, i, &key, &val ) )
{
if( tr_bencIsBool( val ) )
{

View File

@ -163,6 +163,8 @@ tr_benc * tr_bencDictAddDict( tr_benc *, const char * key, size_t reserve );
tr_benc * tr_bencDictAddRaw( tr_benc *, const char * key,
const void * raw, size_t rawlen );
tr_bool tr_bencDictChild( tr_benc *, size_t i, const char ** key, tr_benc ** val );
tr_benc* tr_bencDictFind( tr_benc *, const char * key );
tr_bool tr_bencDictFindList( tr_benc *, const char * key, tr_benc ** setme );

View File

@ -227,7 +227,7 @@ publishWarning( tr_tracker * t,
static void
publishNewPeers( tr_tracker * t,
int allAreSeeds,
void * compact,
const void * compact,
int compactLen )
{
tr_tracker_event event = emptyEvent;
@ -243,11 +243,12 @@ publishNewPeers( tr_tracker * t,
static void
publishNewPeersCompact( tr_tracker * t,
int allAreSeeds,
void * compact,
const void * compact,
int compactLen )
{
int i;
uint8_t *array, *walk, *compactWalk;
const uint8_t *compactWalk;
uint8_t *array, *walk;
const int peerCount = compactLen / 6;
const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 );
tr_address addr;
@ -274,11 +275,12 @@ publishNewPeersCompact( tr_tracker * t,
static void
publishNewPeersCompact6( tr_tracker * t,
int allAreSeeds,
void * compact,
const void * compact,
int compactLen )
{
int i;
uint8_t *array, *walk, *compactWalk;
const uint8_t *compactWalk;
uint8_t *array, *walk;
const int peerCount = compactLen / 18;
const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 );
tr_address addr;
@ -432,79 +434,75 @@ onTrackerResponse( tr_session * session,
int64_t i;
int incomplete = -1;
const char * str;
const uint8_t * raw;
size_t rawlen;
success = TRUE;
t->retryAnnounceIntervalSec = FIRST_SCRAPE_RETRY_INTERVAL_SEC;
if( ( tr_bencDictFindStr( &benc, "failure reason", &str ) ) )
if( tr_bencDictFindStr( &benc, "failure reason", &str ) )
{
publishMessage( t, str, TR_TRACKER_ERROR );
success = FALSE;
}
if( ( tr_bencDictFindStr( &benc, "warning message", &str ) ) )
if( tr_bencDictFindStr( &benc, "warning message", &str ) )
publishWarning( t, str );
if( ( tr_bencDictFindInt( &benc, "interval", &i ) ) )
if( tr_bencDictFindInt( &benc, "interval", &i ) )
{
dbgmsg( t->name, "setting interval to %d", (int)i );
t->announceIntervalSec = i;
}
if( ( tr_bencDictFindInt( &benc, "min interval", &i ) ) )
if( tr_bencDictFindInt( &benc, "min interval", &i ) )
{
dbgmsg( t->name, "setting min interval to %d", (int)i );
t->announceMinIntervalSec = i;
}
if( ( tr_bencDictFindStr( &benc, "tracker id", &str ) ) )
if( tr_bencDictFindStr( &benc, "tracker id", &str ) )
t->trackerID = tr_strdup( str );
if( ( tr_bencDictFindInt( &benc, "complete", &i ) ) )
if( tr_bencDictFindInt( &benc, "complete", &i ) )
{
++scrapeFields;
t->seederCount = i;
}
if( ( tr_bencDictFindInt( &benc, "incomplete", &i ) ) )
if( tr_bencDictFindInt( &benc, "incomplete", &i ) )
{
++scrapeFields;
t->leecherCount = incomplete = i;
}
if( ( tr_bencDictFindInt( &benc, "downloaded", &i ) ) )
if( tr_bencDictFindInt( &benc, "downloaded", &i ) )
{
++scrapeFields;
t->timesDownloaded = i;
}
if( ( tmp = tr_bencDictFind( &benc, "peers" ) ) )
if( tr_bencDictFindRaw( &benc, "peers", &raw, &rawlen ) )
{
/* "compact" extension */
const int allAreSeeds = incomplete == 0;
if( tr_bencIsString( tmp ) ) /* "compact" extension */
{
publishNewPeersCompact( t, allAreSeeds, tmp->val.s.s,
tmp->val.s.i );
publishNewPeersCompact( t, allAreSeeds, raw, rawlen );
}
else if( tr_bencIsList( tmp ) ) /* original protocol */
else if( tr_bencDictFindList( &benc, "peers", &tmp ) )
{
/* original version of peers */
const int allAreSeeds = incomplete == 0;
size_t byteCount = 0;
uint8_t * array = parseOldPeers( tmp, &byteCount );
publishNewPeers( t, allAreSeeds, array, byteCount );
tr_free( array );
}
}
if( ( tmp = tr_bencDictFind( &benc, "peers6" ) ) )
if( tr_bencDictFindRaw( &benc, "peers6", &raw, &rawlen ) )
{
/* "compact" extension */
const int allAreSeeds = incomplete == 0;
if( tr_bencIsString( tmp ) ) /* "compact" extension */
{
publishNewPeersCompact6( t, allAreSeeds, tmp->val.s.s,
tmp->val.s.i );
}
publishNewPeersCompact6( t, allAreSeeds, raw, rawlen );
}
}
@ -624,34 +622,34 @@ onScrapeResponse( tr_session * session,
&benc, NULL );
if( bencLoaded && tr_bencDictFindDict( &benc, "files", &files ) )
{
size_t i;
for( i = 0; i < files->val.l.count; i += 2 )
const char * key;
tr_benc * val;
int i = 0;
while( tr_bencDictChild( files, i++, &key, &val ))
{
int64_t itmp;
const uint8_t* hash =
(const uint8_t*) files->val.l.vals[i].val.s.s;
int64_t intVal;
tr_benc * flags;
tr_benc * tordict = &files->val.l.vals[i + 1];
if( memcmp( t->hash, hash, SHA_DIGEST_LENGTH ) )
if( memcmp( t->hash, key, SHA_DIGEST_LENGTH ) )
continue;
publishErrorClear( t );
if( ( tr_bencDictFindInt( tordict, "complete", &itmp ) ) )
t->seederCount = itmp;
if( ( tr_bencDictFindInt( val, "complete", &intVal ) ) )
t->seederCount = intVal;
if( ( tr_bencDictFindInt( tordict, "incomplete", &itmp ) ) )
t->leecherCount = itmp;
if( ( tr_bencDictFindInt( val, "incomplete", &intVal ) ) )
t->leecherCount = intVal;
if( ( tr_bencDictFindInt( tordict, "downloaded", &itmp ) ) )
t->timesDownloaded = itmp;
if( ( tr_bencDictFindInt( val, "downloaded", &intVal ) ) )
t->timesDownloaded = intVal;
if( ( tr_bencDictFindInt( tordict, "downloaders", &itmp ) ) )
t->downloaderCount = itmp;
if( ( tr_bencDictFindInt( val, "downloaders", &intVal ) ) )
t->downloaderCount = intVal;
if( tr_bencDictFindDict( tordict, "flags", &flags ) )
if( ( tr_bencDictFindInt( flags, "min_request_interval", &itmp ) ) )
t->scrapeIntervalSec = itmp;
if( tr_bencDictFindDict( val, "flags", &flags ) )
if( ( tr_bencDictFindInt( flags, "min_request_interval", &intVal ) ) )
t->scrapeIntervalSec = intVal;
/* as per ticket #1045, safeguard against trackers returning
* a very low min_request_interval... */