1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00
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
This commit is contained in:
Charles Kerr 2009-04-04 05:29:08 +00:00
parent d841a1ba47
commit a1adee368f
6 changed files with 44 additions and 28 deletions

View file

@ -131,6 +131,9 @@
(1) A "torrents" array of objects, each of which contains
the key/value pairs matching the request's "fields" argument.
(2) If the request's "ids" field was "recently-active",
a "removed" array of torrent-id numbers of recently-removed
torrents.
key | type | source
--------------------------------+-----------------------------+---------

View file

@ -29,6 +29,8 @@
#include "utils.h"
#include "web.h"
#define RECENTLY_ACTIVE_SECONDS 60
#define TR_N_ELEMENTS( ary ) ( sizeof( ary ) / sizeof( *ary ) )
#if 0
@ -148,7 +150,7 @@ getTorrents( tr_session * session,
{
tr_torrent * tor = NULL;
const time_t now = time( NULL );
const time_t window = 60;
const time_t window = RECENTLY_ACTIVE_SECONDS;
const int n = tr_sessionCountTorrents( session );
torrents = tr_new0( tr_torrent *, n );
while( ( tor = tr_torrentNext( session, tor ) ) )
@ -590,9 +592,25 @@ torrentGet( tr_session * session,
tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount );
tr_benc * fields;
const char * msg = NULL;
const char * strVal;
assert( idle_data == NULL );
if( tr_bencDictFindStr( args_in, "ids", &strVal ) && !strcmp( strVal, "recently-active" ) ) {
int n = 0;
tr_benc * d;
const time_t now = time( NULL );
const int interval = RECENTLY_ACTIVE_SECONDS;
tr_benc * removed_out = tr_bencDictAddList( args_out, "removed", 0 );
while(( d = tr_bencListChild( &session->removedTorrents, n++ ))) {
int64_t intVal;
if( tr_bencDictFindInt( d, "date", &intVal ) && ( intVal >= now - interval ) ) {
tr_bencDictFindInt( d, "id", &intVal );
tr_bencListAddInt( removed_out, intVal );
}
}
}
if( !tr_bencDictFindList( args_in, "fields", &fields ) )
msg = "no fields specified";
else for( i = 0; i < torrentCount; ++i )

View file

@ -231,15 +231,8 @@ isAltTime( const tr_session * s )
if( toNextDay && (minutes < end) )
day = (day - 1) % 7;
if( s->altSpeedTimeDay == TR_SCHED_ALL )
return TRUE;
else if( s->altSpeedTimeDay == TR_SCHED_WEEKDAY )
return (day != 0) && day != 6;
else if( s->altSpeedTimeDay == TR_SCHED_WEEKEND )
return (day == 0) || (day == 6);
else
return day == s->altSpeedTimeDay;
return ((1<<day) & s->altSpeedTimeDay) != 0;
}
/***
@ -468,6 +461,7 @@ tr_sessionInit( const char * tag,
session->lock = tr_lockNew( );
session->tag = tr_strdup( tag );
session->magicNumber = SESSION_MAGIC_NUMBER;
tr_bencInitList( &session->removedTorrents, 0 );
/* start the libtransmission thread */
tr_netInit( ); /* must go before tr_eventInit */
@ -998,14 +992,7 @@ onAltTimer( int foo UNUSED, short bar UNUSED, void * vsession )
if( isEndTime && !isBeginTime && session->altSpeedTimeEnd < session->altSpeedTimeBegin )
day = (day - 1) % 7;
if( session->altSpeedTimeDay == TR_SCHED_ALL )
isDay = TRUE;
else if( session->altSpeedTimeDay == TR_SCHED_WEEKDAY )
isDay = (day != 0) && (day != 6);
else if( session->altSpeedTimeDay == TR_SCHED_WEEKEND )
isDay = (day == 0) || (day == 6);
else
isDay = day == session->altSpeedTimeDay;
isDay = ((1<<day) & session->altSpeedTimeDay) != 0;
if( isDay )
useAltSpeed( session, isBeginTime, FALSE );
@ -1395,6 +1382,7 @@ tr_sessionClose( tr_session * session )
}
/* free the session memory */
tr_bencFree( &session->removedTorrents );
tr_bandwidthFree( session->bandwidth );
tr_lockFree( session->lock );
for( i = 0; i < session->metainfoLookupCount; ++i )

View file

@ -39,6 +39,7 @@
#endif
#endif
#include "bencode.h"
typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
@ -68,6 +69,7 @@ struct tr_session
tr_bool useLazyBitfield;
tr_bool isRatioLimited;
tr_benc removedTorrents;
int speedLimit[2];
tr_bool speedLimitEnabled[2];

View file

@ -1330,10 +1330,15 @@ tr_torrentStop( tr_torrent * tor )
static void
closeTorrent( void * vtor )
{
tr_benc * d;
tr_torrent * tor = vtor;
assert( tr_isTorrent( tor ) );
d = tr_bencListAddDict( &tor->session->removedTorrents, 2 );
tr_bencDictAddInt( d, "id", tor->uniqueId );
tr_bencDictAddInt( d, "date", time( NULL ) );
tr_torrentSaveResume( tor );
tor->isRunning = 0;
stopTorrent( tor );

View file

@ -605,16 +605,16 @@ int tr_sessionGetAltSpeedEnd ( const tr_session * );
typedef enum
{
TR_SCHED_SUN = 0, //specific days correspond to stuct tm's tm_wday
TR_SCHED_MON,
TR_SCHED_TUES,
TR_SCHED_WED,
TR_SCHED_THURS,
TR_SCHED_FRI,
TR_SCHED_SAT,
TR_SCHED_WEEKDAY,
TR_SCHED_WEEKEND,
TR_SCHED_ALL
TR_SCHED_SUN = (1<<0),
TR_SCHED_MON = (1<<1),
TR_SCHED_TUES = (1<<2),
TR_SCHED_WED = (1<<3),
TR_SCHED_THURS = (1<<4),
TR_SCHED_FRI = (1<<4),
TR_SCHED_SAT = (1<<5),
TR_SCHED_WEEKDAY = (TR_SCHED_MON|TR_SCHED_TUES|TR_SCHED_WED|TR_SCHED_THURS|TR_SCHED_FRI),
TR_SCHED_WEEKEND = (TR_SCHED_SUN|TR_SCHED_SAT),
TR_SCHED_ALL = (TR_SCHED_WEEKDAY|TR_SCHED_WEEKEND)
}
tr_sched_day;