finish splitting the rate control from one state into two states as requested by BMW

This commit is contained in:
Charles Kerr 2007-07-20 08:33:59 +00:00
parent 3e3bf8b4a7
commit bbac082af5
7 changed files with 96 additions and 46 deletions

View File

@ -230,8 +230,11 @@ int main( int argc, char ** argv )
signal( SIGINT, sigHandler );
tr_setBindPort( h, bindPort );
tr_setGlobalUploadLimit( h, uploadLimit );
tr_setGlobalDownloadLimit( h, downloadLimit );
tr_setGlobalSpeedLimit ( h, TR_UP, uploadLimit );
tr_setUseGlobalSpeedLimit( h, TR_UP, uploadLimit > 0 );
tr_setGlobalSpeedLimit ( h, TR_DOWN, downloadLimit );
tr_setUseGlobalSpeedLimit( h, TR_DOWN, downloadLimit > 0 );
tr_natTraversalEnable( h, natTraversal );

View File

@ -423,7 +423,8 @@ torrent_set_uplimit( int uplimit )
assert( NULL != gl_handle );
assert( !gl_exiting );
gl_uplimit = uplimit;
tr_setGlobalUploadLimit( gl_handle, uplimit );
tr_setGlobalSpeedLimit ( gl_handle, TR_UP, uplimit );
tr_setUseGlobalSpeedLimit( gl_handle, TR_UP, uplimit > 0 );
savestate();
}
@ -439,7 +440,8 @@ torrent_set_downlimit( int downlimit )
assert( NULL != gl_handle );
assert( !gl_exiting );
gl_downlimit = downlimit;
tr_setGlobalDownloadLimit( gl_handle, downlimit );
tr_setGlobalSpeedLimit ( gl_handle, TR_DOWN, downlimit );
tr_setUseGlobalSpeedLimit( gl_handle, TR_DOWN, downlimit > 0 );
savestate();
}
@ -720,14 +722,16 @@ loadstate( void )
{
gl_uplimit = num->val.i;
}
tr_setGlobalUploadLimit( gl_handle, gl_uplimit );
tr_setGlobalSpeedLimit( gl_handle, TR_UP, gl_uplimit );
tr_setUseGlobalSpeedLimit( gl_handle, TR_UP, gl_uplimit > 0 );
num = tr_bencDictFind( &top, "download-limit" );
if( NULL != num && TYPE_INT == num->type )
{
gl_downlimit = num->val.i;
}
tr_setGlobalDownloadLimit( gl_handle, gl_downlimit );
tr_setGlobalSpeedLimit( gl_handle, TR_DOWN, gl_downlimit );
tr_setUseGlobalSpeedLimit( gl_handle, TR_DOWN, gl_downlimit > 0 );
str = tr_bencDictFind( &top, "default-directory" );
if( NULL != str && TYPE_STR == str->type )

View File

@ -754,7 +754,6 @@ prefschanged( TrCore * core SHUTUP, int id, gpointer data )
{
struct cbdata * cbdata;
tr_handle_t * tr;
int num;
gboolean boolval;
cbdata = data;
@ -767,23 +766,23 @@ prefschanged( TrCore * core SHUTUP, int id, gpointer data )
break;
case PREF_ID_USEDOWNLIMIT:
tr_setUseGlobalSpeedLimit( tr, TR_DOWN,
tr_prefs_get_bool_with_default( PREF_ID_USEDOWNLIMIT ) );
break;
case PREF_ID_DOWNLIMIT:
num = -1;
if( tr_prefs_get_bool_with_default( PREF_ID_USEDOWNLIMIT ) )
{
num = tr_prefs_get_int_with_default( PREF_ID_DOWNLIMIT );
}
tr_setGlobalDownloadLimit( tr, num );
tr_setGlobalSpeedLimit( tr, TR_DOWN,
tr_prefs_get_int_with_default( PREF_ID_DOWNLIMIT ) );
break;
case PREF_ID_USEUPLIMIT:
tr_setUseGlobalSpeedLimit( tr, TR_UP,
tr_prefs_get_bool_with_default( PREF_ID_USEUPLIMIT ) );
break;
case PREF_ID_UPLIMIT:
num = -1;
if( tr_prefs_get_bool_with_default( PREF_ID_USEUPLIMIT ) )
{
num = tr_prefs_get_int_with_default( PREF_ID_UPLIMIT );
}
tr_setGlobalUploadLimit( tr, num );
tr_setGlobalSpeedLimit( tr, TR_UP,
tr_prefs_get_int_with_default( PREF_ID_UPLIMIT ) );
break;
case PREF_ID_NAT:

View File

@ -230,7 +230,9 @@ struct tr_handle_s
char * tag;
int isPortSet;
char useUploadLimit;
tr_ratecontrol_t * upload;
char useDownloadLimit;
tr_ratecontrol_t * download;
tr_shared_t * shared;

View File

@ -379,9 +379,13 @@ int tr_peerRead( tr_peer_t * peer )
{
int canDL;
switch( tor->downloadLimitMode ) {
case TR_SPEEDLIMIT_GLOBAL: canDL = tr_rcCanTransfer( tor->handle->download ); break;
case TR_SPEEDLIMIT_SINGLE: canDL = tr_rcCanTransfer( tor->download ); break;
default: canDL = TRUE; /* unlimited */
case TR_SPEEDLIMIT_GLOBAL:
canDL = !tor->handle->useDownloadLimit ||
tr_rcCanTransfer( tor->handle->download ); break;
case TR_SPEEDLIMIT_SINGLE:
canDL = tr_rcCanTransfer( tor->download ); break;
default: /* unlimited */
canDL = TRUE;
}
if( !canDL )
break;
@ -586,10 +590,17 @@ writeBegin:
if( SWIFT_ENABLED && !isSeeding && (peer->credit<0) )
canUL = FALSE;
else switch( tor->uploadLimitMode ) {
case TR_SPEEDLIMIT_GLOBAL: canUL = tr_rcCanTransfer( tor->handle->upload ); break;
case TR_SPEEDLIMIT_SINGLE: canUL = tr_rcCanTransfer( tor->upload ); break;
default: canUL = TRUE; /* unlimited */
else switch( tor->uploadLimitMode )
{
case TR_SPEEDLIMIT_GLOBAL:
canUL = !tor->handle->useUploadLimit ||
tr_rcCanTransfer( tor->handle->upload ); break;
case TR_SPEEDLIMIT_SINGLE:
canUL = tr_rcCanTransfer( tor->upload ); break;
default: /* unlimited */
canUL = TRUE;
}
if( !canUL )
break;

View File

@ -136,17 +136,48 @@ tr_handle_status_t * tr_handleStatus( tr_handle_t * h )
return s;
}
void tr_setGlobalUploadLimit( tr_handle_t * h, int limit )
/***
****
***/
void
tr_setUseGlobalSpeedLimit( tr_handle_t * h,
int up_or_down,
int use_flag )
{
tr_rcSetLimit( h->upload, limit );
tr_sharedSetLimit( h->shared, limit );
char * ch = up_or_down==TR_UP ? &h->useUploadLimit
: &h->useDownloadLimit;
*ch = use_flag;
}
void tr_setGlobalDownloadLimit( tr_handle_t * h, int limit )
void
tr_setGlobalSpeedLimit( tr_handle_t * h,
int up_or_down,
int KiB_sec )
{
tr_rcSetLimit( h->download, limit );
if( up_or_down == TR_DOWN )
tr_rcSetLimit( h->download, KiB_sec );
else {
tr_rcSetLimit( h->upload, KiB_sec );
tr_sharedSetLimit( h->shared, KiB_sec );
}
}
void
tr_getGlobalSpeedLimit( tr_handle_t * h,
int up_or_down,
int * setme_enabled,
int * setme_KiBsec )
{
if( setme_enabled != NULL )
*setme_enabled = up_or_down==TR_UP ? h->useUploadLimit
: h->useDownloadLimit;
if( setme_KiBsec != NULL )
*setme_KiBsec = tr_rcGetLimit( up_or_down==TR_UP ? h->upload
: h->download );
}
void tr_torrentRates( tr_handle_t * h, float * dl, float * ul )
{
tr_torrent_t * tor;

View File

@ -165,19 +165,6 @@ void tr_natTraversalEnable( tr_handle_t *, int enable );
typedef struct tr_handle_status_s tr_handle_status_t;
tr_handle_status_t * tr_handleStatus( tr_handle_t * );
/***********************************************************************
* tr_setGlobalUploadLimit
***********************************************************************
* Sets the total upload rate limit in KB/s
**********************************************************************/
void tr_setGlobalUploadLimit( tr_handle_t *, int );
/***********************************************************************
* tr_setGlobalDownloadLimit
***********************************************************************
* Sets the total download rate limit in KB/s
**********************************************************************/
void tr_setGlobalDownloadLimit( tr_handle_t *, int );
/***********************************************************************
* tr_torrentCount
@ -201,6 +188,8 @@ void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
*** Speed Limits
**/
enum { TR_UP, TR_DOWN };
typedef enum
{
TR_SPEEDLIMIT_GLOBAL, /* indirectly follow the global pool's limit */
@ -209,8 +198,6 @@ typedef enum
}
tr_speedlimit_t;
enum { TR_UP, TR_DOWN };
void tr_torrentSetSpeedMode( tr_torrent_t * tor,
int up_or_down,
tr_speedlimit_t mode );
@ -225,6 +212,19 @@ void tr_torrentSetSpeedLimit( tr_torrent_t * tor,
int tr_torrentGetSpeedLimit( const tr_torrent_t * tor,
int up_or_down );
void tr_setUseGlobalSpeedLimit( tr_handle_t * handle,
int up_or_down,
int use_flag );
void tr_setGlobalSpeedLimit( tr_handle_t * handle,
int up_or_down,
int global_KiB_sec );
void tr_getGlobalSpeedLimit( tr_handle_t * handle,
int up_or_down,
int * setme_is_enabled,
int * setme_KiBsec );
/***********************************************************************
* Torrent Priorities
**********************************************************************/