~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-updates

« back to all changes in this revision

Viewing changes to libtransmission/tracker.c

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2009-02-27 10:51:53 UTC
  • mfrom: (1.1.22 upstream)
  • Revision ID: james.westby@ubuntu.com-20090227105153-3d73lc7bg0pkfk00
Tags: 1.51-0ubuntu1
* New upstream bug fix release (LP: #335404)
  - Fixes transmission-daemon doesn't consider settings.json (LP: #322449) 
* Removed 01_check_notification_actions.diff: applied upstream 

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 7722 2009-01-16 17:31:10Z charles $
 
10
 * $Id: tracker.c 7897 2009-02-18 02:11:15Z charles $
11
11
 */
12
12
 
13
13
#include <assert.h>
661
661
                    t->scrapeIntervalSec = DEFAULT_SCRAPE_INTERVAL_SEC;
662
662
 
663
663
                tr_ndbg( t->name,
664
 
                         "Scrape successful.  Rescraping in %d seconds.",
 
664
                         "Scrape successful. Rescraping in %d seconds.",
665
665
                         t->scrapeIntervalSec );
666
666
 
667
667
                success = TRUE;
685
685
    if( 200 <= responseCode && responseCode <= 299 )
686
686
    {
687
687
        const int interval = t->scrapeIntervalSec + t->randOffset;
688
 
        dbgmsg( t->name, "request succeeded. rescraping in %d seconds",
 
688
        dbgmsg( t->name, "Request succeeded. Rescraping in %d seconds",
689
689
                interval );
690
 
        tr_ndbg( t->name, "request succeeded. rescraping in %d seconds",
 
690
        tr_ndbg( t->name, "Request succeeded. Rescraping in %d seconds",
691
691
                 interval );
692
692
        t->scrapeAt = time( NULL ) + interval;
693
693
    }
694
694
    else if( 300 <= responseCode && responseCode <= 399 )
695
695
    {
696
696
        const int interval = 5;
697
 
        dbgmsg( t->name, "got a redirect. retrying in %d seconds", interval );
 
697
        dbgmsg( t->name, "Got a redirect. Retrying in %d seconds", interval );
698
698
        t->scrapeAt = time( NULL ) + interval;
699
699
    }
700
700
    else
702
702
        const int interval = t->retryScrapeIntervalSec + t->randOffset;
703
703
        dbgmsg(
704
704
            t->name,
705
 
            "Tracker responded to scrape with %ld.  Retrying in %d seconds.",
 
705
            "Tracker responded to scrape with %ld. Retrying in %d seconds.",
706
706
            responseCode,  interval );
707
707
        t->retryScrapeIntervalSec *= 2;
708
708
        t->scrapeAt = time( NULL ) + interval;
720
720
    TR_REQ_STOPPED,
721
721
    TR_REQ_PAUSED,     /* BEP 21 */
722
722
    TR_REQ_REANNOUNCE,
723
 
    TR_REQ_SCRAPE
 
723
    TR_REQ_SCRAPE,
 
724
    TR_NUM_REQ_TYPES
724
725
};
725
726
 
726
727
struct tr_tracker_request
835
836
 
836
837
struct tr_tracker_handle
837
838
{
 
839
    tr_bool     shutdownHint;
838
840
    int         runningCount;
839
841
    tr_timer *  pulseTimer;
840
842
};
841
843
 
842
844
static int trackerPulse( void * vsession );
843
845
 
844
 
static void
845
 
ensureGlobalsExist( tr_session * session )
 
846
void
 
847
tr_trackerSessionInit( tr_session * session )
846
848
{
847
 
    if( session->tracker == NULL )
848
 
    {
849
 
        session->tracker = tr_new0( struct tr_tracker_handle, 1 );
850
 
        session->tracker->pulseTimer =
851
 
            tr_timerNew( session, trackerPulse, session,
852
 
                         PULSE_INTERVAL_MSEC );
853
 
        dbgmsg( NULL, "creating tracker timer" );
854
 
    }
 
849
    assert( tr_isSession( session ) );
 
850
 
 
851
    session->tracker = tr_new0( struct tr_tracker_handle, 1 );
 
852
    session->tracker->pulseTimer = tr_timerNew( session, trackerPulse, session, PULSE_INTERVAL_MSEC );
 
853
    dbgmsg( NULL, "creating tracker timer" );
855
854
}
856
855
 
857
856
void
858
857
tr_trackerSessionClose( tr_session * session )
859
858
{
 
859
    assert( tr_isSession( session ) );
 
860
 
 
861
    session->tracker->shutdownHint = TRUE;
 
862
}
 
863
 
 
864
static void
 
865
tr_trackerSessionDestroy( tr_session * session )
 
866
{
860
867
    if( session && session->tracker )
861
868
    {
862
869
        dbgmsg( NULL, "freeing tracker timer" );
874
881
invokeRequest( void * vreq )
875
882
{
876
883
    struct tr_tracker_request * req = vreq;
877
 
    tr_tracker * t = findTracker( req->session, req->torrentId );
878
 
 
879
 
    if( t )
 
884
    tr_tracker * t;
 
885
 
 
886
    assert( req != NULL );
 
887
    assert( tr_isSession( req->session ) );
 
888
    assert( req->torrentId >= 0 );
 
889
    assert( req->reqtype >= 0 );
 
890
    assert( req->reqtype < TR_NUM_REQ_TYPES );
 
891
 
 
892
    dbgmsg( NULL, "invokeRequest got session %p, tracker %p", req->session, req->session->tracker );
 
893
 
 
894
    t = findTracker( req->session, req->torrentId );
 
895
 
 
896
    if( t != NULL )
880
897
    {
881
898
        const time_t now = time( NULL );
882
899
 
893
910
        }
894
911
    }
895
912
 
 
913
    assert( req->session->tracker != NULL );
896
914
    ++req->session->tracker->runningCount;
897
915
 
898
916
    tr_webRun( req->session,
907
925
enqueueScrape( tr_session * session,
908
926
               tr_tracker * tracker )
909
927
{
910
 
    struct tr_tracker_request * req = createScrape( session, tracker );
 
928
    struct tr_tracker_request * req;
 
929
    assert( tr_isSession( session ) );
 
930
 
 
931
    req = createScrape( session, tracker );
911
932
    tr_runInEventThread( session, invokeRequest, req );
912
933
}
913
934
 
916
937
                tr_tracker * tracker,
917
938
                int          reqtype )
918
939
{
919
 
    struct tr_tracker_request * req = createRequest( session, tracker, reqtype );
 
940
    struct tr_tracker_request * req;
 
941
    assert( tr_isSession( session ) );
 
942
 
 
943
    req = createRequest( session, tracker, reqtype );
920
944
    tr_runInEventThread( session, invokeRequest, req );
921
945
}
922
946
 
928
952
    tr_torrent *               tor;
929
953
    const time_t               now = time( NULL );
930
954
 
931
 
    if( !session->tracker )
 
955
    if( !th )
932
956
        return FALSE;
933
957
 
934
958
    if( th->runningCount )
963
987
                th->runningCount );
964
988
 
965
989
    /* free the tracker manager if no torrents are left */
966
 
    if( ( session->tracker )
967
 
      && ( session->tracker->runningCount < 1 )
968
 
      && ( tr_sessionCountTorrents( session ) == 0 ) )
 
990
    if(    ( th != NULL )
 
991
        && ( th->shutdownHint != FALSE )
 
992
        && ( th->runningCount < 1 )
 
993
        && ( tr_sessionCountTorrents( session ) == 0 ) )
969
994
    {
970
 
        tr_trackerSessionClose( session );
 
995
        tr_trackerSessionDestroy( session );
 
996
        return FALSE;
971
997
    }
972
998
 
973
 
    /* if there are still running torrents (as indicated by
974
 
     * the existence of the tracker manager) then keep the
975
 
     * trackerPulse() timer alive */
976
 
    return session->tracker != NULL;
 
999
    return TRUE;
977
1000
}
978
1001
 
979
1002
static void
1035
1058
    const tr_info * info = &torrent->info;
1036
1059
    tr_tracker *    t;
1037
1060
 
1038
 
    ensureGlobalsExist( torrent->session );
1039
 
 
1040
1061
    t = tr_new0( tr_tracker, 1 );
1041
1062
    t->publisher                = TR_PUBLISHER_INIT;
1042
1063
    t->session                  = torrent->session;