Changeset 8583 for trunk/libtransmission/tracker.c
- Timestamp:
- Jun 1, 2009, 6:12:36 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/tracker.c
r8581 r8583 228 228 publishNewPeers( tr_tracker * t, 229 229 int allAreSeeds, 230 void *compact,230 const void * compact, 231 231 int compactLen ) 232 232 { … … 244 244 publishNewPeersCompact( tr_tracker * t, 245 245 int allAreSeeds, 246 void* compact,246 const void * compact, 247 247 int compactLen ) 248 248 { 249 249 int i; 250 uint8_t *array, *walk, *compactWalk; 250 const uint8_t *compactWalk; 251 uint8_t *array, *walk; 251 252 const int peerCount = compactLen / 6; 252 253 const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 ); … … 275 276 publishNewPeersCompact6( tr_tracker * t, 276 277 int allAreSeeds, 277 void* compact,278 const void * compact, 278 279 int compactLen ) 279 280 { 280 281 int i; 281 uint8_t *array, *walk, *compactWalk; 282 const uint8_t *compactWalk; 283 uint8_t *array, *walk; 282 284 const int peerCount = compactLen / 18; 283 285 const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 ); … … 433 435 int incomplete = -1; 434 436 const char * str; 437 const uint8_t * raw; 438 size_t rawlen; 435 439 436 440 success = TRUE; 437 441 t->retryAnnounceIntervalSec = FIRST_SCRAPE_RETRY_INTERVAL_SEC; 438 442 439 if( ( tr_bencDictFindStr( &benc, "failure reason", &str )) )443 if( tr_bencDictFindStr( &benc, "failure reason", &str ) ) 440 444 { 441 445 publishMessage( t, str, TR_TRACKER_ERROR ); … … 443 447 } 444 448 445 if( ( tr_bencDictFindStr( &benc, "warning message", &str )) )449 if( tr_bencDictFindStr( &benc, "warning message", &str ) ) 446 450 publishWarning( t, str ); 447 451 448 if( ( tr_bencDictFindInt( &benc, "interval", &i )) )452 if( tr_bencDictFindInt( &benc, "interval", &i ) ) 449 453 { 450 454 dbgmsg( t->name, "setting interval to %d", (int)i ); … … 452 456 } 453 457 454 if( ( tr_bencDictFindInt( &benc, "min interval", &i )) )458 if( tr_bencDictFindInt( &benc, "min interval", &i ) ) 455 459 { 456 460 dbgmsg( t->name, "setting min interval to %d", (int)i ); … … 458 462 } 459 463 460 if( ( tr_bencDictFindStr( &benc, "tracker id", &str )) )464 if( tr_bencDictFindStr( &benc, "tracker id", &str ) ) 461 465 t->trackerID = tr_strdup( str ); 462 466 463 if( ( tr_bencDictFindInt( &benc, "complete", &i )) )467 if( tr_bencDictFindInt( &benc, "complete", &i ) ) 464 468 { 465 469 ++scrapeFields; … … 467 471 } 468 472 469 if( ( tr_bencDictFindInt( &benc, "incomplete", &i )) )473 if( tr_bencDictFindInt( &benc, "incomplete", &i ) ) 470 474 { 471 475 ++scrapeFields; … … 473 477 } 474 478 475 if( ( tr_bencDictFindInt( &benc, "downloaded", &i )) )479 if( tr_bencDictFindInt( &benc, "downloaded", &i ) ) 476 480 { 477 481 ++scrapeFields; … … 479 483 } 480 484 481 if( ( tmp = tr_bencDictFind( &benc, "peers" )) )485 if( tr_bencDictFindRaw( &benc, "peers", &raw, &rawlen ) ) 482 486 { 487 /* "compact" extension */ 483 488 const int allAreSeeds = incomplete == 0; 484 485 if( tr_bencIsString( tmp ) ) /* "compact" extension */ 486 { 487 publishNewPeersCompact( t, allAreSeeds, tmp->val.s.s, 488 tmp->val.s.i ); 489 } 490 else if( tr_bencIsList( tmp ) ) /* original protocol */ 491 { 492 size_t byteCount = 0; 493 uint8_t * array = parseOldPeers( tmp, &byteCount ); 494 publishNewPeers( t, allAreSeeds, array, byteCount ); 495 tr_free( array ); 496 } 489 publishNewPeersCompact( t, allAreSeeds, raw, rawlen ); 497 490 } 498 499 if( ( tmp = tr_bencDictFind( &benc, "peers6" ) ) ) 491 else if( tr_bencDictFindList( &benc, "peers", &tmp ) ) 500 492 { 493 /* original version of peers */ 501 494 const int allAreSeeds = incomplete == 0; 502 503 if( tr_bencIsString( tmp ) ) /* "compact" extension */ 504 { 505 publishNewPeersCompact6( t, allAreSeeds, tmp->val.s.s, 506 tmp->val.s.i ); 507 } 495 size_t byteCount = 0; 496 uint8_t * array = parseOldPeers( tmp, &byteCount ); 497 publishNewPeers( t, allAreSeeds, array, byteCount ); 498 tr_free( array ); 499 } 500 501 if( tr_bencDictFindRaw( &benc, "peers6", &raw, &rawlen ) ) 502 { 503 /* "compact" extension */ 504 const int allAreSeeds = incomplete == 0; 505 publishNewPeersCompact6( t, allAreSeeds, raw, rawlen ); 508 506 } 509 507 } … … 625 623 if( bencLoaded && tr_bencDictFindDict( &benc, "files", &files ) ) 626 624 { 627 size_t i; 628 for( i = 0; i < files->val.l.count; i += 2 ) 625 const char * key; 626 tr_benc * val; 627 int i = 0; 628 while( tr_bencDictChild( files, i++, &key, &val )) 629 629 { 630 int64_t itmp; 631 const uint8_t* hash = 632 (const uint8_t*) files->val.l.vals[i].val.s.s; 633 tr_benc * flags; 634 tr_benc * tordict = &files->val.l.vals[i + 1]; 635 if( memcmp( t->hash, hash, SHA_DIGEST_LENGTH ) ) 630 int64_t intVal; 631 tr_benc * flags; 632 633 if( memcmp( t->hash, key, SHA_DIGEST_LENGTH ) ) 636 634 continue; 637 635 638 636 publishErrorClear( t ); 639 637 640 if( ( tr_bencDictFindInt( tordict, "complete", &itmp) ) )641 t->seederCount = i tmp;642 643 if( ( tr_bencDictFindInt( tordict, "incomplete", &itmp) ) )644 t->leecherCount = i tmp;645 646 if( ( tr_bencDictFindInt( tordict, "downloaded", &itmp) ) )647 t->timesDownloaded = i tmp;648 649 if( ( tr_bencDictFindInt( tordict, "downloaders", &itmp) ) )650 t->downloaderCount = i tmp;651 652 if( tr_bencDictFindDict( tordict, "flags", &flags ) )653 if( ( tr_bencDictFindInt( flags, "min_request_interval", &i tmp) ) )654 t->scrapeIntervalSec = i tmp;638 if( ( tr_bencDictFindInt( val, "complete", &intVal ) ) ) 639 t->seederCount = intVal; 640 641 if( ( tr_bencDictFindInt( val, "incomplete", &intVal ) ) ) 642 t->leecherCount = intVal; 643 644 if( ( tr_bencDictFindInt( val, "downloaded", &intVal ) ) ) 645 t->timesDownloaded = intVal; 646 647 if( ( tr_bencDictFindInt( val, "downloaders", &intVal ) ) ) 648 t->downloaderCount = intVal; 649 650 if( tr_bencDictFindDict( val, "flags", &flags ) ) 651 if( ( tr_bencDictFindInt( flags, "min_request_interval", &intVal ) ) ) 652 t->scrapeIntervalSec = intVal; 655 653 656 654 /* as per ticket #1045, safeguard against trackers returning
Note: See TracChangeset
for help on using the changeset viewer.