~ubuntu-branches/ubuntu/maverick/transmission/maverick-updates

« back to all changes in this revision

Viewing changes to libtransmission/tracker.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson, Krzysztof Klimonda, Chris Coulson
  • Date: 2009-09-09 09:06:11 UTC
  • mfrom: (1.1.27 upstream)
  • Revision ID: james.westby@ubuntu.com-20090909090611-09ai2hyo66h1dhv8
Tags: 1.74-0ubuntu1
[ Krzysztof Klimonda ]
* Merge from debian unstable, remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
    + add liblaunchpad-integration to Build-Depends
  - debian/rules:
    + Create a PO template during package build.
  - debian/patches/01_lpi.patch:
    + Integrate Transmission with Launchpad
  - debian/patches/20_add_X-Ubuntu-Gettext-Domain.diff:
    + Add X-Ubuntu-Gettext-Domain to .desktop file.
* debian/control:
  - add lsb-release to Build-Depends
* This includes the QT client in transmission-qt.

[ Chris Coulson ]
* Update to new upstream version 1.74 (LP: #418367):
  - Better data recovery in the case of an OS or Transmission crash
  - If a data file is moved, stop the torrent instead of redownloading 
    it (LP: #419304).
  - Fix bug that didn't list some peers in the resume file and in PEX
  - More helpful torrent error messages
  - DHT now honors the bind-address-ipv4 configuration option
  - Fix Debian build error with miniupnpc
  - Fix Cygwin build error with strtold
  - Update to a newer snapshot of miniupnpc
  - Fix crash that occurred when adding torrents on some desktops
  - Synchronize the statusbar's and torrent list's speeds
  - Fix the Properties dialog's "Origin" field for multiple torrents
* debian/rules, debian/control:
  - Don't run autoreconf at build time and don't build-dep on libtool.
* debian/control:
  - transmission-common replaces transmission-gtk (<< 1.74) rather than
    (<= 1.73-1).
* Refreshed patches:
  - 01_lpi.patch.
  - dont_build_libevent.patch.
  - qt_client_use_system_libevent.patch.
* Dropped patches not needed anymore:
  - updateminiupnpcstrings_double_escape_slash.patch
* Added 99_autoreconf.patch for autotools update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: tracker.c 8767 2009-07-01 14:58:57Z charles $
 
10
 * $Id: tracker.c 8905 2009-08-12 20:12:52Z charles $
11
11
 */
12
12
 
13
13
#include <assert.h>
48
48
    DEFAULT_SCRAPE_INTERVAL_SEC = ( 60 * 15 ),
49
49
 
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 ),
52
52
 
53
53
    /* unless the tracker says otherwise, this is the announce min_interval */
54
54
    DEFAULT_ANNOUNCE_MIN_INTERVAL_SEC = ( 60 * 2 ),
122
122
    time_t    scrapeAt;
123
123
 
124
124
    time_t    lastScrapeTime;
125
 
    long      lastScrapeResponse;
 
125
    char      lastScrapeStr[128];
126
126
 
127
127
    time_t    lastAnnounceTime;
128
 
    long      lastAnnounceResponse;
 
128
    char      lastAnnounceStr[128];
129
129
};
130
130
 
131
131
#define dbgmsg( name, ... ) \
253
253
    const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 );
254
254
    tr_address addr;
255
255
    tr_port port;
256
 
    
 
256
 
257
257
    addr.type = TR_AF_INET;
258
258
    memset( &addr.addr, 0x00, sizeof( addr.addr ) );
259
259
    array = tr_new( uint8_t, arrayLen );
261
261
    {
262
262
        memcpy( &addr.addr.addr4, compactWalk, 4 );
263
263
        memcpy( &port, compactWalk + 4, 2 );
264
 
        
 
264
 
265
265
        memcpy( walk, &addr, sizeof( addr ) );
266
266
        memcpy( walk + sizeof( addr ), &port, 2 );
267
 
        
 
267
 
268
268
        walk += sizeof( tr_address ) + 2;
269
269
        compactWalk += 6;
270
270
    }
285
285
    const int arrayLen = peerCount * ( sizeof( tr_address ) + 2 );
286
286
    tr_address addr;
287
287
    tr_port port;
288
 
    
 
288
 
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;
297
 
        
 
297
 
298
298
        memcpy( walk, &addr, sizeof( addr ) );
299
299
        memcpy( walk + sizeof( addr ), &port, 2 );
300
300
        walk += sizeof( tr_address ) + 2;
420
420
 
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';
424
424
 
425
425
    if( responseCode == HTTP_OK )
426
426
    {
442
442
 
443
443
            if( tr_bencDictFindStr( &benc, "failure reason", &str ) )
444
444
            {
 
445
                tr_strlcpy( t->lastAnnounceStr, str, sizeof( t->lastAnnounceStr ) );
445
446
                publishMessage( t, str, TR_TRACKER_ERROR );
446
447
                success = FALSE;
447
448
            }
448
449
 
449
450
            if( tr_bencDictFindStr( &benc, "warning message", &str ) )
 
451
            {
 
452
                tr_strlcpy( t->lastAnnounceStr, str, sizeof( t->lastAnnounceStr ) );
450
453
                publishWarning( t, str );
 
454
            }
451
455
 
452
456
            if( tr_bencDictFindInt( &benc, "interval", &i ) )
453
457
            {
504
508
                const int allAreSeeds = incomplete == 0;
505
509
                publishNewPeersCompact6( t, allAreSeeds, raw, rawlen );
506
510
            }
 
511
 
 
512
            if( !*t->lastAnnounceStr )
 
513
                tr_strlcpy( t->lastAnnounceStr, _( "Success" ), sizeof( t->lastAnnounceStr ) );
507
514
        }
508
515
 
509
516
        if( bencLoaded )
513
520
    {
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)" ),
517
524
                                      responseCode,
518
525
                                      tr_webGetResponseStr( responseCode ) );
 
526
        tr_strlcpy( t->lastAnnounceStr, buf, sizeof( t->lastAnnounceStr ) );
519
527
        publishWarning( t, buf );
520
528
        tr_free( buf );
521
529
    }
 
530
    else
 
531
    {
 
532
        tr_strlcpy( t->lastAnnounceStr, _( "Announce failed: tracker did not respond." ), sizeof( t->lastAnnounceStr ) );
 
533
    }
522
534
 
523
535
    retry = updateAddresses( t, success );
524
536
 
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;
546
557
        }
553
564
 
554
565
        t->reannounceAt = now + interval;
555
566
        t->manualAnnounceAllowedAt = now + t->announceMinIntervalSec;
556
 
 
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 ) );
560
567
    }
561
568
    else if( 300 <= responseCode && responseCode <= 399 )
562
569
    {
613
620
 
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';
617
624
 
618
625
    if( responseCode == HTTP_OK )
619
626
    {
681
688
    if( 200 <= responseCode && responseCode <= 299 )
682
689
    {
683
690
        const int interval = t->scrapeIntervalSec + t->randOffset;
684
 
        dbgmsg( t->name, "Request succeeded. Rescraping in %d seconds",
685
 
                interval );
686
 
        tr_ndbg( t->name, "Request succeeded. Rescraping in %d seconds",
687
 
                 interval );
688
691
        t->scrapeAt = time( NULL ) + interval;
 
692
 
 
693
        tr_strlcpy( t->lastScrapeStr, _( "Success" ), sizeof( t->lastScrapeStr ) );
 
694
        tr_ndbg( t->name, "Request succeeded. Rescraping in %d seconds", interval );
689
695
    }
690
696
    else if( 300 <= responseCode && responseCode <= 399 )
691
697
    {
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;
 
700
 
 
701
        tr_snprintf( t->lastScrapeStr, sizeof( t->lastScrapeStr ), "Got a redirect. Retrying in %d seconds", interval );
 
702
        tr_ndbg( t->name, "%s", t->lastScrapeStr );
695
703
    }
696
704
    else
697
705
    {
698
706
        const int interval = t->retryScrapeIntervalSec + t->randOffset;
699
 
        dbgmsg(
700
 
            t->name,
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;
 
709
 
 
710
        /* %1$ld - http status code, such as 404
 
711
         * %2$s - human-readable explanation of the http status code */
 
712
        if( !responseCode )
 
713
            tr_strlcpy( t->lastScrapeStr, _( "Scrape failed: tracker did not respond." ), sizeof( t->lastScrapeStr ) );
 
714
        else
 
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 ) );
705
718
    }
 
719
 
 
720
    dbgmsg( t->name, "%s", t->lastScrapeStr );
706
721
}
707
722
 
708
723
/***
968
983
          && ( t->scrapeAt <= now )
969
984
          && ( trackerSupportsScrape( t, tor ) ) )
970
985
        {
971
 
            t->scrapeAt = TR_TRACKER_BUSY;
972
 
            enqueueScrape( session, t );
 
986
            if( ( tor->error == TR_STAT_TRACKER_ERROR ) || ( tor->error == TR_STAT_LOCAL_ERROR ) )
 
987
            {
 
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;
 
991
            }
 
992
            else
 
993
            {
 
994
                t->scrapeAt = TR_TRACKER_BUSY;
 
995
                enqueueScrape( session, t );
 
996
            }
973
997
        }
974
998
 
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;
1246
 
 
1247
 
    if( t->lastScrapeResponse == -1 ) /* never been scraped */
1248
 
        *setme->scrapeResponse = '\0';
1249
 
    else
1250
 
        tr_snprintf( setme->scrapeResponse,
1251
 
                     sizeof( setme->scrapeResponse ),
1252
 
                     "%s (%ld)",
1253
 
                     tr_webGetResponseStr( t->lastScrapeResponse ),
1254
 
                     t->lastScrapeResponse );
1255
 
 
1256
 
    if( t->lastAnnounceResponse == -1 ) /* never been announced */
1257
 
        *setme->announceResponse = '\0';
1258
 
    else
1259
 
        tr_snprintf( setme->announceResponse,
1260
 
                     sizeof( setme->announceResponse ),
1261
 
                     "%s (%ld)",
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 ) );
1264
1270
}
1265