48
48
DEFAULT_SCRAPE_INTERVAL_SEC = ( 60 * 15 ),
50
50
/* unless the tracker says otherwise, this is the announce interval */
51
DEFAULT_ANNOUNCE_INTERVAL_SEC = ( 60 * 4 ),
51
DEFAULT_ANNOUNCE_INTERVAL_SEC = ( 60 * 10 ),
53
53
/* unless the tracker says otherwise, this is the announce min_interval */
54
54
DEFAULT_ANNOUNCE_MIN_INTERVAL_SEC = ( 60 * 2 ),
253
253
const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 );
257
257
addr.type = TR_AF_INET;
258
258
memset( &addr.addr, 0x00, sizeof( addr.addr ) );
259
259
array = tr_new( uint8_t, arrayLen );
262
262
memcpy( &addr.addr.addr4, compactWalk, 4 );
263
263
memcpy( &port, compactWalk + 4, 2 );
265
265
memcpy( walk, &addr, sizeof( addr ) );
266
266
memcpy( walk + sizeof( addr ), &port, 2 );
268
268
walk += sizeof( tr_address ) + 2;
269
269
compactWalk += 6;
285
285
const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 );
289
289
addr.type = TR_AF_INET6;
290
290
memset( &addr.addr, 0x00, sizeof( addr.addr ) );
291
291
array = tr_new( uint8_t, arrayLen );
294
294
memcpy( &addr.addr.addr6, compactWalk, 16 );
295
295
memcpy( &port, compactWalk + 16, 2 );
296
296
compactWalk += 18;
298
298
memcpy( walk, &addr, sizeof( addr ) );
299
299
memcpy( walk + sizeof( addr ), &port, 2 );
300
300
walk += sizeof( tr_address ) + 2;
421
421
dbgmsg( t->name, "tracker response: %ld", responseCode );
422
422
tr_ndbg( t->name, "tracker response: %ld", responseCode );
423
t->lastAnnounceResponse = responseCode;
423
t->lastAnnounceStr[0] = '\0';
425
425
if( responseCode == HTTP_OK )
443
443
if( tr_bencDictFindStr( &benc, "failure reason", &str ) )
445
tr_strlcpy( t->lastAnnounceStr, str, sizeof( t->lastAnnounceStr ) );
445
446
publishMessage( t, str, TR_TRACKER_ERROR );
449
450
if( tr_bencDictFindStr( &benc, "warning message", &str ) )
452
tr_strlcpy( t->lastAnnounceStr, str, sizeof( t->lastAnnounceStr ) );
450
453
publishWarning( t, str );
452
456
if( tr_bencDictFindInt( &benc, "interval", &i ) )
504
508
const int allAreSeeds = incomplete == 0;
505
509
publishNewPeersCompact6( t, allAreSeeds, raw, rawlen );
512
if( !*t->lastAnnounceStr )
513
tr_strlcpy( t->lastAnnounceStr, _( "Success" ), sizeof( t->lastAnnounceStr ) );
514
521
/* %1$ld - http status code, such as 404
515
522
* %2$s - human-readable explanation of the http status code */
516
char * buf = tr_strdup_printf( _( "Tracker request failed. Got HTTP Status Code %1$ld (%2$s)" ),
523
char * buf = tr_strdup_printf( _( "Announce failed: tracker gave HTTP Response Code %1$ld (%2$s)" ),
518
525
tr_webGetResponseStr( responseCode ) );
526
tr_strlcpy( t->lastAnnounceStr, buf, sizeof( t->lastAnnounceStr ) );
519
527
publishWarning( t, buf );
532
tr_strlcpy( t->lastAnnounceStr, _( "Announce failed: tracker did not respond." ), sizeof( t->lastAnnounceStr ) );
523
535
retry = updateAddresses( t, success );
540
552
/* if the announce response was a superset of the scrape response,
541
553
treat this as both a successful announce AND scrape. */
542
554
if( scrapeFields >= 3 ) {
543
t->lastScrapeResponse = responseCode;
544
555
t->lastScrapeTime = now;
545
556
t->scrapeAt = now + t->scrapeIntervalSec + t->randOffset;
554
565
t->reannounceAt = now + interval;
555
566
t->manualAnnounceAllowedAt = now + t->announceMinIntervalSec;
557
/* #319: save the .resume file after an announce so that, in case
558
* of a crash, our stats still match up with the tracker's stats */
559
tr_torrentSaveResume( tr_torrentFindFromHash( t->session, t->hash ) );
561
568
else if( 300 <= responseCode && responseCode <= 399 )
614
621
dbgmsg( t->name, "scrape response: %ld\n", responseCode );
615
622
tr_ndbg( t->name, "scrape response: %ld", responseCode );
616
t->lastScrapeResponse = responseCode;
623
t->lastScrapeStr[0] = '\0';
618
625
if( responseCode == HTTP_OK )
681
688
if( 200 <= responseCode && responseCode <= 299 )
683
690
const int interval = t->scrapeIntervalSec + t->randOffset;
684
dbgmsg( t->name, "Request succeeded. Rescraping in %d seconds",
686
tr_ndbg( t->name, "Request succeeded. Rescraping in %d seconds",
688
691
t->scrapeAt = time( NULL ) + interval;
693
tr_strlcpy( t->lastScrapeStr, _( "Success" ), sizeof( t->lastScrapeStr ) );
694
tr_ndbg( t->name, "Request succeeded. Rescraping in %d seconds", interval );
690
696
else if( 300 <= responseCode && responseCode <= 399 )
692
698
const int interval = 5;
693
dbgmsg( t->name, "Got a redirect. Retrying in %d seconds", interval );
694
699
t->scrapeAt = time( NULL ) + interval;
701
tr_snprintf( t->lastScrapeStr, sizeof( t->lastScrapeStr ), "Got a redirect. Retrying in %d seconds", interval );
702
tr_ndbg( t->name, "%s", t->lastScrapeStr );
698
706
const int interval = t->retryScrapeIntervalSec + t->randOffset;
701
"Tracker responded to scrape with %ld. Retrying in %d seconds.",
702
responseCode, interval );
703
707
t->retryScrapeIntervalSec *= 2;
704
708
t->scrapeAt = time( NULL ) + interval;
710
/* %1$ld - http status code, such as 404
711
* %2$s - human-readable explanation of the http status code */
713
tr_strlcpy( t->lastScrapeStr, _( "Scrape failed: tracker did not respond." ), sizeof( t->lastScrapeStr ) );
715
tr_snprintf( t->lastScrapeStr, sizeof( t->lastScrapeStr ),
716
_( "Scrape failed: tracker gave HTTP Response Code %1$ld (%2$s)" ),
717
responseCode, tr_webGetResponseStr( responseCode ) );
720
dbgmsg( t->name, "%s", t->lastScrapeStr );
968
983
&& ( t->scrapeAt <= now )
969
984
&& ( trackerSupportsScrape( t, tor ) ) )
971
t->scrapeAt = TR_TRACKER_BUSY;
972
enqueueScrape( session, t );
986
if( ( tor->error == TR_STAT_TRACKER_ERROR ) || ( tor->error == TR_STAT_LOCAL_ERROR ) )
988
/* keep deferring the scrape until the errors are resolved.
989
there's no point in wasting a round trip on this torrent until then. */
990
t->scrapeAt = now + t->scrapeIntervalSec + t->randOffset;
994
t->scrapeAt = TR_TRACKER_BUSY;
995
enqueueScrape( session, t );
975
999
if( ( t->reannounceAt > 1 )
1082
1106
t->seederCount = -1;
1083
1107
t->downloaderCount = -1;
1084
1108
t->leecherCount = -1;
1085
t->lastAnnounceResponse = -1;
1086
t->lastScrapeResponse = -1;
1087
1109
t->manualAnnounceAllowedAt = ~(time_t)0;
1088
1110
t->name = tr_strdup( info->name );
1089
1111
t->torrentId = torrent->uniqueId;
1243
1265
setme->lastAnnounceTime = t->lastAnnounceTime;
1244
1266
setme->nextAnnounceTime = t->reannounceAt;
1245
1267
setme->manualAnnounceTime = t->manualAnnounceAllowedAt;
1247
if( t->lastScrapeResponse == -1 ) /* never been scraped */
1248
*setme->scrapeResponse = '\0';
1250
tr_snprintf( setme->scrapeResponse,
1251
sizeof( setme->scrapeResponse ),
1253
tr_webGetResponseStr( t->lastScrapeResponse ),
1254
t->lastScrapeResponse );
1256
if( t->lastAnnounceResponse == -1 ) /* never been announced */
1257
*setme->announceResponse = '\0';
1259
tr_snprintf( setme->announceResponse,
1260
sizeof( setme->announceResponse ),
1262
tr_webGetResponseStr( t->lastAnnounceResponse ),
1263
t->lastAnnounceResponse );
1268
tr_strlcpy( setme->scrapeResponse, t->lastScrapeStr, sizeof( setme->scrapeResponse ) );
1269
tr_strlcpy( setme->announceResponse, t->lastAnnounceStr, sizeof( setme->announceResponse ) );