Changeset 2554


Ignore:
Timestamp:
Jul 30, 2007, 5:11:00 PM (14 years ago)
Author:
charles
Message:

(libT) get "update tracker" working again.
(gtk) add "update tracker" button.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r2553 r2554  
    8282    N_("Show _Debug Window"), NULL, NULL, G_CALLBACK(action_cb) },
    8383  { "toggle-main-window", "ICON_TRANSMISSION",
    84     N_("Show / Hide _Transmission"), NULL, NULL, G_CALLBACK(action_cb) }
     84    N_("Show / Hide _Transmission"), NULL, NULL, G_CALLBACK(action_cb) },
     85  { "update-tracker", GTK_STOCK_REFRESH,
     86    N_("Update Tracker"), NULL, NULL, G_CALLBACK(action_cb) }
    8587};
    8688
  • trunk/gtk/main.c

    r2553 r2554  
    186186
    187187static void
     188accumulateCanUpdateForeach (GtkTreeModel * model,
     189                            GtkTreePath  * path UNUSED,
     190                            GtkTreeIter  * iter,
     191                            gpointer       accumulated_status)
     192{
     193    TrTorrent * gtor = NULL;
     194    gtk_tree_model_get( model, iter, MC_TORRENT, &gtor, -1 );
     195    *(int*)accumulated_status |=
     196        tr_torrentCanManualUpdate( tr_torrent_handle( gtor ) );
     197    g_object_unref( G_OBJECT( gtor ) );
     198}
     199
     200static void
    188201refreshTorrentActions( GtkTreeSelection * s )
    189202{
     
    195208    action_sensitize( "recheck-torrent", status != 0);
    196209    action_sensitize( "show-torrent-inspector", status != 0);
     210
     211    status = 0;
     212    gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &status );
     213    action_sensitize( "update-tracker", status != 0);
    197214}
    198215
     
    931948
    932949static void
     950updateTrackerForeach (GtkTreeModel * model,
     951                      GtkTreePath  * path UNUSED,
     952                      GtkTreeIter  * iter,
     953                      gpointer       data UNUSED)
     954{
     955    TrTorrent * tor = NULL;
     956    gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
     957    tr_manualUpdate( tr_torrent_handle( tor ) );
     958    g_object_unref( G_OBJECT( tor ) );
     959}
     960
     961static void
    933962showInfoForeach (GtkTreeModel * model,
    934963                 GtkTreePath  * path UNUSED,
     
    9881017        GtkTreeSelection * s = tr_window_get_selection(data->wind);
    9891018        gtk_tree_selection_selected_foreach( s, showInfoForeach, data->wind );
     1019    }
     1020    else if (!strcmp( action_name, "update-tracker"))
     1021    {
     1022        GtkTreeSelection * s = tr_window_get_selection(data->wind);
     1023        gtk_tree_selection_selected_foreach( s, updateTrackerForeach, data->wind );
    9901024    }
    9911025    else if (!strcmp (action_name, "create-torrent"))
  • trunk/gtk/ui.h

    r2553 r2554  
    55"      <menuitem action='add-torrent'/>\n"
    66"      <menuitem action='start-torrent'/>\n"
     7"      <menuitem action='update-tracker'/>\n"
    78"      <menuitem action='stop-torrent'/>\n"
    89"      <menuitem action='recheck-torrent'/>\n"
  • trunk/libtransmission/torrent.c

    r2552 r2554  
    592592}
    593593
    594 void tr_manualUpdate( tr_torrent_t * tor UNUSED )
    595 {
    596 #if 0
    597     int peerCount, new;
    598     uint8_t * peerCompact;
    599 
    600     if( tor->status != TR_RUN_RUNNING )
    601         return;
    602    
    603     tr_torrentWriterLock( tor );
    604     tr_trackerAnnouncePulse( tor->tracker, &peerCount, &peerCompact, 1 );
    605     new = 0;
    606     if( peerCount > 0 )
    607     {
    608         new = tr_torrentAddCompact( tor, TR_PEER_FROM_TRACKER,
    609                                     peerCompact, peerCount );
    610         free( peerCompact );
    611     }
    612     tr_dbg( "got %i peers from manual announce, used %i", peerCount, new );
    613     tr_torrentWriterUnlock( tor );
    614 #endif
     594void
     595tr_manualUpdate( tr_torrent_t * tor )
     596{
     597    if( tor->runStatus == TR_RUN_RUNNING )
     598        tr_trackerManualAnnounce( tor->tracker );
     599}
     600int
     601tr_torrentCanManualUpdate( const tr_torrent_t * tor )
     602{
     603    return ( tor != NULL )
     604        && ( tor->runStatus == TR_RUN_RUNNING )
     605        && ( tr_trackerCanManualAnnounce( tor->tracker ) );
    615606}
    616607
  • trunk/libtransmission/tracker.c

    r2544 r2554  
    3939#include "shared.h"
    4040
     41/* Users aren't allowed to make a manual announce more often than this. */
     42static const int MANUAL_ANNOUNCE_INTERVAL_MSEC = (60*1000);
     43
    4144struct tclist
    4245{
     
    4750SLIST_HEAD( tchead, tclist );
    4851
     52typedef uint8_t tr_flag_t;
     53
    4954struct tr_tracker_s
    5055{
     
    6368#define TC_CHANGE_NONEXT    2
    6469#define TC_CHANGE_REDIRECT  4
    65     int            shouldChangeAnnounce;
     70    uint8_t        shouldChangeAnnounce;
    6671   
    6772    char         * redirectAddress;
     
    7075    int            redirectScrapeAddressLen;
    7176
    72     char           started;
    73     char           completed;
    74     char           stopped;
     77    tr_flag_t      started;
     78    tr_flag_t      completed;
     79    tr_flag_t      stopped;
     80    tr_flag_t      forceAnnounce;
    7581
    7682    int            interval;
     
    7985    int            seeders;
    8086    int            leechers;
    81     int            hasManyPeers;
    8287    int            complete;
    8388    int            randOffset;
    8489
    85     int            completelyUnconnectable;
    86     int            allUnreachIfError;
    87     int            lastError;
     90    tr_flag_t      hasManyPeers;
     91    tr_flag_t      completelyUnconnectable;
     92    tr_flag_t      allUnreachIfError;
     93    tr_flag_t      lastError;
    8894
    8995    uint64_t       dateTry;
    9096    uint64_t       dateOk;
    9197    uint64_t       dateScrape;
    92     int            lastScrapeFailed;
    93     int            scrapeNeeded;
     98    tr_flag_t      lastScrapeFailed;
     99    tr_flag_t      scrapeNeeded;
    94100
    95101    tr_http_t    * http;
     
    191197}
    192198
     199int
     200tr_trackerCanManualAnnounce( const tr_tracker_t * tc )
     201{
     202    return tc && ((tc->dateOk + MANUAL_ANNOUNCE_INTERVAL_MSEC) < tr_date());
     203}
     204
    193205static int shouldConnect( tr_tracker_t * tc )
    194206{
    195207    tr_torrent_t * tor = tc->tor;
    196208    const uint64_t now = tr_date();
     209
     210    /* User has requested a manual announce
     211       and it's been long enough since the last one */
     212    if( tc->forceAnnounce && tr_trackerCanManualAnnounce(tc) )
     213        return 1;
    197214   
    198215    /* Last tracker failed, try next */
     
    302319
    303320    return now > tc->dateScrape + interval;
     321}
     322
     323void
     324tr_trackerManualAnnounce( tr_tracker_t * tc )
     325{
     326    if( tc != NULL )
     327        tc->forceAnnounce = 1;
    304328}
    305329
     
    839863nodict:
    840864    /* Success */
    841     tc->started   = 0;
    842     tc->completed = 0;
    843     tc->dateOk    = tr_date();
     865    tc->started       = 0;
     866    tc->completed     = 0;
     867    tc->dateOk        = tr_date();
     868    tc->forceAnnounce = FALSE;
    844869
    845870    if( tc->stopped )
  • trunk/libtransmission/tracker.h

    r2358 r2554  
    3737void           tr_trackerStopped  ( tr_tracker_t * );
    3838void           tr_trackerClose    ( tr_tracker_t * );
     39
     40/* if a tracker is running, enqueue a manual announce. */
     41void tr_trackerManualAnnounce( tr_tracker_t * );
     42
     43int tr_trackerCanManualAnnounce( const tr_tracker_t * );
    3944
    4045/***********************************************************************
  • trunk/libtransmission/transmission.h

    r2531 r2554  
    433433
    434434
    435 /***********************************************************************
    436  * tr_manualUpdate
    437  ***********************************************************************
    438  * Reannounce to tracker regardless of wait interval
    439  **********************************************************************/
     435/**
     436 * MANUAL ANNOUNCE
     437 *
     438 * Trackers usually set an announce interval of 15 or 30 minutes.
     439 * Users can send one-time announce requests that override this
     440 * interval by calling tr_manualUpdate().
     441 *
     442 * The wait interval for tr_manualUpdate() is much smaller.
     443 * You can test whether or not a manual update is possible
     444 * (for example, to desensitize the button) by calling
     445 * tr_torrentCanManualUpdate().
     446 */
     447
    440448void tr_manualUpdate( tr_torrent_t * );
     449
     450int tr_torrentCanManualUpdate( const tr_torrent_t * );
    441451
    442452/***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.