Changeset 8132


Ignore:
Timestamp:
Apr 4, 2009, 5:29:08 AM (13 years ago)
Author:
charles
Message:

(trunk)

  1. add to the "recently-changed" torrent a list of recently-removed torrent ids.
  2. make the day-of-week alt speed a bitfield of days or'ed together, so that you can have (say) speed limits on monday and wednesday
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/rpc-spec.txt

    r8130 r8132  
    132132   (1) A "torrents" array of objects, each of which contains
    133133       the key/value pairs matching the request's "fields" argument.
     134   (2) If the request's "ids" field was "recently-active",
     135       a "removed" array of torrent-id numbers of recently-removed
     136       torrents.
    134137
    135138   key                             | type                        | source
  • trunk/libtransmission/rpcimpl.c

    r8130 r8132  
    2929#include "utils.h"
    3030#include "web.h"
     31
     32#define RECENTLY_ACTIVE_SECONDS 60
    3133
    3234#define TR_N_ELEMENTS( ary ) ( sizeof( ary ) / sizeof( *ary ) )
     
    149151            tr_torrent * tor = NULL;
    150152            const time_t now = time( NULL );
    151             const time_t window = 60;
     153            const time_t window = RECENTLY_ACTIVE_SECONDS;
    152154            const int n = tr_sessionCountTorrents( session );
    153155            torrents = tr_new0( tr_torrent *, n );
     
    591593    tr_benc *     fields;
    592594    const char *  msg = NULL;
     595    const char *  strVal;
    593596
    594597    assert( idle_data == NULL );
     598
     599    if( tr_bencDictFindStr( args_in, "ids", &strVal ) && !strcmp( strVal, "recently-active" ) ) {
     600        int n = 0;
     601        tr_benc * d;
     602        const time_t now = time( NULL );
     603        const int interval = RECENTLY_ACTIVE_SECONDS;
     604        tr_benc * removed_out = tr_bencDictAddList( args_out, "removed", 0 );
     605        while(( d = tr_bencListChild( &session->removedTorrents, n++ ))) {
     606            int64_t intVal;
     607            if( tr_bencDictFindInt( d, "date", &intVal ) && ( intVal >= now - interval ) ) {
     608                tr_bencDictFindInt( d, "id", &intVal );
     609                tr_bencListAddInt( removed_out, intVal );
     610            }
     611        }
     612    }
    595613
    596614    if( !tr_bencDictFindList( args_in, "fields", &fields ) )
  • trunk/libtransmission/session.c

    r8130 r8132  
    232232    if( toNextDay && (minutes < end) )
    233233        day = (day - 1) % 7;
    234    
    235     if( s->altSpeedTimeDay == TR_SCHED_ALL )
    236         return TRUE;
    237     else if( s->altSpeedTimeDay == TR_SCHED_WEEKDAY )
    238         return (day != 0) && day != 6;
    239     else if( s->altSpeedTimeDay == TR_SCHED_WEEKEND )
    240         return (day == 0) || (day == 6);
    241     else
    242         return day == s->altSpeedTimeDay;
     234
     235    return ((1<<day) & s->altSpeedTimeDay) != 0;
    243236}
    244237
     
    469462    session->tag = tr_strdup( tag );
    470463    session->magicNumber = SESSION_MAGIC_NUMBER;
     464    tr_bencInitList( &session->removedTorrents, 0 );
    471465
    472466    /* start the libtransmission thread */
     
    999993                day = (day - 1) % 7;
    1000994           
    1001             if( session->altSpeedTimeDay == TR_SCHED_ALL )
    1002                 isDay = TRUE;
    1003             else if( session->altSpeedTimeDay == TR_SCHED_WEEKDAY )
    1004                 isDay = (day != 0) && (day != 6);
    1005             else if( session->altSpeedTimeDay == TR_SCHED_WEEKEND )
    1006                 isDay = (day == 0) || (day == 6);
    1007             else
    1008                 isDay = day == session->altSpeedTimeDay;
     995            isDay = ((1<<day) & session->altSpeedTimeDay) != 0;
    1009996
    1010997            if( isDay )
     
    13961383
    13971384    /* free the session memory */
     1385    tr_bencFree( &session->removedTorrents );
    13981386    tr_bandwidthFree( session->bandwidth );
    13991387    tr_lockFree( session->lock );
  • trunk/libtransmission/session.h

    r8130 r8132  
    4040#endif
    4141
     42#include "bencode.h"
    4243
    4344typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
     
    6970    tr_bool                      isRatioLimited;
    7071
     72    tr_benc                      removedTorrents;
    7173   
    7274    int                          speedLimit[2];
  • trunk/libtransmission/torrent.c

    r8124 r8132  
    13311331closeTorrent( void * vtor )
    13321332{
     1333    tr_benc * d;
    13331334    tr_torrent * tor = vtor;
    13341335
    13351336    assert( tr_isTorrent( tor ) );
     1337
     1338    d = tr_bencListAddDict( &tor->session->removedTorrents, 2 );
     1339    tr_bencDictAddInt( d, "id", tor->uniqueId );
     1340    tr_bencDictAddInt( d, "date", time( NULL ) );
    13361341
    13371342    tr_torrentSaveResume( tor );
  • trunk/libtransmission/transmission.h

    r8130 r8132  
    606606typedef enum
    607607{
    608     TR_SCHED_SUN = 0, //specific days correspond to stuct tm's tm_wday
    609     TR_SCHED_MON,
    610     TR_SCHED_TUES,
    611     TR_SCHED_WED,
    612     TR_SCHED_THURS,
    613     TR_SCHED_FRI,
    614     TR_SCHED_SAT,
    615     TR_SCHED_WEEKDAY,
    616     TR_SCHED_WEEKEND,
    617     TR_SCHED_ALL
     608    TR_SCHED_SUN      = (1<<0),
     609    TR_SCHED_MON      = (1<<1),
     610    TR_SCHED_TUES     = (1<<2),
     611    TR_SCHED_WED      = (1<<3),
     612    TR_SCHED_THURS    = (1<<4),
     613    TR_SCHED_FRI      = (1<<4),
     614    TR_SCHED_SAT      = (1<<5),
     615    TR_SCHED_WEEKDAY  = (TR_SCHED_MON|TR_SCHED_TUES|TR_SCHED_WED|TR_SCHED_THURS|TR_SCHED_FRI),
     616    TR_SCHED_WEEKEND  = (TR_SCHED_SUN|TR_SCHED_SAT),
     617    TR_SCHED_ALL      = (TR_SCHED_WEEKDAY|TR_SCHED_WEEKEND)
    618618}
    619619tr_sched_day;
Note: See TracChangeset for help on using the changeset viewer.