#define MY_CONFIG_NAME "transmission"
#define MY_READABLE_NAME "transmission-cli"
-static tr_bool showVersion = FALSE;
-static tr_bool verify = 0;
+static bool showVersion = false;
+static bool verify = 0;
static sig_atomic_t gotsig = 0;
static sig_atomic_t manualUpdate = 0;
return buf;
}
-static tr_bool waitingOnWeb;
+static bool waitingOnWeb;
static void
onTorrentFileDownloaded( tr_session * session UNUSED,
- tr_bool did_connect UNUSED,
- tr_bool did_timeout UNUSED,
+ bool did_connect UNUSED,
+ bool did_timeout UNUSED,
long response_code UNUSED,
const void * response,
size_t response_byte_count,
void * ctor )
{
tr_ctorSetMetainfo( ctor, response, response_byte_count );
- waitingOnWeb = FALSE;
+ waitingOnWeb = false;
}
static void
return EXIT_FAILURE;
}
- h = tr_sessionInit( "cli", configDir, FALSE, &settings );
+ h = tr_sessionInit( "cli", configDir, false, &settings );
ctor = tr_ctorNew( h );
fileContents = tr_loadFile( torrentPath, &fileLength );
- tr_ctorSetPaused( ctor, TR_FORCE, FALSE );
+ tr_ctorSetPaused( ctor, TR_FORCE, false );
if( fileContents != NULL ) {
tr_ctorSetMetainfo( ctor, fileContents, fileLength );
} else if( !memcmp( torrentPath, "magnet:?", 8 ) ) {
tr_ctorSetMetainfoFromMagnetLink( ctor, torrentPath );
} else if( !memcmp( torrentPath, "http", 4 ) ) {
tr_webRun( h, torrentPath, NULL, NULL, onTorrentFileDownloaded, ctor );
- waitingOnWeb = TRUE;
+ waitingOnWeb = true;
while( waitingOnWeb ) tr_wait_msec( 1000 );
} else {
fprintf( stderr, "ERROR: Unrecognized torrent \"%s\".\n", torrentPath );
{
switch( c )
{
- case 'b': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, TRUE );
+ case 'b': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, true );
break;
- case 'B': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE );
+ case 'B': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false );
break;
case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, atoi( optarg ) );
- tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, true );
break;
- case 'D': tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
+ case 'D': tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, false );
break;
case 'f': tr_bencDictAddStr( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, optarg );
- tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, TRUE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, true );
break;
case 'g': /* handled above */
break;
- case 'm': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE );
+ case 'm': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, true );
break;
- case 'M': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, FALSE );
+ case 'M': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, false );
break;
case 'p': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT, atoi( optarg ) );
break;
case 't': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi( optarg ) );
break;
case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_KBps, atoi( optarg ) );
- tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, true );
break;
- case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
+ case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, false );
break;
- case 'v': verify = TRUE;
+ case 'v': verify = true;
break;
- case 'V': showVersion = TRUE;
+ case 'V': showVersion = true;
break;
case 'w': tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, optarg );
break;
AC_HEADER_STDC
AC_HEADER_TIME
+AC_CHECK_HEADERS([stdbool.h])
AC_CHECK_FUNCS([iconv_open pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign statvfs htonll ntohll])
AC_PROG_INSTALL
AC_PROG_MAKE_SET
#define SPEED_G_STR "GiB/s"
#define SPEED_T_STR "TiB/s"
-static tr_bool paused = FALSE;
-static tr_bool closing = FALSE;
+static bool paused = false;
+static bool closing = false;
static tr_session * mySession = NULL;
/***
const char * configDir = tr_sessionGetConfigDir( mySession );
tr_inf( "Reloading settings from \"%s\"", configDir );
tr_bencInitDict( &settings, 0 );
- tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, TRUE );
+ tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, true );
tr_sessionLoadSettings( &settings, configDir, MY_NAME );
tr_sessionSet( mySession, &settings );
tr_bencFree( &settings );
}
default:
- closing = TRUE;
+ closing = true;
break;
}
}
tr_err( "Error parsing .torrent file \"%s\"", file );
else
{
- tr_bool trash = FALSE;
+ bool trash = false;
int test = tr_ctorGetDeleteSource( ctor, &trash );
tr_inf( "Parsing .torrent file successful \"%s\"", file );
void * user_data UNUSED )
{
if( type == TR_RPC_SESSION_CLOSE )
- closing = TRUE;
+ closing = true;
return TR_RPC_OK;
}
int c;
const char * optarg;
tr_benc settings;
- tr_bool boolVal;
- tr_bool loaded;
- tr_bool foreground = FALSE;
- tr_bool dumpSettings = FALSE;
+ bool boolVal;
+ bool loaded;
+ bool foreground = false;
+ bool dumpSettings = false;
const char * configDir = NULL;
const char * pid_filename;
dtr_watchdir * watchdir = NULL;
FILE * logfile = NULL;
- tr_bool pidfile_created = FALSE;
+ bool pidfile_created = false;
signal( SIGINT, gotsig );
signal( SIGTERM, gotsig );
/* load settings from defaults + config file */
tr_bencInitDict( &settings, 0 );
- tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, TRUE );
+ tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, true );
configDir = getConfigDir( argc, (const char**)argv );
loaded = tr_sessionLoadSettings( &settings, configDir, MY_NAME );
while(( c = tr_getopt( getUsage(), argc, (const char**)argv, options, &optarg ))) {
switch( c ) {
case 'a': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, optarg );
- tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, TRUE );
+ tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, true );
break;
- case 'b': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, TRUE );
+ case 'b': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, true );
break;
- case 'B': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE );
+ case 'B': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, false );
break;
case 'c': tr_bencDictAddStr( &settings, PREF_KEY_DIR_WATCH, optarg );
- tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, TRUE );
+ tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, true );
break;
- case 'C': tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, FALSE );
+ case 'C': tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, false );
break;
case 941: tr_bencDictAddStr( &settings, TR_PREFS_KEY_INCOMPLETE_DIR, optarg );
- tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, TRUE );
+ tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, true );
break;
- case 942: tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE );
+ case 942: tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false );
break;
- case 'd': dumpSettings = TRUE;
+ case 'd': dumpSettings = true;
break;
case 'e': logfile = fopen( optarg, "a+" );
if( logfile == NULL )
fprintf( stderr, "Couldn't open \"%s\": %s\n", optarg, tr_strerror( errno ) );
break;
- case 'f': foreground = TRUE;
+ case 'f': foreground = true;
break;
case 'g': /* handled above */
break;
case 'V': /* version */
fprintf(stderr, "%s %s\n", MY_NAME, LONG_VERSION_STRING);
exit( 0 );
- case 'o': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, TRUE );
+ case 'o': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, true );
break;
- case 'O': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, FALSE );
+ case 'O': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, false );
break;
case 'p': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_PORT, atoi( optarg ) );
break;
- case 't': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, TRUE );
+ case 't': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, true );
break;
- case 'T': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, FALSE );
+ case 'T': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, false );
break;
case 'u': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_USERNAME, optarg );
break;
break;
case 'P': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_PORT, atoi( optarg ) );
break;
- case 'm': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, TRUE );
+ case 'm': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, true );
break;
- case 'M': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, FALSE );
+ case 'M': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, false );
break;
case 'L': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi( optarg ) );
break;
case 'l': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi( optarg ) );
break;
- case 800: paused = TRUE;
+ case 800: paused = true;
break;
case 910: tr_bencDictAddInt( &settings, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_REQUIRED );
break;
case 'r': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_BIND_ADDRESS, optarg );
break;
case 953: tr_bencDictAddReal( &settings, TR_PREFS_KEY_RATIO, atof(optarg) );
- tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, TRUE );
+ tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, true );
break;
- case 954: tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, FALSE );
+ case 954: tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, false );
break;
case 'x': tr_bencDictAddStr( &settings, PREF_KEY_PIDFILE, optarg );
break;
- case 'y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, TRUE );
+ case 'y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, true );
break;
- case 'Y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, FALSE );
+ case 'Y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, false );
break;
case 810: tr_bencDictAddInt( &settings, TR_PREFS_KEY_MSGLEVEL, TR_MSG_ERR );
break;
return 0;
}
- if( !foreground && tr_daemon( TRUE, FALSE ) < 0 )
+ if( !foreground && tr_daemon( true, false ) < 0 )
{
char buf[256];
tr_snprintf( buf, sizeof( buf ), "Failed to daemonize: %s", tr_strerror( errno ) );
tr_formatter_mem_init( MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR );
tr_formatter_size_init( DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR );
tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR );
- mySession = tr_sessionInit( "daemon", configDir, TRUE, &settings );
+ mySession = tr_sessionInit( "daemon", configDir, true, &settings );
tr_sessionSetRPCCallback( mySession, on_rpc_callback, NULL );
tr_ninf( NULL, "Using settings from \"%s\"", configDir );
tr_sessionSaveSettings( mySession, configDir, &settings );
fprintf( fp, "%d", (int)getpid() );
fclose( fp );
tr_inf( "Saved pidfile \"%s\"", pid_filename );
- pidfile_created = TRUE;
+ pidfile_created = true;
}
else
tr_err( "Unable to save pidfile \"%s\": %s", pid_filename, strerror( errno ) );
tr_torrent ** torrents;
tr_ctor * ctor = tr_ctorNew( mySession );
if( paused )
- tr_ctorSetPaused( ctor, TR_FORCE, TRUE );
+ tr_ctorSetPaused( ctor, TR_FORCE, true );
torrents = tr_sessionLoadTorrents( mySession, ctor, NULL );
tr_free( torrents );
tr_ctorFree( ctor );
}
}
-static tr_bool debug = 0;
+static bool debug = 0;
static char * auth = NULL;
static char * netrc = NULL;
static char * sessionId = NULL;
if( strcmp( id, "all" ) )
{
const char * pch;
- tr_bool isList = strchr(id,',') || strchr(id,'-');
- tr_bool isNum = TRUE;
+ bool isList = strchr(id,',') || strchr(id,'-');
+ bool isNum = true;
for( pch=id; isNum && *pch; ++pch )
if( !isdigit( *pch ) )
- isNum = FALSE;
+ isNum = false;
if( isNum || isList )
tr_rpc_parse_list_str( tr_bencDictAdd( args, "ids" ), id, strlen( id ) );
else
addTime( tr_benc * args, const char * key, const char * arg )
{
int time;
- tr_bool success = FALSE;
+ bool success = false;
if( arg && ( strlen( arg ) == 4 ) )
{
if( 0<=hour && hour<24 && 0<=min && min<60 )
{
time = min + ( hour * 60 );
- success = TRUE;
+ success = true;
}
}
getStatusString( tr_benc * t, char * buf, size_t buflen )
{
int64_t status;
- tr_bool boolVal;
+ bool boolVal;
if( !tr_bencDictFindInt( t, "status", &status ) )
{
char buf[512];
char buf2[512];
int64_t i, j, k;
- tr_bool boolVal;
+ bool boolVal;
double d;
printf( "NAME\n" );
tr_benc *args;
if( ( tr_bencDictFindDict( top, "arguments", &args ) ) )
{
- tr_bool boolVal;
+ bool boolVal;
if( tr_bencDictFindBool( args, "port-is-open", &boolVal ) )
printf( "Port is open: %s\n", ( boolVal ? "Yes" : "No" ) );
for( i=0; (( t = tr_bencListChild( trackerStats, i ))); ++i )
{
int64_t downloadCount;
- tr_bool hasAnnounced;
- tr_bool hasScraped;
+ bool hasAnnounced;
+ bool hasScraped;
const char * host;
int64_t id;
- tr_bool isBackup;
+ bool isBackup;
int64_t lastAnnouncePeerCount;
const char * lastAnnounceResult;
int64_t lastAnnounceStartTime;
- tr_bool lastAnnounceSucceeded;
+ bool lastAnnounceSucceeded;
int64_t lastAnnounceTime;
- tr_bool lastAnnounceTimedOut;
+ bool lastAnnounceTimedOut;
const char * lastScrapeResult;
- tr_bool lastScrapeSucceeded;
+ bool lastScrapeSucceeded;
int64_t lastScrapeStartTime;
int64_t lastScrapeTime;
- tr_bool lastScrapeTimedOut;
+ bool lastScrapeTimedOut;
int64_t leecherCount;
int64_t nextAnnounceTime;
int64_t nextScrapeTime;
{
int64_t i;
char buf[64];
- tr_bool boolVal;
+ bool boolVal;
const char * str;
printf( "VERSION\n" );
printf( "\n" );
{
- tr_bool altEnabled, altTimeEnabled, upEnabled, downEnabled, seedRatioLimited;
+ bool altEnabled, altTimeEnabled, upEnabled, downEnabled, seedRatioLimited;
int64_t altDown, altUp, altBegin, altEnd, altDay, upLimit, downLimit, peerLimit;
double seedRatioLimit;
break;
case 'b': /* debug */
- debug = TRUE;
+ debug = true;
break;
case 'n': /* auth */
switch( c )
{
case 800: tr_bencDictAddStr( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, optarg );
- tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, TRUE );
+ tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, true );
break;
- case 801: tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, FALSE );
+ case 801: tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, false );
break;
- case 970: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, TRUE );
+ case 970: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, true );
break;
- case 971: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE );
+ case 971: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, false );
break;
case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, numarg( optarg ) );
break;
case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP_KBps, numarg( optarg ) );
break;
- case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, TRUE );
+ case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, true );
break;
- case 975: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, FALSE );
+ case 975: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, false );
break;
case 976: addTime( args, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, optarg );
break;
case 978: addDays( args, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, optarg );
break;
case 'c': tr_bencDictAddStr( args, TR_PREFS_KEY_INCOMPLETE_DIR, optarg );
- tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, TRUE );
+ tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, true );
break;
- case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE );
+ case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false );
break;
case 'e': tr_bencDictAddInt( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, atoi(optarg) );
break;
break;
case 912: tr_bencDictAddStr( args, TR_PREFS_KEY_ENCRYPTION, "tolerated" );
break;
- case 'm': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, TRUE );
+ case 'm': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, true );
break;
- case 'M': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, FALSE );
+ case 'M': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, false );
break;
- case 'o': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, TRUE );
+ case 'o': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, true );
break;
- case 'O': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, FALSE );
+ case 'O': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, false );
break;
- case 830: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, TRUE );
+ case 830: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, true );
break;
- case 831: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, FALSE );
+ case 831: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, false );
break;
case 'p': tr_bencDictAddInt( args, TR_PREFS_KEY_PEER_PORT, numarg( optarg ) );
break;
- case 'P': tr_bencDictAddBool( args, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, TRUE);
+ case 'P': tr_bencDictAddBool( args, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, true);
break;
- case 'x': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, TRUE );
+ case 'x': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, true );
break;
- case 'X': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, FALSE );
+ case 'X': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, false );
break;
- case 'y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, TRUE );
+ case 'y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, true );
break;
- case 'Y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, FALSE );
+ case 'Y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, false );
break;
case 953: tr_bencDictAddReal( args, "seedRatioLimit", atof(optarg) );
- tr_bencDictAddBool( args, "seedRatioLimited", TRUE );
+ tr_bencDictAddBool( args, "seedRatioLimited", true );
break;
- case 954: tr_bencDictAddBool( args, "seedRatioLimited", FALSE );
+ case 954: tr_bencDictAddBool( args, "seedRatioLimited", false );
break;
- case 990: tr_bencDictAddBool( args, TR_PREFS_KEY_START, FALSE );
+ case 990: tr_bencDictAddBool( args, TR_PREFS_KEY_START, false );
break;
- case 991: tr_bencDictAddBool( args, TR_PREFS_KEY_START, TRUE );
+ case 991: tr_bencDictAddBool( args, TR_PREFS_KEY_START, true );
break;
- case 992: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, TRUE );
+ case 992: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, true );
break;
- case 993: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, FALSE );
+ case 993: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, false );
break;
default: assert( "unhandled value" && 0 );
break;
{
case 'd': if( targs ) {
tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) );
- tr_bencDictAddBool( targs, "downloadLimited", TRUE );
+ tr_bencDictAddBool( targs, "downloadLimited", true );
} else {
tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED_KBps, numarg( optarg ) );
- tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
+ tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, true );
}
break;
case 'D': if( targs )
- tr_bencDictAddBool( targs, "downloadLimited", FALSE );
+ tr_bencDictAddBool( targs, "downloadLimited", false );
else
- tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
+ tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, false );
break;
case 'u': if( targs ) {
tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) );
- tr_bencDictAddBool( targs, "uploadLimited", TRUE );
+ tr_bencDictAddBool( targs, "uploadLimited", true );
} else {
tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED_KBps, numarg( optarg ) );
- tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
+ tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, true );
}
break;
case 'U': if( targs )
- tr_bencDictAddBool( targs, "uploadLimited", FALSE );
+ tr_bencDictAddBool( targs, "uploadLimited", false );
else
- tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
+ tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, false );
break;
case 930: if( targs )
tr_bencDictAddInt( targs, "peer-limit", atoi(optarg) );
break;
case 952: tr_bencDictAddInt( args, "seedRatioMode", TR_RATIOLIMIT_UNLIMITED );
break;
- case 984: tr_bencDictAddBool( args, "honorsSessionLimits", TRUE );
+ case 984: tr_bencDictAddBool( args, "honorsSessionLimits", true );
break;
- case 985: tr_bencDictAddBool( args, "honorsSessionLimits", FALSE );
+ case 985: tr_bencDictAddBool( args, "honorsSessionLimits", false );
break;
default: assert( "unhandled value" && 0 );
break;
tr_bencDictAddStr( top, "method", "torrent-set-location" );
args = tr_bencDictAddDict( top, ARGUMENTS, 3 );
tr_bencDictAddStr( args, "location", optarg );
- tr_bencDictAddBool( args, "move", FALSE );
+ tr_bencDictAddBool( args, "move", false );
addIdArg( args, id );
status |= flush( rpcurl, &top );
break;
case 's': /* start */
{
if( tadd )
- tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", FALSE );
+ tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", false );
else {
tr_benc * top = tr_new0( tr_benc, 1 );
tr_bencInitDict( top, 2 );
case 'S': /* stop */
{
if( tadd )
- tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", TRUE );
+ tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", true );
else {
tr_benc * top = tr_new0( tr_benc, 1 );
tr_bencInitDict( top, 2 );
tr_bencDictAddStr( top, "method", "torrent-set-location" );
args = tr_bencDictAddDict( top, ARGUMENTS, 3 );
tr_bencDictAddStr( args, "location", optarg );
- tr_bencDictAddBool( args, "move", TRUE );
+ tr_bencDictAddBool( args, "move", true );
addIdArg( args, id );
status |= flush( rpcurl, &top );
break;
gboolean
gtr_pref_flag_get( const char * key )
{
- tr_bool boolVal;
+ bool boolVal;
tr_bencDictFindBool( getPrefs( ), key, &boolVal );
return boolVal != 0;
}
/* honor_limits_check */
if( n ) {
- const tr_bool baseline = tr_torrentUsesSessionLimits( torrents[0] );
+ const bool baseline = tr_torrentUsesSessionLimits( torrents[0] );
int i;
for( i=1; i<n; ++i )
if( baseline != tr_torrentUsesSessionLimits( torrents[i] ) )
/* down_limited_check */
if( n ) {
- const tr_bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_DOWN );
+ const bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_DOWN );
int i;
for( i=1; i<n; ++i )
if( baseline != tr_torrentUsesSpeedLimit( torrents[i], TR_DOWN ) )
/* up_limited_check */
if( n ) {
- const tr_bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_UP );
+ const bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_UP );
int i;
for( i=1; i<n; ++i )
if( baseline != tr_torrentUsesSpeedLimit( torrents[i], TR_UP ) )
****/
static const char *
-activityString( int activity, tr_bool finished )
+activityString( int activity, bool finished )
{
switch( activity )
{
if( n<=0 )
str = no_torrent;
else {
- const tr_bool baseline = infos[0]->isPrivate;
+ const bool baseline = infos[0]->isPrivate;
for( i=1; i<n; ++i )
if( baseline != infos[i]->isPrivate )
break;
str = no_torrent;
else {
const tr_torrent_activity activity = stats[0]->activity;
- tr_bool allFinished = stats[0]->finished;
+ bool allFinished = stats[0]->finished;
for( i=1; i<n; ++i ) {
if( activity != stats[i]->activity )
break;
{
int i;
int n = 0;
- const tr_bool more = gtr_pref_flag_get( PREF_KEY_SHOW_MORE_PEER_INFO );
+ const bool more = gtr_pref_flag_get( PREF_KEY_SHOW_MORE_PEER_INFO );
int view_columns[32];
GtkTreeViewColumn * c;
GtkCellRenderer * r;
return pixbuf;
}
-static void favicon_web_done_cb( tr_session*, tr_bool, tr_bool, long, const void*, size_t, void* );
+static void favicon_web_done_cb( tr_session*, bool, bool, long, const void*, size_t, void* );
static gboolean
favicon_web_done_idle_cb( gpointer vfav )
static void
favicon_web_done_cb( tr_session * session UNUSED,
- tr_bool did_connect UNUSED,
- tr_bool did_timeout UNUSED,
+ bool did_connect UNUSED,
+ bool did_timeout UNUSED,
long code UNUSED,
const void * data,
size_t len,
tr_sessionGetSettings( session, &tmp );
for( i=0; tr_bencDictChild( &tmp, i, &key, &newval ); ++i )
{
- tr_bool changed;
+ bool changed;
tr_benc * oldval = tr_bencDictFind( oldvals, key );
if( !oldval )
- changed = TRUE;
+ changed = true;
else {
char * a = tr_bencToStr( oldval, TR_FMT_BENC, NULL );
char * b = tr_bencToStr( newval, TR_FMT_BENC, NULL );
GtkWidget * grab;
GtkWidget * source_chooser;
struct OpenData * data;
- uint8_t flag;
+ bool flag;
GSList * list;
GSList * walk;
struct relocate_dialog_data
{
int done;
- tr_bool do_move;
+ bool do_move;
TrCore * core;
GSList * torrent_ids;
GtkWidget * message_dialog;
**** BUSY
***/
-static tr_bool
+static bool
core_is_busy( TrCore * core )
{
return core->priv->busy_count > 0;
static void
core_add_to_busy( TrCore * core, int addMe )
{
- const tr_bool wasBusy = core_is_busy( core );
+ const bool wasBusy = core_is_busy( core );
core->priv->busy_count += addMe;
static void
on_torrent_completeness_changed( tr_torrent * tor,
tr_completeness completeness,
- tr_bool was_running,
+ bool was_running,
void * gcore )
{
if( was_running && ( completeness != TR_LEECH ) && ( tr_torrentStat( tor )->sizeWhenDone != 0 ) )
{
int errcode = 0;
tr_torrent * tor;
- uint8_t do_trash = FALSE;
+ bool do_trash = false;
tr_session * session = gtr_core_session( core );
/* let the gtk client handle the removal, since libT
tr_ctor * ctor;
char * url;
- tr_bool did_connect;
- tr_bool did_timeout;
+ bool did_connect;
+ bool did_timeout;
long response_code;
};
static void
on_url_done( tr_session * session,
- tr_bool did_connect,
- tr_bool did_timeout,
+ bool did_connect,
+ bool did_timeout,
long response_code,
const void * response,
size_t response_byte_count,
int oldActivity, newActivity;
int oldActivePeerCount, newActivePeerCount;
int oldError, newError;
- tr_bool oldFinished, newFinished;
+ bool oldFinished, newFinished;
tr_priority_t oldPriority, newPriority;
char * oldCollatedName, * newCollatedName;
char * oldTrackers, * newTrackers;
on_port_test_response( TrCore * core, tr_benc * response, gpointer u UNUSED )
{
tr_benc * args;
- tr_bool is_open = FALSE;
+ bool is_open = FALSE;
if( tr_bencDictFindDict( response, "arguments", &args ) )
tr_bencDictFindBool( args, "port-is-open", &is_open );
static void
onBlocklistUpdated( TrCore * core, int n, gpointer gdata )
{
- const tr_bool success = n >= 0;
+ const bool success = n >= 0;
const int count = n >=0 ? n : tr_blocklistGetRuleCount( gtr_core_session( core ) );
const char * s = gtr_ngettext( "Blocklist has %'d rule.", "Blocklist has %'d rules.", count );
struct blocklist_data * data = gdata;
}
static void
-onAltSpeedToggled( tr_session * s UNUSED, tr_bool isEnabled UNUSED, tr_bool byUser UNUSED, void * p )
+onAltSpeedToggled( tr_session * s UNUSED, bool isEnabled UNUSED, bool byUser UNUSED, void * p )
{
gtr_idle_add( onAltSpeedToggledIdle, p );
}
typedef struct
{
/* whether or not we managed to connect to the tracker */
- tr_bool did_connect;
+ bool did_connect;
/* whether or not the scrape timed out */
- tr_bool did_timeout;
+ bool did_timeout;
/* how many info hashes are in the 'rows' field */
int row_count;
typedef struct
{
tr_announce_event event;
- tr_bool partial_seed;
+ bool partial_seed;
/* the port we listen for incoming peers on */
int port;
uint8_t info_hash[SHA_DIGEST_LENGTH];
/* whether or not we managed to connect to the tracker */
- tr_bool did_connect;
+ bool did_connect;
/* whether or not the scrape timed out */
- tr_bool did_timeout;
+ bool did_timeout;
/* preferred interval between announces.
* transmission treats this as the interval for periodic announces */
char ipv6_readable[INET6_ADDRSTRLEN];
evutil_inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN );
evbuffer_add_printf( buf, "&ipv6=");
- tr_http_escape( buf, ipv6_readable, -1, TRUE );
+ tr_http_escape( buf, ipv6_readable, -1, true );
}
return evbuffer_free_to_str( buf );
static void
on_announce_done( tr_session * session,
- tr_bool did_connect,
- tr_bool did_timeout,
+ bool did_connect,
+ bool did_timeout,
long response_code,
const void * msg,
size_t msglen,
static void
on_scrape_done( tr_session * session,
- tr_bool did_connect,
- tr_bool did_timeout,
+ bool did_connect,
+ bool did_timeout,
long response_code,
const void * msg,
size_t msglen,
}
tau_action_t;
-static tr_bool
+static bool
is_tau_response_message( int action, int msglen )
{
if( action == TAU_ACTION_CONNECT ) return msglen == 16;
if( action == TAU_ACTION_ANNOUNCE ) return msglen >= 20;
if( action == TAU_ACTION_SCRAPE ) return msglen >= 20;
if( action == TAU_ACTION_ERROR ) return msglen >= 8;
- return FALSE;
+ return false;
}
enum
static void
tau_scrape_request_fail( tr_session * session,
struct tau_scrape_request * request,
- tr_bool did_connect,
- tr_bool did_timeout,
+ bool did_connect,
+ bool did_timeout,
const char * errmsg )
{
request->response.did_connect = did_connect;
tau_action_t action,
struct evbuffer * buf )
{
- request->response.did_connect = TRUE;
- request->response.did_timeout = FALSE;
+ request->response.did_connect = true;
+ request->response.did_timeout = false;
if( action == TAU_ACTION_SCRAPE )
{
else
errmsg = tr_strdup( _( "Unknown error" ) );
- tau_scrape_request_fail( session, request, TRUE, FALSE, errmsg );
+ tau_scrape_request_fail( session, request, true, false, errmsg );
tr_free( errmsg );
}
}
static void
tau_announce_request_fail( tr_session * session,
struct tau_announce_request * request,
- tr_bool did_connect,
- tr_bool did_timeout,
+ bool did_connect,
+ bool did_timeout,
const char * errmsg )
{
request->response.did_connect = did_connect;
tau_action_t action,
struct evbuffer * buf )
{
- request->response.did_connect = TRUE;
- request->response.did_timeout = FALSE;
+ request->response.did_connect = true;
+ request->response.did_timeout = false;
if( ( action == TAU_ACTION_ANNOUNCE )
&& ( evbuffer_get_length( buf ) >= 3*sizeof(uint32_t) ) )
else
errmsg = tr_strdup( _( "Unknown error" ) );
- tau_announce_request_fail( session, request, TRUE, FALSE, errmsg );
+ tau_announce_request_fail( session, request, true, false, errmsg );
tr_free( errmsg );
}
}
char * host;
int port;
- tr_bool is_asking_dns;
+ bool is_asking_dns;
struct evutil_addrinfo * addr;
time_t addr_expiration_time;
static void
tau_tracker_fail_all( struct tau_tracker * tracker,
- tr_bool did_connect,
- tr_bool did_timeout,
+ bool did_connect,
+ bool did_timeout,
const char * errmsg )
{
int i;
{
struct tau_tracker * tracker = vtracker;
- tracker->is_asking_dns = FALSE;
+ tracker->is_asking_dns = false;
if ( errcode )
{
char * errmsg = tr_strdup_printf( _( "DNS Lookup failed: %s" ),
evdns_err_to_string( errcode ) );
dbgmsg( tracker->key, "%s", errmsg );
- tau_tracker_fail_all( tracker, FALSE, FALSE, errmsg );
+ tau_tracker_fail_all( tracker, false, false, errmsg );
tr_free( errmsg );
}
else
errmsg = tr_strdup( _( "Connection failed" ) );
dbgmsg( tracker->key, "%s", errmsg );
- tau_tracker_fail_all( tracker, TRUE, FALSE, errmsg );
+ tau_tracker_fail_all( tracker, true, false, errmsg );
tr_free( errmsg );
}
int i, n;
tr_ptrArray * reqs;
const time_t now = time( NULL );
- const tr_bool cancel_all = tracker->close_at && ( tracker->close_at <= now );
+ const bool cancel_all = tracker->close_at && ( tracker->close_at <= now );
if( tracker->connecting_at && ( tracker->connecting_at + TAU_REQUEST_TTL < now ) ) {
struct tau_announce_request * req = tr_ptrArrayNth( reqs, i );
if( cancel_all || ( req->created_at + TAU_REQUEST_TTL < now ) ) {
dbgmsg( tracker->key, "timeout announce req %p", req );
- tau_announce_request_fail( tracker->session, req, FALSE, TRUE, NULL );
+ tau_announce_request_fail( tracker->session, req, false, true, NULL );
tau_announce_request_free( req );
tr_ptrArrayRemove( reqs, i );
--i;
struct tau_scrape_request * req = tr_ptrArrayNth( reqs, i );
if( cancel_all || ( req->created_at + TAU_REQUEST_TTL < now ) ) {
dbgmsg( tracker->key, "timeout scrape req %p", req );
- tau_scrape_request_fail( tracker->session, req, FALSE, TRUE, NULL );
+ tau_scrape_request_fail( tracker->session, req, false, true, NULL );
tau_scrape_request_free( req );
tr_ptrArrayRemove( reqs, i );
--i;
}
}
-static tr_bool
+static bool
tau_tracker_is_empty( const struct tau_tracker * tracker )
{
return tr_ptrArrayEmpty( &tracker->announces )
hints.ai_flags = EVUTIL_AI_CANONNAME;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
- tracker->is_asking_dns = TRUE;
+ tracker->is_asking_dns = true;
dbgmsg( tracker->host, "Trying a new DNS lookup" );
evdns_getaddrinfo( tracker->session->evdns_base,
tracker->host, NULL, &hints,
(PtrArrayForeachFunc)tau_tracker_upkeep );
}
-tr_bool
+bool
tr_tracker_udp_is_empty( const tr_session * session )
{
int i;
if( tau != NULL )
for( i=0, n=tr_ptrArraySize(&tau->trackers); i<n; ++i )
if( !tau_tracker_is_empty( tr_ptrArrayNth( &tau->trackers, i ) ) )
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
/* drop dead now. */
/* @brief process an incoming udp message if it's a tracker response.
* @return true if msg was a tracker response; false otherwise */
-tr_bool
+bool
tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen )
{
int i;
/*fprintf( stderr, "got an incoming udp message w/len %zu\n", msglen );*/
if( !session || !session->announcer_udp )
- return FALSE;
+ return false;
if( msglen < (sizeof(uint32_t)*2) )
- return FALSE;
+ return false;
/* extract the action_id and see if it makes sense */
buf = evbuffer_new( );
action_id = evbuffer_read_ntoh_32( buf );
if( !is_tau_response_message( action_id, msglen ) ) {
evbuffer_free( buf );
- return FALSE;
+ return false;
}
/* extract the transaction_id and look for a match */
dbgmsg( tracker->key, "%"PRIu32" is my connection request!", transaction_id );
on_tracker_connection_response( tracker, action_id, buf );
evbuffer_free( buf );
- return TRUE;
+ return true;
}
/* is it a response to one of this tracker's announces? */
on_announce_response( session, req, action_id, buf );
tau_announce_request_free( req );
evbuffer_free( buf );
- return TRUE;
+ return true;
}
}
on_scrape_response( session, req, action_id, buf );
tau_scrape_request_free( req );
evbuffer_free( buf );
- return TRUE;
+ return true;
}
}
}
/* no match... */
evbuffer_free( buf );
- return FALSE;
+ return false;
}
void
}
tr_announcer;
-tr_bool
+bool
tr_announcerHasBacklog( const struct tr_announcer * announcer )
{
return announcer->slotsAvailable < 1;
time_t scrapeAt;
time_t lastScrapeStartTime;
time_t lastScrapeTime;
- tr_bool lastScrapeSucceeded;
- tr_bool lastScrapeTimedOut;
+ bool lastScrapeSucceeded;
+ bool lastScrapeTimedOut;
time_t announceAt;
time_t manualAnnounceAllowedAt;
time_t lastAnnounceStartTime;
time_t lastAnnounceTime;
- tr_bool lastAnnounceSucceeded;
- tr_bool lastAnnounceTimedOut;
+ bool lastAnnounceSucceeded;
+ bool lastAnnounceTimedOut;
tr_announce_event * announce_events;
int announce_event_count;
int lastAnnouncePeerCount;
- tr_bool isRunning;
- tr_bool isAnnouncing;
- tr_bool isScraping;
- tr_bool wasCopied;
+ bool isRunning;
+ bool isAnnouncing;
+ bool isScraping;
+ bool wasCopied;
char lastAnnounceStr[128];
char lastScrapeStr[128];
tier->scrapeIntervalSec = DEFAULT_SCRAPE_INTERVAL_SEC;
tier->announceIntervalSec = DEFAULT_ANNOUNCE_INTERVAL_SEC;
tier->announceMinIntervalSec = DEFAULT_ANNOUNCE_MIN_INTERVAL_SEC;
- tier->isAnnouncing = FALSE;
- tier->isScraping = FALSE;
+ tier->isAnnouncing = false;
+ tier->isScraping = false;
tier->lastAnnounceStartTime = 0;
tier->lastScrapeStartTime = 0;
}
char * scheme;
char * host;
char * path;
- tr_bool is_duplicate = FALSE;
+ bool is_duplicate = false;
tr_urlParse( input[i].announce, -1, &scheme, &host, &port, &path );
/* weed out one common source of duplicates:
****
***/
-static tr_bool
+static bool
tierCanManualAnnounce( const tr_tier * tier )
{
return tier->manualAnnounceAllowedAt <= tr_time( );
}
-tr_bool
+bool
tr_announcerCanManualAnnounce( const tr_torrent * tor )
{
int i;
assert( tor->tiers != NULL );
if( !tor->isRunning )
- return FALSE;
+ return false;
/* return true if any tier can manual announce */
n = tr_ptrArraySize( &tor->tiers->tiers );
tiers = (const tr_tier**) tr_ptrArrayBase( &tor->tiers->tiers );
for( i=0; i<n; ++i )
if( tierCanManualAnnounce( tiers[i] ) )
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
time_t
/* special case #1: if we're adding a "stopped" event,
* dump everything leading up to it except "completed" */
if( e == TR_ANNOUNCE_EVENT_STOPPED ) {
- tr_bool has_completed = FALSE;
+ bool has_completed = false;
const tr_announce_event c = TR_ANNOUNCE_EVENT_COMPLETED;
for( i=0; !has_completed && i<tier->announce_event_count; ++i )
has_completed = c == tier->announce_events[i];
tr_announce_event event;
/** If the request succeeds, the value for tier's "isRunning" flag */
- tr_bool isRunningOnSuccess;
+ bool isRunningOnSuccess;
};
static void
tier->lastAnnounceTime = now;
tier->lastAnnounceTimedOut = response->did_timeout;
- tier->lastAnnounceSucceeded = FALSE;
- tier->isAnnouncing = FALSE;
+ tier->lastAnnounceSucceeded = false;
+ tier->isAnnouncing = false;
tier->manualAnnounceAllowedAt = now + tier->announceMinIntervalSec;
if( !response->did_connect )
{
int i;
const char * str;
- const tr_bool isStopped = event == TR_ANNOUNCE_EVENT_STOPPED;
+ const bool isStopped = event == TR_ANNOUNCE_EVENT_STOPPED;
publishErrorClear( tier );
tier->isRunning = data->isRunningOnSuccess;
tier->scrapeAt = now + tier->scrapeIntervalSec;
tier->lastScrapeTime = now;
- tier->lastScrapeSucceeded = TRUE;
- tier->lastAnnounceSucceeded = TRUE;
+ tier->lastScrapeSucceeded = true;
+ tier->lastAnnounceSucceeded = true;
tier->lastAnnouncePeerCount = response->pex_count
+ response->pex6_count;
data->timeSent = now;
data->event = announce_event;
- tier->isAnnouncing = TRUE;
+ tier->isAnnouncing = true;
tier->lastAnnounceStartTime = now;
--announcer->slotsAvailable;
/* schedule a rescrape */
interval = getRetryInterval( tier->currentTracker );
dbgmsg( tier, "Retrying scrape in %d seconds.", interval );
- tier->lastScrapeSucceeded = FALSE;
+ tier->lastScrapeSucceeded = false;
tier->scrapeAt = tr_time() + interval;
}
response->min_request_interval,
response->errmsg ? response->errmsg : "none" );
- tier->isScraping = FALSE;
+ tier->isScraping = false;
tier->lastScrapeTime = now;
- tier->lastScrapeSucceeded = FALSE;
+ tier->lastScrapeSucceeded = false;
tier->lastScrapeTimedOut = response->did_timeout;
if( !response->did_connect )
{
tr_tracker * tracker;
- tier->lastScrapeSucceeded = TRUE;
+ tier->lastScrapeSucceeded = true;
tier->scrapeIntervalSec = MAX( DEFAULT_SCRAPE_INTERVAL_SEC,
response->min_request_interval );
tier->scrapeAt = now + tier->scrapeIntervalSec;
continue;
memcpy( req->info_hash[req->info_hash_count++], hash, SHA_DIGEST_LENGTH );
- tier->isScraping = TRUE;
+ tier->isScraping = true;
tier->lastScrapeStartTime = now;
break;
}
tier_build_log_name( tier, req->log_name, sizeof( req->log_name ) );
memcpy( req->info_hash[req->info_hash_count++], hash, SHA_DIGEST_LENGTH );
- tier->isScraping = TRUE;
+ tier->isScraping = true;
tier->lastScrapeStartTime = now;
}
}
tr_ptrArrayClear( &announcer->stops );
}
-static tr_bool
+static bool
tierNeedsToAnnounce( const tr_tier * tier, const time_t now )
{
return !tier->isAnnouncing
&& ( tier->announce_event_count > 0 );
}
-static tr_bool
+static bool
tierNeedsToScrape( const tr_tier * tier, const time_t now )
{
return ( !tier->isScraping )
{
tr_announcer * announcer = vannouncer;
tr_session * session = announcer->session;
- const tr_bool is_closing = session->isClosed;
+ const bool is_closing = session->isClosed;
const time_t now = tr_time( );
tr_sessionLock( session );
tierCopyAttributes( t, o );
t->currentTracker = item;
t->currentTrackerIndex = k;
- t->wasCopied = TRUE;
+ t->wasCopied = true;
trackerItemCopyAttributes( item, o->currentTracker );
dbgmsg( t, "attributes copied to tier %d, tracker %d"
"from tier %d, tracker %d",
tr_tracker_callback * cb,
void * cbdata );
-tr_bool tr_announcerHasBacklog( const struct tr_announcer * );
+bool tr_announcerHasBacklog( const struct tr_announcer * );
void tr_announcerResetTorrent( struct tr_announcer*, tr_torrent* );
void tr_announcerChangeMyPort( tr_torrent * );
-tr_bool tr_announcerCanManualAnnounce( const tr_torrent * );
+bool tr_announcerCanManualAnnounce( const tr_torrent * );
void tr_announcerManualAnnounce( tr_torrent * );
void tr_tracker_udp_close( tr_session * session );
-tr_bool tr_tracker_udp_is_empty( const tr_session * session );
+bool tr_tracker_udp_is_empty( const tr_session * session );
b->session = session;
b->children = TR_PTR_ARRAY_INIT;
b->magicNumber = BANDWIDTH_MAGIC_NUMBER;
- b->band[TR_UP].honorParentLimits = TRUE;
- b->band[TR_DOWN].honorParentLimits = TRUE;
+ b->band[TR_UP].honorParentLimits = true;
+ b->band[TR_DOWN].honorParentLimits = true;
tr_bandwidthSetParent( b, parent );
return b;
}
tr_bandwidthUsed( tr_bandwidth * b,
tr_direction dir,
size_t byteCount,
- tr_bool isPieceData,
+ bool isPieceData,
uint64_t now )
{
struct tr_band * band;
* it's included in the header for inlining and composition. */
struct tr_band
{
- tr_bool isLimited;
- tr_bool honorParentLimits;
+ bool isLimited;
+ bool honorParentLimits;
unsigned int bytesLeft;
unsigned int desiredSpeed_Bps;
struct bratecontrol raw;
}
/** @brief test to see if the pointer refers to a live bandwidth object */
-static inline tr_bool tr_isBandwidth( const tr_bandwidth * b )
+static inline bool tr_isBandwidth( const tr_bandwidth * b )
{
return ( b != NULL ) && ( b->magicNumber == BANDWIDTH_MAGIC_NUMBER );
}
* @see tr_bandwidthAllocate
* @see tr_bandwidthGetDesiredSpeed
*/
-static inline tr_bool tr_bandwidthSetDesiredSpeed_Bps( tr_bandwidth * bandwidth,
- tr_direction dir,
- unsigned int desiredSpeed )
+static inline bool tr_bandwidthSetDesiredSpeed_Bps( tr_bandwidth * bandwidth,
+ tr_direction dir,
+ unsigned int desiredSpeed )
{
unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps;
- const tr_bool didChange = desiredSpeed != *value;
+ const bool didChange = desiredSpeed != *value;
*value = desiredSpeed;
return didChange;
}
/**
* @brief Set whether or not this bandwidth should throttle its peer-io's speeds
*/
-static inline tr_bool tr_bandwidthSetLimited( tr_bandwidth * bandwidth,
- tr_direction dir,
- tr_bool isLimited )
+static inline bool tr_bandwidthSetLimited( tr_bandwidth * bandwidth,
+ tr_direction dir,
+ bool isLimited )
{
- tr_bool * value = &bandwidth->band[dir].isLimited;
- const tr_bool didChange = isLimited != *value;
+ bool * value = &bandwidth->band[dir].isLimited;
+ const bool didChange = isLimited != *value;
*value = isLimited;
return didChange;
}
/**
* @return nonzero if this bandwidth throttles its peer-ios speeds
*/
-static inline tr_bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth,
- tr_direction dir )
+static inline bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth,
+ tr_direction dir )
{
return bandwidth->band[dir].isLimited;
}
void tr_bandwidthUsed ( tr_bandwidth * bandwidth,
tr_direction direction,
size_t byteCount,
- tr_bool isPieceData,
+ bool isPieceData,
uint64_t now );
/******
* But when we set a torrent's speed mode to TR_SPEEDLIMIT_UNLIMITED, then
* in that particular case we want to ignore the global speed limit...
*/
-static inline tr_bool tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth,
- tr_direction direction,
- tr_bool isEnabled )
+static inline bool tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth,
+ tr_direction direction,
+ bool isEnabled )
{
- tr_bool * value = &bandwidth->band[direction].honorParentLimits;
- const tr_bool didChange = isEnabled != *value;
+ bool * value = &bandwidth->band[direction].honorParentLimits;
+ const bool didChange = isEnabled != *value;
*value = isEnabled;
return didChange;
}
-static inline tr_bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth * bandwidth,
- tr_direction direction )
+static inline bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth * bandwidth,
+ tr_direction direction )
{
assert( tr_isBandwidth( bandwidth ) );
assert( tr_isDirection( direction ) );
tr_free( saved );
tr_bencFree( &val );
- if( ( err = testString( "llleee", TRUE ) ) )
+ if( ( err = testString( "llleee", true ) ) )
return err;
- if( ( err = testString( "d3:cow3:moo4:spam4:eggse", TRUE ) ) )
+ if( ( err = testString( "d3:cow3:moo4:spam4:eggse", true ) ) )
return err;
- if( ( err = testString( "d4:spaml1:a1:bee", TRUE ) ) )
+ if( ( err = testString( "d4:spaml1:a1:bee", true ) ) )
return err;
if( ( err =
testString( "d5:greenli1ei2ei3ee4:spamd1:ai123e3:keyi214eee",
- TRUE ) ) )
+ true ) ) )
return err;
if( ( err =
testString(
"d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee",
- TRUE ) ) )
+ true ) ) )
return err;
if( ( err =
testString(
"d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e",
- TRUE ) ) )
+ true ) ) )
return err;
- if( ( err = testString( "d1:ai0e1:be", FALSE ) ) ) /* odd number of children
+ if( ( err = testString( "d1:ai0e1:be", false ) ) ) /* odd number of children
*/
return err;
- if( ( err = testString( "", FALSE ) ) )
+ if( ( err = testString( "", false ) ) )
return err;
- if( ( err = testString( " ", FALSE ) ) )
+ if( ( err = testString( " ", false ) ) )
return err;
/* nested containers
{
tr_benc top;
int64_t intVal;
- tr_bool boolVal;
+ bool boolVal;
tr_bencInitDict( &top, 0 );
- tr_bencDictAddBool( &top, "key1", FALSE );
+ tr_bencDictAddBool( &top, "key1", false );
tr_bencDictAddBool( &top, "key2", 0 );
- tr_bencDictAddInt ( &top, "key3", TRUE );
+ tr_bencDictAddInt ( &top, "key3", true );
tr_bencDictAddInt ( &top, "key4", 1 );
check( tr_bencDictFindBool( &top, "key1", &boolVal ) )
check( !boolVal )
int64_t intVal;
const char * strVal;
double realVal;
- tr_bool boolVal;
+ bool boolVal;
int len;
char * benc;
const uint8_t * end;
tr_bencInitDict( &top, 0 );
- tr_bencDictAddBool( &top, "this-is-a-bool", TRUE );
+ tr_bencDictAddBool( &top, "this-is-a-bool", true );
tr_bencDictAddInt( &top, "this-is-an-int", 1234 );
tr_bencDictAddReal( &top, "this-is-a-real", 0.5 );
tr_bencDictAddStr( &top, "this-is-a-string", "this-is-a-string" );
check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) )
check( intVal == 1234 )
check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) )
- check( boolVal == TRUE )
+ check( boolVal == true )
check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) )
check( !strcmp( strVal, "this-is-a-string" ) )
check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) )
***
**/
-static tr_bool
+static bool
isContainer( const tr_benc * val )
{
return tr_bencIsList( val ) || tr_bencIsDict( val );
}
-static tr_bool
+static bool
isSomething( const tr_benc * val )
{
return isContainer( val ) || tr_bencIsInt( val )
return i < 0 ? NULL : &val->val.l.vals[i + 1];
}
-static tr_bool
+static bool
tr_bencDictFindType( tr_benc * dict, const char * key, int type, tr_benc ** setme )
{
return tr_bencIsType( *setme = tr_bencDictFind( dict, key ), type );
fprintf( stderr, "warning: %s\n", err );
}
-tr_bool
+bool
tr_bencGetInt( const tr_benc * val,
int64_t * setme )
{
- tr_bool success = FALSE;
+ bool success = false;
if( !success && (( success = tr_bencIsInt( val ))))
if( setme )
return success;
}
-tr_bool
+bool
tr_bencGetStr( const tr_benc * val, const char ** setme )
{
- const tr_bool success = tr_bencIsString( val );
+ const bool success = tr_bencIsString( val );
if( success )
*setme = getStr( val );
return success;
}
-tr_bool
+bool
tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_len )
{
- const tr_bool success = tr_bencIsString( val );
+ const bool success = tr_bencIsString( val );
if( success ) {
*setme_raw = (uint8_t*) getStr(val);
return success;
}
-tr_bool
-tr_bencGetBool( const tr_benc * val, tr_bool * setme )
+bool
+tr_bencGetBool( const tr_benc * val, bool * setme )
{
const char * str;
- tr_bool success = FALSE;
+ bool success = false;
if(( success = tr_bencIsBool( val )))
*setme = val->val.b;
return success;
}
-tr_bool
+bool
tr_bencGetReal( const tr_benc * val, double * setme )
{
- tr_bool success = FALSE;
+ bool success = false;
if( !success && (( success = tr_bencIsReal( val ))))
*setme = val->val.d;
return success;
}
-tr_bool
+bool
tr_bencDictFindInt( tr_benc * dict, const char * key, int64_t * setme )
{
return tr_bencGetInt( tr_bencDictFind( dict, key ), setme );
}
-tr_bool
-tr_bencDictFindBool( tr_benc * dict, const char * key, tr_bool * setme )
+bool
+tr_bencDictFindBool( tr_benc * dict, const char * key, bool * setme )
{
return tr_bencGetBool( tr_bencDictFind( dict, key ), setme );
}
-tr_bool
+bool
tr_bencDictFindReal( tr_benc * dict, const char * key, double * setme )
{
return tr_bencGetReal( tr_bencDictFind( dict, key ), setme );
}
-tr_bool
+bool
tr_bencDictFindStr( tr_benc * dict, const char * key, const char ** setme )
{
return tr_bencGetStr( tr_bencDictFind( dict, key ), setme );
}
-tr_bool
+bool
tr_bencDictFindList( tr_benc * dict, const char * key, tr_benc ** setme )
{
return tr_bencDictFindType( dict, key, TR_TYPE_LIST, setme );
}
-tr_bool
+bool
tr_bencDictFindDict( tr_benc * dict, const char * key, tr_benc ** setme )
{
return tr_bencDictFindType( dict, key, TR_TYPE_DICT, setme );
}
-tr_bool
+bool
tr_bencDictFindRaw( tr_benc * dict, const char * key, const uint8_t ** setme_raw, size_t * setme_len )
{
return tr_bencGetRaw( tr_bencDictFind( dict, key ), setme_raw, setme_len );
}
tr_benc *
-tr_bencListAddBool( tr_benc * list, tr_bool val )
+tr_bencListAddBool( tr_benc * list, bool val )
{
tr_benc * node = tr_bencListAdd( list );
tr_bencInitBool( node, val );
}
tr_benc*
-tr_bencDictAddBool( tr_benc * dict, const char * key, tr_bool val )
+tr_bencDictAddBool( tr_benc * dict, const char * key, bool val )
{
tr_benc * child = dictFindOrAdd( dict, key, TR_TYPE_BOOL );
tr_bencInitBool( child, val );
};
static void
-nodeInitDict( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts )
+nodeInitDict( struct SaveNode * node, const tr_benc * val, bool sort_dicts )
{
const int n = val->val.l.count;
const int nKeys = n / 2;
}
static void
-nodeInit( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts )
+nodeInit( struct SaveNode * node, const tr_benc * val, bool sort_dicts )
{
static const struct SaveNode INIT_NODE = { NULL, 0, 0, 0, NULL };
*node = INIT_NODE;
bencWalk( const tr_benc * top,
const struct WalkFuncs * walkFuncs,
void * user_data,
- tr_bool sort_dicts )
+ bool sort_dicts )
{
int stackSize = 0;
int stackAlloc = 64;
if( !node->valIsVisited )
{
val = node->val;
- node->valIsVisited = TRUE;
+ node->valIsVisited = true;
}
else if( node->childIndex < node->childCount )
{
tr_bencFree( tr_benc * val )
{
if( isSomething( val ) )
- bencWalk( val, &freeWalkFuncs, NULL, FALSE );
+ bencWalk( val, &freeWalkFuncs, NULL, false );
}
/***
/** @brief Implementation helper class for tr_bencToBuffer(TR_FMT_JSON) */
struct jsonWalk
{
- tr_bool doIndent;
+ bool doIndent;
tr_list * parents;
struct evbuffer * out;
};
if( !( i % 2 ) )
evbuffer_add( data->out, ": ", data->doIndent ? 2 : 1 );
else {
- const tr_bool isLast = parentState->childIndex == parentState->childCount;
+ const bool isLast = parentState->childIndex == parentState->childCount;
if( !isLast ) {
evbuffer_add( data->out, ", ", data->doIndent ? 2 : 1 );
jsonIndent( data );
case TR_TYPE_LIST:
{
- const tr_bool isLast = ++parentState->childIndex == parentState->childCount;
+ const bool isLast = ++parentState->childIndex == parentState->childCount;
if( !isLast ) {
evbuffer_add( data->out, ", ", data->doIndent ? 2 : 1 );
jsonIndent( data );
void * vdata )
{
struct jsonWalk * data = vdata;
- int emptyContainer = FALSE;
+ int emptyContainer = false;
jsonPopParent( data );
if( !emptyContainer )
{
if( tr_bencIsBool( val ) )
{
- tr_bool boolVal = 0;
+ bool boolVal = 0;
tr_bencGetBool( val, &boolVal );
tr_bencListAddBool( target, boolVal );
}
return count;
}
-tr_bool
+bool
tr_bencDictChild( tr_benc * dict, size_t n, const char ** key, tr_benc ** val )
{
- tr_bool success = 0;
+ bool success = 0;
assert( tr_bencIsDict( dict ) );
{
if( tr_bencIsBool( val ) )
{
- tr_bool boolVal;
+ bool boolVal;
tr_bencGetBool( val, &boolVal );
tr_bencDictAddBool( target, key, boolVal );
}
switch( mode )
{
case TR_FMT_BENC:
- bencWalk( top, &saveFuncs, buf, TRUE );
+ bencWalk( top, &saveFuncs, buf, true );
break;
case TR_FMT_JSON:
data.doIndent = mode==TR_FMT_JSON;
data.out = buf;
data.parents = NULL;
- bencWalk( top, &jsonWalkFuncs, &data, TRUE );
+ bencWalk( top, &jsonWalkFuncs, &data, true );
if( evbuffer_get_length( buf ) )
evbuffer_add_printf( buf, "\n" );
break;
tr_benc * tr_bencListAdd( tr_benc * );
-tr_benc * tr_bencListAddBool( tr_benc *, tr_bool val );
+tr_benc * tr_bencListAddBool( tr_benc *, bool val );
tr_benc * tr_bencListAddInt( tr_benc *, int64_t val );
tr_benc * tr_bencDictAddInt( tr_benc *, const char * key, int64_t );
-tr_benc * tr_bencDictAddBool( tr_benc *, const char * key, tr_bool );
+tr_benc * tr_bencDictAddBool( tr_benc *, const char * key, bool );
tr_benc * tr_bencDictAddStr( tr_benc *, const char * key, const char * );
tr_benc * tr_bencDictAddRaw( tr_benc *, const char * key,
const void * raw, size_t rawlen );
-tr_bool tr_bencDictChild( tr_benc *, size_t i, const char ** key, tr_benc ** val );
+bool tr_bencDictChild( tr_benc *, size_t i, const char ** key, tr_benc ** val );
tr_benc* tr_bencDictFind( tr_benc *, const char * key );
-tr_bool tr_bencDictFindList( tr_benc *, const char * key, tr_benc ** setme );
+bool tr_bencDictFindList( tr_benc *, const char * key, tr_benc ** setme );
-tr_bool tr_bencDictFindDict( tr_benc *, const char * key, tr_benc ** setme );
+bool tr_bencDictFindDict( tr_benc *, const char * key, tr_benc ** setme );
-tr_bool tr_bencDictFindInt( tr_benc *, const char * key, int64_t * setme );
+bool tr_bencDictFindInt( tr_benc *, const char * key, int64_t * setme );
-tr_bool tr_bencDictFindReal( tr_benc *, const char * key, double * setme );
+bool tr_bencDictFindReal( tr_benc *, const char * key, double * setme );
-tr_bool tr_bencDictFindBool( tr_benc *, const char * key, tr_bool * setme );
+bool tr_bencDictFindBool( tr_benc *, const char * key, bool * setme );
-tr_bool tr_bencDictFindStr( tr_benc *, const char * key, const char ** setme );
+bool tr_bencDictFindStr( tr_benc *, const char * key, const char ** setme );
-tr_bool tr_bencDictFindRaw( tr_benc *, const char * key,
+bool tr_bencDictFindRaw( tr_benc *, const char * key,
const uint8_t ** setme_raw, size_t * setme_len );
/***
***/
/** @brief Get an int64_t from a variant object
- @return TRUE if successful, or FALSE if the variant could not be represented as an int64_t */
-tr_bool tr_bencGetInt( const tr_benc * val, int64_t * setme );
+ @return true if successful, or false if the variant could not be represented as an int64_t */
+bool tr_bencGetInt( const tr_benc * val, int64_t * setme );
/** @brief Get an string from a variant object
- @return TRUE if successful, or FALSE if the variant could not be represented as a string */
-tr_bool tr_bencGetStr( const tr_benc * val, const char ** setme );
+ @return true if successful, or false if the variant could not be represented as a string */
+bool tr_bencGetStr( const tr_benc * val, const char ** setme );
/** @brief Get a raw byte array from a variant object
- @return TRUE if successful, or FALSE if the variant could not be represented as a raw byte array */
-tr_bool tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_len );
+ @return true if successful, or false if the variant could not be represented as a raw byte array */
+bool tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_len );
/** @brief Get a boolean from a variant object
- @return TRUE if successful, or FALSE if the variant could not be represented as a boolean */
-tr_bool tr_bencGetBool( const tr_benc * val, tr_bool * setme );
+ @return true if successful, or false if the variant could not be represented as a boolean */
+bool tr_bencGetBool( const tr_benc * val, bool * setme );
/** @brief Get a floating-point number from a variant object
- @return TRUE if successful, or FALSE if the variant could not be represented as a floating-point number */
-tr_bool tr_bencGetReal( const tr_benc * val, double * setme );
+ @return true if successful, or false if the variant could not be represented as a floating-point number */
+bool tr_bencGetReal( const tr_benc * val, double * setme );
-static inline tr_bool tr_bencIsType ( const tr_benc * b, int type ) { return ( b != NULL ) && ( b->type == type ); }
+static inline bool tr_bencIsType ( const tr_benc * b, int type ) { return ( b != NULL ) && ( b->type == type ); }
-static inline tr_bool tr_bencIsInt ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_INT ); }
-static inline tr_bool tr_bencIsDict ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_DICT ); }
-static inline tr_bool tr_bencIsList ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_LIST ); }
-static inline tr_bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_STR ); }
-static inline tr_bool tr_bencIsBool ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_BOOL ); }
-static inline tr_bool tr_bencIsReal ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_REAL ); }
+static inline bool tr_bencIsInt ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_INT ); }
+static inline bool tr_bencIsDict ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_DICT ); }
+static inline bool tr_bencIsList ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_LIST ); }
+static inline bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_STR ); }
+static inline bool tr_bencIsBool ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_BOOL ); }
+static inline bool tr_bencIsReal ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_REAL ); }
/** @brief Private function that's exposed here only for unit tests */
int tr_bencParseInt( const uint8_t * buf,
has none of tr_bitfieldHas()'s safety checks, so you
need to call tr_bitfieldTestFast() first before you
start looping. */
-static inline tr_bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth )
+static inline bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth )
{
return ( b->bits[nth>>3u] << ( nth & 7u ) & 0x80 ) != 0;
}
/** @param high the highest nth bit you're going to access */
-static inline tr_bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high )
+static inline bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high )
{
return ( b != NULL )
&& ( b->bits != NULL )
&& ( high < b->bitCount );
}
-static inline tr_bool tr_bitfieldHas( const tr_bitfield * b, size_t nth )
+static inline bool tr_bitfieldHas( const tr_bitfield * b, size_t nth )
{
return tr_bitfieldTestFast( b, nth ) && tr_bitfieldHasFast( b, nth );
}
#include "bitset.h"
#include "utils.h"
-const tr_bitset TR_BITSET_INIT = { FALSE, FALSE, { NULL, 0, 0 } };
+const tr_bitset TR_BITSET_INIT = { false, false, { NULL, 0, 0 } };
void
tr_bitsetConstruct( tr_bitset * b, size_t bitCount )
{
tr_free( b->bitfield.bits );
b->bitfield.bits = NULL;
- b->haveAll = FALSE;
- b->haveNone = FALSE;
+ b->haveAll = false;
+ b->haveNone = false;
}
void
tr_bitsetSetHaveAll( tr_bitset * b )
{
tr_bitsetClear( b );
- b->haveAll = TRUE;
+ b->haveAll = true;
}
void
tr_bitsetSetHaveNone( tr_bitset * b )
{
tr_bitsetClear( b );
- b->haveNone = TRUE;
+ b->haveNone = true;
}
void
if( b->haveAll )
return;
- b->haveNone = FALSE;
+ b->haveNone = false;
/* do we need to resize the bitfield to accomodate this bit? */
if( !bf->bits || ( bf->bitCount < i+1 ) )
if( b->haveNone )
return;
- b->haveAll = FALSE;
+ b->haveAll = false;
if( !b->bitfield.bits )
{
if( b->haveNone )
return;
- b->haveAll = FALSE;
+ b->haveAll = false;
if( !b->bitfield.bits )
{
tr_bitfieldConstruct( &b->bitfield, b->bitfield.bitCount );
****
***/
-tr_bool
+bool
tr_bitsetHas( const tr_bitset * b, const size_t nth )
{
- if( b->haveAll ) return TRUE;
- if( b->haveNone ) return FALSE;
- if( nth >= b->bitfield.bitCount ) return FALSE;
+ if( b->haveAll ) return true;
+ if( b->haveNone ) return false;
+ if( nth >= b->bitfield.bitCount ) return false;
return tr_bitfieldHas( &b->bitfield, nth );
}
****
***/
-tr_bool
+bool
tr_bitsetFromBenc( tr_bitset * b, tr_benc * benc )
{
size_t buflen;
const uint8_t * buf;
- tr_bool handled = FALSE;
+ bool handled = false;
if( tr_bencGetRaw( benc, &buf, &buflen ) )
{
if( ( buflen == 3 ) && !memcmp( buf, "all", 3 ) )
{
tr_bitsetSetHaveAll( b );
- handled = TRUE;
+ handled = true;
}
else if( ( buflen == 4 ) && !memcmp( buf, "none", 4 ) )
{
tr_bitsetSetHaveNone( b );
- handled = TRUE;
+ handled = true;
}
else
{
- b->haveAll = FALSE;
- b->haveNone = FALSE;
+ b->haveAll = false;
+ b->haveNone = false;
tr_free( b->bitfield.bits );
b->bitfield.bits = tr_memdup( buf, buflen );
b->bitfield.byteCount = buflen;
b->bitfield.bitCount = buflen * 8;
- handled = TRUE;
+ handled = true;
}
}
/** @brief like a tr_bitfield, but supports haveAll and haveNone */
typedef struct tr_bitset
{
- tr_bool haveAll;
- tr_bool haveNone;
+ bool haveAll;
+ bool haveNone;
tr_bitfield bitfield;
}
tr_bitset;
void tr_bitsetRemRange ( tr_bitset * b, size_t begin, size_t end );
struct tr_benc;
-tr_bool tr_bitsetFromBenc( tr_bitset * bitset, struct tr_benc * benc );
+bool tr_bitsetFromBenc( tr_bitset * bitset, struct tr_benc * benc );
void tr_bitsetToBenc( const tr_bitset * bitset, struct tr_benc * benc );
/***
double tr_bitsetPercent( const tr_bitset * b );
-tr_bool tr_bitsetHas( const tr_bitset * b, const size_t nth );
+bool tr_bitsetHas( const tr_bitset * b, const size_t nth );
size_t tr_bitsetCountRange( const tr_bitset * b, const size_t begin, const size_t end );
void tr_bitsetOr( tr_bitfield * a, const tr_bitset * b );
remove( tmpfile_txt );
remove( tmpfile_bin );
- b = _tr_blocklistNew( tmpfile_bin, TRUE );
+ b = _tr_blocklistNew( tmpfile_bin, true );
createTestBlocklist( tmpfile_txt );
_tr_blocklistSetContent( b, tmpfile_txt );
struct tr_blocklist
{
- tr_bool isEnabled;
+ bool isEnabled;
int fd;
size_t ruleCount;
size_t byteCount;
***/
tr_blocklist *
-_tr_blocklistNew( const char * filename, tr_bool isEnabled )
+_tr_blocklistNew( const char * filename, bool isEnabled )
{
tr_blocklist * b;
* http://wiki.phoenixlabs.org/wiki/P2P_Format
* http://en.wikipedia.org/wiki/PeerGuardian#P2P_plaintext_format
*/
-static tr_bool
+static bool
parseLine1( const char * line, struct tr_ipv4_range * range )
{
char * walk;
walk = strrchr( line, ':' );
if( !walk )
- return FALSE;
+ return false;
++walk; /* walk past the colon */
if( sscanf( walk, "%d.%d.%d.%d-%d.%d.%d.%d",
&b[0], &b[1], &b[2], &b[3],
&e[0], &e[1], &e[2], &e[3] ) != 8 )
- return FALSE;
+ return false;
tr_snprintf( str, sizeof( str ), "%d.%d.%d.%d", b[0], b[1], b[2], b[3] );
if( tr_pton( str, &addr ) == NULL )
- return FALSE;
+ return false;
range->begin = ntohl( addr.addr.addr4.s_addr );
tr_snprintf( str, sizeof( str ), "%d.%d.%d.%d", e[0], e[1], e[2], e[3] );
if( tr_pton( str, &addr ) == NULL )
- return FALSE;
+ return false;
range->end = ntohl( addr.addr.addr4.s_addr );
- return TRUE;
+ return true;
}
/*
* DAT format: "000.000.000.000 - 000.255.255.255 , 000 , invalid ip"
* http://wiki.phoenixlabs.org/wiki/DAT_Format
*/
-static tr_bool
+static bool
parseLine2( const char * line, struct tr_ipv4_range * range )
{
int unk;
&a[0], &a[1], &a[2], &a[3],
&b[0], &b[1], &b[2], &b[3],
&unk ) != 9 )
- return FALSE;
+ return false;
tr_snprintf( str, sizeof(str), "%d.%d.%d.%d", a[0], a[1], a[2], a[3] );
if( tr_pton( str, &addr ) == NULL )
- return FALSE;
+ return false;
range->begin = ntohl( addr.addr.addr4.s_addr );
tr_snprintf( str, sizeof(str), "%d.%d.%d.%d", b[0], b[1], b[2], b[3] );
if( tr_pton( str, &addr ) == NULL )
- return FALSE;
+ return false;
range->end = ntohl( addr.addr.addr4.s_addr );
- return TRUE;
+ return true;
}
static int
typedef struct tr_blocklist tr_blocklist;
tr_blocklist* _tr_blocklistNew ( const char * filename,
- tr_bool isEnabled );
+ bool isEnabled );
int _tr_blocklistExists ( const tr_blocklist * b );
int pos;
int rank;
time_t last_block_time;
- tr_bool is_multi_piece;
- tr_bool is_piece_done;
+ bool is_multi_piece;
+ bool is_piece_done;
unsigned len;
};
const struct cache_block * b = blocks[i-1];
info->last_block_time = b->time;
info->is_piece_done = tr_cpPieceIsComplete( &b->tor->completion, b->piece );
- info->is_multi_piece = b->piece != blocks[pos]->piece ? TRUE : FALSE;
+ info->is_multi_piece = b->piece != blocks[pos]->piece ? true : false;
info->len = i - pos;
info->pos = pos;
}
if( !memcmp( id, "exbc", 4 ) ) mod = "";
else if( !memcmp( id, "FUTB", 4 )) mod = "(Solidox Mod) ";
else if( !memcmp( id, "xUTB", 4 )) mod = "(Mod 2) ";
- else return FALSE;
+ else return false;
is_bitlord = !memcmp( id+6, "LORD", 4 );
name = (is_bitlord) ? "BitLord " : "BitComet ";
else
tr_snprintf( buf, buflen, "%s%s%d.%02d", name, mod, major, minor );
- return TRUE;
+ return true;
}
void
tr_free( cp->completeBlocks );
cp->completeBlocks = NULL;
cp->sizeNow = 0;
- cp->sizeWhenDoneIsDirty = TRUE;
- cp->blocksWantedIsDirty = TRUE;
- cp->haveValidIsDirty = TRUE;
+ cp->sizeWhenDoneIsDirty = true;
+ cp->blocksWantedIsDirty = true;
+ cp->haveValidIsDirty = true;
}
tr_completion *
****
***/
-static inline tr_bool
+static inline bool
isSeed( const tr_completion * cp )
{
return cp->blockBitset.haveAll;
void
tr_cpInvalidateDND( tr_completion * cp )
{
- cp->sizeWhenDoneIsDirty = TRUE;
- cp->blocksWantedIsDirty = TRUE;
+ cp->sizeWhenDoneIsDirty = true;
+ cp->blocksWantedIsDirty = true;
}
tr_block_index_t
cp->blocksWantedLazy = wanted;
cp->blocksWantedCompleteLazy = complete;
- cp->blocksWantedIsDirty = FALSE;
+ cp->blocksWantedIsDirty = false;
}
return ccp->blocksWantedLazy - ccp->blocksWantedCompleteLazy;
if( !tor->info.pieces[piece].dnd )
cp->blocksWantedCompleteLazy -= complete_blocks[piece];
- cp->sizeWhenDoneIsDirty = TRUE;
- cp->haveValidIsDirty = TRUE;
+ cp->sizeWhenDoneIsDirty = true;
+ cp->haveValidIsDirty = true;
complete_blocks[piece] = 0;
tr_bitsetRemRange( &cp->blockBitset, first, last+1 );
}
if( !tor->info.pieces[piece].dnd )
cp->blocksWantedCompleteLazy++;
- cp->sizeWhenDoneIsDirty = TRUE;
- cp->haveValidIsDirty = TRUE;
+ cp->sizeWhenDoneIsDirty = true;
+ cp->haveValidIsDirty = true;
}
}
-tr_bool
+bool
tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks )
{
- tr_bool success = FALSE;
+ bool success = false;
tr_torrent * tor = cp->tor;
/* start cp with a state where it thinks we have nothing */
tr_bitsetSetHaveAll( &cp->blockBitset );
cp->sizeNow = tor->info.totalSize;
- success = TRUE;
+ success = true;
}
else if( blocks->haveNone )
{
/* already reset... */
- success = TRUE;
+ success = true;
}
else
{
tr_bitsetSetHaveNone( &cp->blockBitset );
cp->sizeNow = 0;
} else {
- cp->blockBitset.haveAll = cp->blockBitset.haveNone = FALSE;
+ cp->blockBitset.haveAll = cp->blockBitset.haveNone = false;
cp->sizeNow = tr_bitfieldCountRange( tgt, 0, tor->blockCount-1 );
cp->sizeNow *= tor->blockSize;
if( tr_bitfieldHas( tgt, tor->blockCount-1 ) )
if( tr_cpPieceIsComplete( ccp, i ) )
size += tr_torPieceCountBytes( tor, i );
- cp->haveValidIsDirty = FALSE;
+ cp->haveValidIsDirty = false;
cp->haveValidLazy = size;
}
if( !info->pieces[i].dnd || tr_cpPieceIsComplete( cp, i ) )
size += tr_torPieceCountBytes( tor, i );
- cp->sizeWhenDoneIsDirty = FALSE;
+ cp->sizeWhenDoneIsDirty = false;
cp->sizeWhenDoneLazy = size;
}
{
int i;
const float interval = cp->tor->info.pieceCount / (float)tabCount;
- const tr_bool seed = isSeed( cp );
+ const bool seed = isSeed( cp );
for( i=0; i<tabCount; ++i ) {
if( seed )
return countBlocksInPiece( cp->tor, i ) - getCompleteBlocks(cp)[i];
}
-tr_bool
+bool
tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t i )
{
tr_block_index_t f, l;
if( cp->tor->info.files[i].length == 0 )
- return TRUE;
+ return true;
tr_torGetFileBlockRange( cp->tor, i, &f, &l );
return tr_bitsetCountRange( &cp->blockBitset, f, l+1 ) == (l+1-f);
typedef struct tr_completion
{
- tr_bool sizeWhenDoneIsDirty;
- tr_bool blocksWantedIsDirty;
- tr_bool haveValidIsDirty;
+ bool sizeWhenDoneIsDirty;
+ bool blocksWantedIsDirty;
+ bool haveValidIsDirty;
tr_torrent * tor;
int tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t i );
-static inline tr_bool
+static inline bool
tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t i )
{
return tr_cpMissingBlocksInPiece( cp, i ) == 0;
}
-void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
+void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
-void tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
+void tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
-tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
+bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
/**
*** Blocks
**/
-static inline tr_bool
+static inline bool
tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i )
{
return tr_bitsetHas( &cp->blockBitset, i );
void tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
-tr_bool tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks );
+bool tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks );
/***
****
RC4_KEY dec_key;
RC4_KEY enc_key;
uint8_t torrentHash[SHA_DIGEST_LENGTH];
- tr_bool isIncoming;
- tr_bool torrentHashIsSet;
- tr_bool mySecretIsSet;
+ bool isIncoming;
+ bool torrentHashIsSet;
+ bool mySecretIsSet;
uint8_t myPublicKey[KEY_LEN];
uint8_t mySecret[KEY_LEN];
DH * dh;
int
tr_cryptoWeakRandInt( int upperBound )
{
- static tr_bool init = FALSE;
+ static bool init = false;
assert( upperBound > 0 );
if( !init )
{
srand( tr_time_msec( ) );
- init = TRUE;
+ init = true;
}
return rand( ) % upperBound;
return tr_strdup( &buf );
}
-tr_bool
+bool
tr_ssha1_matches( const char * source, const char * pass )
{
char * salt;
size_t saltlen;
char * hashed;
uint8_t buf[SHA_DIGEST_LENGTH];
- tr_bool result;
+ bool result;
/* extract the salt */
saltlen = strlen( source ) - 2*SHA_DIGEST_LENGTH-1;
hashed[1+2*SHA_DIGEST_LENGTH + saltlen] = '\0';
hashed[0] = '{';
- result = strcmp( source, hashed ) == 0 ? TRUE : FALSE;
+ result = strcmp( source, hashed ) == 0 ? true : false;
tr_free( hashed );
tr_free( salt );
char* tr_ssha1( const void * plaintext );
/** @brief Validate a test password against the a ssha1 password */
-tr_bool tr_ssha1_matches( const char * ssha1, const char * pass );
+bool tr_ssha1_matches( const char * ssha1, const char * pass );
/* @} */
#endif
-static tr_bool
+static bool
preallocate_file_sparse( int fd, uint64_t length )
{
const char zero = '\0';
- tr_bool success = 0;
+ bool success = 0;
if( !length )
- success = TRUE;
+ success = true;
#ifdef HAVE_FALLOCATE64
if( !success ) /* fallocate64 is always preferred, so try it first */
return success;
}
-static tr_bool
+static bool
preallocate_file_full( const char * filename, uint64_t length )
{
- tr_bool success = 0;
+ bool success = 0;
#ifdef WIN32
{
uint8_t buf[ 4096 ];
memset( buf, 0, sizeof( buf ) );
- success = TRUE;
+ success = true;
while ( success && ( length > 0 ) )
{
const int thisPass = MIN( length, sizeof( buf ) );
struct tr_cached_file
{
- tr_bool is_writable;
+ bool is_writable;
int fd;
int torrent_id;
tr_file_index_t file_index;
time_t used_at;
};
-static inline tr_bool
+static inline bool
cached_file_is_open( const struct tr_cached_file * o )
{
assert( o != NULL );
cached_file_open( struct tr_cached_file * o,
const char * existing_dir,
const char * filename,
- tr_bool writable,
+ bool writable,
tr_preallocation_mode allocation,
uint64_t file_size )
{
int flags;
struct stat sb;
- tr_bool alreadyExisted;
+ bool alreadyExisted;
/* confirm that existing_dir, if specified, exists on the disk */
if( existing_dir && *existing_dir && stat( existing_dir, &sb ) )
}
int
-tr_fdFileGetCached( tr_session * s, int torrent_id, tr_file_index_t i, tr_bool writable )
+tr_fdFileGetCached( tr_session * s, int torrent_id, tr_file_index_t i, bool writable )
{
struct tr_cached_file * o = fileset_lookup( get_fileset( s ), torrent_id, i );
tr_file_index_t i,
const char * existing_dir,
const char * filename,
- tr_bool writable,
+ bool writable,
tr_preallocation_mode allocation,
uint64_t file_size )
{
if( s >= 0 )
{
- static tr_bool buf_logged = FALSE;
+ static bool buf_logged = false;
if( !buf_logged )
{
int i;
socklen_t size = sizeof( int );
- buf_logged = TRUE;
+ buf_logged = true;
getsockopt( s, SOL_SOCKET, SO_SNDBUF, &i, &size );
tr_dbg( "SO_SNDBUF size is %d", i );
getsockopt( s, SOL_SOCKET, SO_RCVBUF, &i, &size );
tr_file_index_t file_num,
const char * existing_dir,
const char * filename,
- tr_bool do_write,
+ bool do_write,
tr_preallocation_mode preallocation_mode,
uint64_t preallocation_file_size );
int tr_fdFileGetCached( tr_session * session,
int torrent_id,
tr_file_index_t file_num,
- tr_bool doWrite );
+ bool doWrite );
/**
* Closes a file that's being held by our file repository.
struct tr_handshake
{
- tr_bool haveReadAnythingFromPeer;
- tr_bool havePeerID;
- tr_bool haveSentBitTorrentHandshake;
+ bool haveReadAnythingFromPeer;
+ bool havePeerID;
+ bool haveSentBitTorrentHandshake;
tr_peerIo * io;
tr_crypto * crypto;
tr_session * session;
}
static int tr_handshakeDone( tr_handshake * handshake,
- tr_bool isConnected );
+ bool isConnected );
enum
{
tr_peerIoSetPeersId( handshake->io, peer_id );
/* peer id */
- handshake->havePeerID = TRUE;
+ handshake->havePeerID = true;
dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id );
tor = tr_torrentFindFromHash( handshake->session, hash );
/* send it */
setReadState( handshake, AWAITING_YB );
- tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, FALSE );
+ tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, false );
}
static uint32_t
return READ_NOW;
}
- handshake->haveReadAnythingFromPeer = TRUE;
+ handshake->haveReadAnythingFromPeer = true;
/* compute the secret */
evbuffer_remove( inbuf, yb, KEY_LEN );
{
uint8_t vc[VC_LENGTH] = { 0, 0, 0, 0, 0, 0, 0, 0 };
- tr_peerIoWriteBuf( handshake->io, outbuf, FALSE );
+ tr_peerIoWriteBuf( handshake->io, outbuf, false );
tr_cryptoEncryptInit( handshake->crypto );
tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_RC4 );
/* send it */
tr_cryptoDecryptInit( handshake->crypto );
setReadState( handshake, AWAITING_VC );
- tr_peerIoWriteBuf( handshake->io, outbuf, FALSE );
+ tr_peerIoWriteBuf( handshake->io, outbuf, false );
/* cleanup */
evbuffer_free( outbuf );
{
dbgmsg( handshake,
"peer selected an encryption option we didn't provide" );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
tr_peerIoReadUint16( handshake->io, inbuf, &pad_d_len );
if( pad_d_len > 512 )
{
dbgmsg( handshake, "encryption handshake: pad_d_len is too long" );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
handshake->pad_d_len = pad_d_len;
if( evbuffer_get_length( inbuf ) < INCOMING_HANDSHAKE_LEN )
return READ_LATER;
- handshake->haveReadAnythingFromPeer = TRUE;
+ handshake->haveReadAnythingFromPeer = true;
pstrlen = evbuffer_pullup( inbuf, 1 )[0]; /* peek, don't read. We may be
handing inbuf to AWAITING_YA */
{
dbgmsg( handshake,
"peer is unencrypted, and we're disallowing that" );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
}
else /* encrypted or corrupt */
{
dbgmsg( handshake,
"I think peer has sent us a corrupt handshake..." );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
}
if( strcmp( (char*)pstr, "BitTorrent protocol" ) )
{
tr_free( pstr );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
tr_free( pstr );
if( !tr_torrentExists( handshake->session, hash ) )
{
dbgmsg( handshake, "peer is trying to connect to us for a torrent we don't have." );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
else
{
SHA_DIGEST_LENGTH ) )
{
dbgmsg( handshake, "peer returned the wrong hash. wtf?" );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
}
{
uint8_t msg[HANDSHAKE_SIZE];
buildHandshakeMessage( handshake, msg );
- tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE );
+ tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false );
handshake->haveSentBitTorrentHandshake = 1;
}
readPeerId( tr_handshake * handshake,
struct evbuffer * inbuf )
{
- tr_bool peerIsGood;
+ bool peerIsGood;
char client[128];
tr_torrent * tor;
const uint8_t * tor_peer_id;
/* peer id */
tr_peerIoReadBytes( handshake->io, inbuf, peer_id, PEER_ID_LEN );
tr_peerIoSetPeersId( handshake->io, peer_id );
- handshake->havePeerID = TRUE;
+ handshake->havePeerID = true;
tr_clientForId( client, sizeof( client ), peer_id );
dbgmsg( handshake, "peer-id is [%s] ... isIncoming is %d", client,
tr_peerIoIsIncoming( handshake->io ) );
walk += len;
setReadState( handshake, AWAITING_PAD_A );
- tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, FALSE );
+ tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, false );
return READ_NOW;
}
obfuscatedTorrentHash[i] = req2[i] ^ req3[i];
if(( tor = tr_torrentFindFromObfuscatedHash( handshake->session, obfuscatedTorrentHash )))
{
- const tr_bool clientIsSeed = tr_torrentIsSeed( tor );
- const tr_bool peerIsSeed = tr_peerMgrPeerIsSeed( tor, tr_peerIoGetAddress( handshake->io, NULL ) );
+ const bool clientIsSeed = tr_torrentIsSeed( tor );
+ const bool peerIsSeed = tr_peerMgrPeerIsSeed( tor, tr_peerIoGetAddress( handshake->io, NULL ) );
dbgmsg( handshake, "got INCOMING connection's encrypted handshake for torrent [%s]",
tr_torrentName( tor ) );
tr_peerIoSetTorrentHash( handshake->io, tor->info.hash );
if( clientIsSeed && peerIsSeed )
{
dbgmsg( handshake, "another seed tried to reconnect to us!" );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
}
else
{
dbgmsg( handshake, "can't find that torrent..." );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
/* next part: ENCRYPT(VC, crypto_provide, len(PadC), */
{
dbgmsg( handshake, "peer didn't offer an encryption mode we like." );
evbuffer_free( outbuf );
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
}
dbgmsg( handshake, "sending pad d" );
/* maybe de-encrypt our connection */
if( crypto_select == CRYPTO_PROVIDE_PLAINTEXT )
{
- tr_peerIoWriteBuf( handshake->io, outbuf, FALSE );
+ tr_peerIoWriteBuf( handshake->io, outbuf, false );
tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_NONE );
}
}
/* send it out */
- tr_peerIoWriteBuf( handshake->io, outbuf, FALSE );
+ tr_peerIoWriteBuf( handshake->io, outbuf, false );
evbuffer_free( outbuf );
/* now await the handshake */
i = parseHandshake( handshake, inbuf );
dbgmsg( handshake, "parseHandshake returned %d", i );
if( i != HANDSHAKE_OK )
- return tr_handshakeDone( handshake, FALSE );
+ return tr_handshakeDone( handshake, false );
/* we've completed the BT handshake... pass the work on to peer-msgs */
- return tr_handshakeDone( handshake, TRUE );
+ return tr_handshakeDone( handshake, true );
}
/***
tr_handshake * handshake = arg;
struct evbuffer * inbuf = tr_peerIoGetReadBuffer( io );
ReadState ret;
- tr_bool readyForMore = TRUE;
+ bool readyForMore = true;
assert( tr_isPeerIo( io ) );
}
if( ret != READ_NOW )
- readyForMore = FALSE;
+ readyForMore = false;
else if( handshake->state == AWAITING_PAD_C )
readyForMore = evbuffer_get_length( inbuf ) >= handshake->pad_c_len;
else if( handshake->state == AWAITING_PAD_D )
return ret;
}
-static tr_bool
-fireDoneFunc( tr_handshake * handshake, tr_bool isConnected )
+static bool
+fireDoneFunc( tr_handshake * handshake, bool isConnected )
{
const uint8_t * peer_id = isConnected && handshake->havePeerID
? tr_peerIoGetPeersId( handshake->io )
: NULL;
- const tr_bool success = ( *handshake->doneCB )( handshake,
- handshake->io,
- handshake->haveReadAnythingFromPeer,
- isConnected,
- peer_id,
- handshake->doneUserData );
+ const bool success = ( *handshake->doneCB )( handshake,
+ handshake->io,
+ handshake->haveReadAnythingFromPeer,
+ isConnected,
+ peer_id,
+ handshake->doneUserData );
return success;
}
}
static int
-tr_handshakeDone( tr_handshake * handshake,
- tr_bool isOK )
+tr_handshakeDone( tr_handshake * handshake, bool isOK )
{
- tr_bool success;
+ bool success;
dbgmsg( handshake, "handshakeDone: %s", isOK ? "connected" : "aborting" );
tr_peerIoSetIOFuncs( handshake->io, NULL, NULL, NULL, NULL );
tr_handshakeAbort( tr_handshake * handshake )
{
if( handshake != NULL )
- tr_handshakeDone( handshake, FALSE );
+ tr_handshakeDone( handshake, false );
}
static void
tr_torrentLock( tor );
tr_peerMgrSetUtpFailed( tor,
tr_peerIoGetAddress( io, NULL ),
- TRUE );
+ true );
tr_torrentUnlock( tor );
}
buildHandshakeMessage( handshake, msg );
handshake->haveSentBitTorrentHandshake = 1;
setReadState( handshake, AWAITING_HANDSHAKE );
- tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE );
+ tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false );
}
}
buildHandshakeMessage( handshake, msg );
handshake->haveSentBitTorrentHandshake = 1;
setReadState( handshake, AWAITING_HANDSHAKE );
- tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE );
+ tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false );
}
else
{
dbgmsg( handshake, "libevent got an error what==%d, errno=%d (%s)",
(int)what, errno, tr_strerror( errno ) );
- tr_handshakeDone( handshake, FALSE );
+ tr_handshakeDone( handshake, false );
}
}
handshake->haveSentBitTorrentHandshake = 1;
setReadState( handshake, AWAITING_HANDSHAKE );
- tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE );
+ tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false );
}
return handshake;
typedef struct tr_handshake tr_handshake;
/* returns true on success, false on error */
-typedef tr_bool ( *handshakeDoneCB )( struct tr_handshake * handshake,
- struct tr_peerIo * io,
- tr_bool readAnythingFromPeer,
- tr_bool isConnected,
- const uint8_t * peerId,
- void * userData );
+typedef bool ( *handshakeDoneCB )( struct tr_handshake * handshake,
+ struct tr_peerIo * io,
+ bool readAnythingFromPeer,
+ bool isConnected,
+ const uint8_t * peerId,
+ void * userData );
/** @brief instantiate a new handshake */
tr_handshake * tr_handshakeNew( struct tr_peerIo * io,
{
int fd;
int err = 0;
- const tr_bool doWrite = ioMode >= TR_IO_WRITE;
+ const bool doWrite = ioMode >= TR_IO_WRITE;
const tr_info * const info = &tor->info;
const tr_file * const file = &info->files[fileIndex];
*****
****/
-static tr_bool
-recalculateHash( tr_torrent * tor,
- tr_piece_index_t pieceIndex,
- uint8_t * setme )
+static bool
+recalculateHash( tr_torrent * tor, tr_piece_index_t pieceIndex, uint8_t * setme )
{
size_t bytesLeft;
uint32_t offset = 0;
- tr_bool success = TRUE;
+ bool success = true;
const size_t buflen = tor->blockSize;
void * buffer = tr_valloc( buflen );
SHA_CTX sha;
return success;
}
-tr_bool
+bool
tr_ioTestPiece( tr_torrent * tor, tr_piece_index_t piece )
{
uint8_t hash[SHA_DIGEST_LENGTH];
/**
* @brief Test to see if the piece matches its metainfo's SHA1 checksum.
*/
-tr_bool tr_ioTestPiece( tr_torrent * tor,
- tr_piece_index_t piece );
+bool tr_ioTestPiece( tr_torrent * tor,
+ tr_piece_index_t piece );
/**
struct json_benc_data
{
- tr_bool hasContent;
+ bool hasContent;
tr_benc * top;
tr_ptrArray stack;
char * key;
switch( type )
{
case JSON_T_ARRAY_BEGIN:
- data->hasContent = TRUE;
+ data->hasContent = true;
node = getNode( data );
tr_bencInitList( node, 0 );
tr_ptrArrayAppend( &data->stack, node );
break;
case JSON_T_OBJECT_BEGIN:
- data->hasContent = TRUE;
+ data->hasContent = true;
node = getNode( data );
tr_bencInitDict( node, 0 );
tr_ptrArrayAppend( &data->stack, node );
break;
case JSON_T_FLOAT:
- data->hasContent = TRUE;
+ data->hasContent = true;
tr_bencInitReal( getNode( data ), value->vu.float_value );
break;
case JSON_T_NULL:
- data->hasContent = TRUE;
+ data->hasContent = true;
tr_bencInitStr( getNode( data ), "", 0 );
break;
case JSON_T_INTEGER:
- data->hasContent = TRUE;
+ data->hasContent = true;
tr_bencInitInt( getNode( data ), value->vu.integer_value );
break;
case JSON_T_TRUE:
- data->hasContent = TRUE;
+ data->hasContent = true;
tr_bencInitBool( getNode( data ), 1 );
break;
case JSON_T_FALSE:
- data->hasContent = TRUE;
+ data->hasContent = true;
tr_bencInitBool( getNode( data ), 0 );
break;
case JSON_T_STRING:
- data->hasContent = TRUE;
+ data->hasContent = true;
tr_bencInitStr( getNode( data ),
value->vu.str.value,
value->vu.str.length );
break;
case JSON_T_KEY:
- data->hasContent = TRUE;
+ data->hasContent = true;
assert( !data->key );
data->key = tr_strdup( value->vu.str.value );
break;
config.callback_ctx = &data;
config.depth = -1;
- data.hasContent = FALSE;
+ data.hasContent = false;
data.key = NULL;
data.top = setme_benc;
data.stack = TR_PTR_ARRAY_INIT;
tr_magnet_info *
tr_magnetParse( const char * uri )
{
- tr_bool got_checksum = FALSE;
+ bool got_checksum = false;
int trCount = 0;
int wsCount = 0;
char * tr[MAX_TRACKERS];
if( hashlen == 40 ) {
tr_hex_to_sha1( sha1, hash );
- got_checksum = TRUE;
+ got_checksum = true;
}
else if( hashlen == 32 ) {
base32_to_sha1( sha1, hash, hashlen );
- got_checksum = TRUE;
+ got_checksum = true;
}
}
builder->errfile[0] = '\0';
builder->my_errno = ENOENT;
builder->result = TR_MAKEMETA_IO_READ;
- builder->isDone = TRUE;
+ builder->isDone = true;
}
if( !builder->result && builder->trackerCount )
****
***/
-static tr_bool
+static bool
path_is_suspicious( const char * path )
{
return ( path == NULL )
|| ( strstr( path, "../" ) != NULL );
}
-static tr_bool
+static bool
getfile( char ** setme, const char * root, tr_benc * path )
{
- tr_bool success = FALSE;
+ bool success = false;
if( tr_bencIsList( path ) )
{
*setme = tr_utf8clean( tmp, -1 );
tr_free( tmp );
/* fprintf( stderr, "[%s]\n", *setme ); */
- success = TRUE;
+ success = true;
}
if( ( *setme != NULL ) && path_is_suspicious( *setme ) )
{
tr_free( *setme );
*setme = NULL;
- success = FALSE;
+ success = false;
}
return success;
{
tr_benc * tier = tr_bencListChild( tiers, i );
const int tierSize = tr_bencListSize( tier );
- tr_bool anyAdded = FALSE;
+ bool anyAdded = false;
for( j = 0; j < tierSize; ++j )
{
if( tr_bencGetStr( tr_bencListChild( tier, j ), &str ) )
t->scrape = tr_convertAnnounceToScrape( url );
t->id = trackerCount;
- anyAdded = TRUE;
+ anyAdded = true;
++trackerCount;
}
tr_free( url );
static const char*
tr_metainfoParseImpl( const tr_session * session,
tr_info * inf,
- tr_bool * hasInfoDict,
+ bool * hasInfoDict,
int * infoDictLength,
const tr_benc * meta_in )
{
tr_benc * d;
tr_benc * infoDict = NULL;
tr_benc * meta = (tr_benc *) meta_in;
- tr_bool b;
- tr_bool isMagnet = FALSE;
+ bool b;
+ bool isMagnet = false;
/* info_hash: urlencoded 20-byte SHA1 hash of the value of the info key
* from the Metainfo file. Note that the value will be a bencoded
/* no info dictionary... is this a magnet link? */
if( tr_bencDictFindDict( meta, "magnet-info", &d ) )
{
- isMagnet = TRUE;
+ isMagnet = true;
/* get the info-hash */
if( !tr_bencDictFindRaw( d, "info_hash", &raw, &raw_len ) )
return NULL;
}
-tr_bool
+bool
tr_metainfoParse( const tr_session * session,
const tr_benc * meta_in,
tr_info * inf,
- tr_bool * hasInfoDict,
+ bool * hasInfoDict,
int * infoDictLength )
{
const char * badTag = tr_metainfoParseImpl( session,
hasInfoDict,
infoDictLength,
meta_in );
- const tr_bool success = badTag == NULL;
+ const bool success = badTag == NULL;
if( badTag )
{
struct tr_benc;
-tr_bool tr_metainfoParse( const tr_session * session,
- const struct tr_benc * benc,
- tr_info * setmeInfo,
- tr_bool * setmeHasInfoDict,
- int * setmeInfoDictLength );
+bool tr_metainfoParse( const tr_session * session,
+ const struct tr_benc * benc,
+ tr_info * setmeInfo,
+ bool * setmeHasInfoDict,
+ int * setmeInfoDictLength );
void tr_metainfoRemoveSaved( const tr_session * session,
const tr_info * info );
struct tr_natpmp
{
- tr_bool has_discovered;
- tr_bool is_mapped;
+ bool has_discovered;
+ bool is_mapped;
tr_port public_port;
tr_port private_port;
}
int
-tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, tr_bool is_enabled, tr_port * public_port )
+tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, bool is_enabled, tr_port * public_port )
{
int ret;
val = sendpublicaddressrequest( &nat->natpmp );
logVal( "sendpublicaddressrequest", val );
nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_PUB;
- nat->has_discovered = TRUE;
+ nat->has_discovered = true;
setCommandTime( nat );
}
nat->private_port = 0;
nat->public_port = 0;
nat->state = TR_NATPMP_IDLE;
- nat->is_mapped = FALSE;
+ nat->is_mapped = false;
}
}
else if( val != NATPMP_TRYAGAIN )
if( val >= 0 )
{
nat->state = TR_NATPMP_IDLE;
- nat->is_mapped = TRUE;
+ nat->is_mapped = true;
nat->renew_time = tr_time( ) + ( resp.pnu.newportmapping.lifetime / 2 );
nat->private_port = resp.pnu.newportmapping.privateport;
nat->public_port = resp.pnu.newportmapping.mappedpublicport;
void tr_natpmpClose( tr_natpmp * );
-int tr_natpmpPulse( tr_natpmp *, tr_port port, tr_bool isEnabled, tr_port * public_port );
+int tr_natpmpPulse( tr_natpmp *, tr_port port, bool isEnabled, tr_port * public_port );
/* @} */
#endif
void
tr_netInit( void )
{
- static int initialized = FALSE;
+ static int initialized = false;
if( !initialized )
{
WSADATA wsaData;
WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
#endif
- initialized = TRUE;
+ initialized = true;
}
}
#endif
}
-tr_bool
+bool
tr_ssToAddr( tr_address * setme_addr,
tr_port * setme_port,
const struct sockaddr_storage * from )
setme_addr->type = TR_AF_INET;
setme_addr->addr.addr4.s_addr = sin->sin_addr.s_addr;
*setme_port = sin->sin_port;
- return TRUE;
+ return true;
}
if( from->ss_family == AF_INET6 )
setme_addr->type = TR_AF_INET6;
setme_addr->addr.addr6 = sin6->sin6_addr;
*setme_port = sin6->sin6_port;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
static socklen_t
tr_netOpenPeerSocket( tr_session * session,
const tr_address * addr,
tr_port port,
- tr_bool clientIsSeed )
+ bool clientIsSeed )
{
static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
int s;
tr_netOpenPeerUTPSocket( tr_session * session,
const tr_address * addr,
tr_port port,
- tr_bool clientIsSeed UNUSED )
+ bool clientIsSeed UNUSED )
{
struct sockaddr_storage ss;
socklen_t sslen;
}
static int
-tr_netBindTCPImpl( const tr_address * addr, tr_port port, tr_bool suppressMsgs, int * errOut )
+tr_netBindTCPImpl( const tr_address * addr, tr_port port, bool suppressMsgs, int * errOut )
{
static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
struct sockaddr_storage sock;
}
int
-tr_netBindTCP( const tr_address * addr, tr_port port, tr_bool suppressMsgs )
+tr_netBindTCP( const tr_address * addr, tr_port port, bool suppressMsgs )
{
int unused;
return tr_netBindTCPImpl( addr, port, suppressMsgs, &unused );
}
-tr_bool
+bool
tr_net_hasIPv6( tr_port port )
{
- static tr_bool result = FALSE;
- static tr_bool alreadyDone = FALSE;
+ static bool result = false;
+ static bool alreadyDone = false;
if( !alreadyDone )
{
int err;
- int fd = tr_netBindTCPImpl( &tr_in6addr_any, port, TRUE, &err );
+ int fd = tr_netBindTCPImpl( &tr_in6addr_any, port, true, &err );
if( fd >= 0 || err != EAFNOSUPPORT ) /* we support ipv6 */
- result = TRUE;
+ result = true;
if( fd >= 0 )
tr_netCloseSocket( fd );
- alreadyDone = TRUE;
+ alreadyDone = true;
}
return result;
****
***/
-static tr_bool
+static bool
isIPv4MappedAddress( const tr_address * addr )
{
return ( addr->type == TR_AF_INET6 ) && IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 );
}
-static tr_bool
+static bool
isIPv6LinkLocalAddress( const tr_address * addr )
{
return ( ( addr->type == TR_AF_INET6 )
/* isMartianAddr was written by Juliusz Chroboczek,
and is covered under the same license as third-party/dht/dht.c. */
-static tr_bool
+static bool
isMartianAddr( const struct tr_address * a )
{
static const unsigned char zeroes[16] =
}
default:
- return TRUE;
+ return true;
}
}
-tr_bool
+bool
tr_isValidPeerAddress( const tr_address * addr, tr_port port )
{
return ( port != 0 )
extern const tr_address tr_inaddr_any;
extern const tr_address tr_in6addr_any;
-tr_bool tr_ssToAddr( tr_address * setme_addr,
- tr_port * setme_port,
- const struct sockaddr_storage * from );
+bool tr_ssToAddr( tr_address * setme_addr,
+ tr_port * setme_port,
+ const struct sockaddr_storage * from );
const char *tr_ntop( const tr_address * src,
char * dst,
int tr_compareAddresses( const tr_address * a,
const tr_address * b);
-tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
+bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
-static inline tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
+static inline bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
-tr_bool tr_net_hasIPv6( tr_port );
+bool tr_net_hasIPv6( tr_port );
/***********************************************************************
* Sockets
int tr_netOpenPeerSocket( tr_session * session,
const tr_address * addr,
tr_port port,
- tr_bool clientIsSeed );
+ bool clientIsSeed );
struct UTPSocket *
tr_netOpenPeerUTPSocket( tr_session * session,
const tr_address * addr,
tr_port port,
- tr_bool clientIsSeed);
+ bool clientIsSeed);
int tr_netBindTCP( const tr_address * addr,
tr_port port,
- tr_bool suppressMsgs );
+ bool suppressMsgs );
int tr_netAccept( tr_session * session,
int bound,
uint32_t offset; /* for GOT_BLOCK */
uint32_t length; /* for GOT_BLOCK + GOT_DATA */
int err; /* errno for GOT_ERROR */
- tr_bool wasPieceData; /* for GOT_DATA */
+ bool wasPieceData; /* for GOT_DATA */
tr_port port; /* for GOT_PORT */
}
tr_peer_event;
struct tr_datatype
{
- tr_bool isPieceData;
- size_t length;
+ bool isPieceData;
+ size_t length;
};
tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData, now );
if( overhead > 0 )
- tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE, now );
+ tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, false, now );
if( io->didWrite )
io->didWrite( io, payload, next->isPieceData, io->userData );
static void
canReadWrapper( tr_peerIo * io )
{
- tr_bool err = 0;
- tr_bool done = 0;
+ bool err = 0;
+ bool done = 0;
tr_session * session;
dbgmsg( io, "canRead" );
if( piece || (piece!=used) )
{
if( piece )
- tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, TRUE, now );
+ tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, true, now );
if( used != piece )
- tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, FALSE, now );
+ tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, false, now );
}
if( overhead > 0 )
- tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE, now );
+ tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, false, now );
switch( ret )
{
/* if we don't have any bandwidth left, stop reading */
if( howmuch < 1 ) {
- tr_peerIoSetEnabled( io, dir, FALSE );
+ tr_peerIoSetEnabled( io, dir, false );
return;
}
if( res > 0 )
{
- tr_peerIoSetEnabled( io, dir, TRUE );
+ tr_peerIoSetEnabled( io, dir, true );
/* Invoke the user callback - must always be called last */
canReadWrapper( io );
what |= BEV_EVENT_EOF;
else if( res == -1 ) {
if( e == EAGAIN || e == EINTR ) {
- tr_peerIoSetEnabled( io, dir, TRUE );
+ tr_peerIoSetEnabled( io, dir, true );
return;
}
what |= BEV_EVENT_ERROR;
/* if we don't have any bandwidth left, stop writing */
if( howmuch < 1 ) {
- tr_peerIoSetEnabled( io, dir, FALSE );
+ tr_peerIoSetEnabled( io, dir, false );
return;
}
goto error;
if( evbuffer_get_length( io->outbuf ) )
- tr_peerIoSetEnabled( io, dir, TRUE );
+ tr_peerIoSetEnabled( io, dir, true );
didWriteWrapper( io, res );
return;
reschedule:
if( evbuffer_get_length( io->outbuf ) )
- tr_peerIoSetEnabled( io, dir, TRUE );
+ tr_peerIoSetEnabled( io, dir, true );
return;
error:
return;
}
- tr_peerIoSetEnabled( io, TR_DOWN, TRUE );
+ tr_peerIoSetEnabled( io, TR_DOWN, true );
canReadWrapper( io );
}
if( state == UTP_STATE_CONNECT ) {
dbgmsg( io, "utp_on_state_change -- changed to connected" );
- io->utpSupported = TRUE;
+ io->utpSupported = true;
} else if( state == UTP_STATE_WRITABLE ) {
dbgmsg( io, "utp_on_state_change -- changed to writable" );
} else if( state == UTP_STATE_EOF ) {
dbgmsg( io, "utp_on_overhead -- count is %zu", count );
tr_bandwidthUsed( &io->bandwidth, send ? TR_UP : TR_DOWN,
- count, FALSE, tr_time_msec() );
+ count, false, tr_time_msec() );
}
static struct UTPFunctionTable utp_function_table = {
const tr_address * addr,
tr_port port,
const uint8_t * torrentHash,
- tr_bool isIncoming,
- tr_bool isSeed,
+ bool isIncoming,
+ bool isSeed,
int socket,
struct UTPSocket * utp_socket)
{
assert( session );
assert( tr_isAddress( addr ) );
- return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE,
+ return tr_peerIoNew( session, parent, addr, port, NULL, true, false,
fd, utp_socket );
}
const tr_address * addr,
tr_port port,
const uint8_t * torrentHash,
- tr_bool isSeed,
- tr_bool utp )
+ bool isSeed,
+ bool utp )
{
int fd = -1;
struct UTPSocket *utp_socket = NULL;
return NULL;
return tr_peerIoNew( session, parent, addr, port,
- torrentHash, FALSE, isSeed, fd, utp_socket );
+ torrentHash, false, isSeed, fd, utp_socket );
}
/***
void
tr_peerIoSetEnabled( tr_peerIo * io,
tr_direction dir,
- tr_bool isEnabled )
+ bool isEnabled )
{
const short event = dir == TR_UP ? EV_WRITE : EV_READ;
tr_peerIoClear( tr_peerIo * io )
{
tr_peerIoSetIOFuncs( io, NULL, NULL, NULL, NULL );
- tr_peerIoSetEnabled( io, TR_UP, FALSE );
- tr_peerIoSetEnabled( io, TR_DOWN, FALSE );
+ tr_peerIoSetEnabled( io, TR_UP, false );
+ tr_peerIoSetEnabled( io, TR_DOWN, false );
}
int
**/
static void
-addDatatype( tr_peerIo * io, size_t byteCount, tr_bool isPieceData )
+addDatatype( tr_peerIo * io, size_t byteCount, bool isPieceData )
{
struct tr_datatype * d;
}
void
-tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, tr_bool isPieceData )
+tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, bool isPieceData )
{
const size_t byteCount = evbuffer_get_length( buf );
maybeEncryptBuffer( io, buf );
}
void
-tr_peerIoWriteBytes( tr_peerIo * io, const void * bytes, size_t byteCount, tr_bool isPieceData )
+tr_peerIoWriteBytes( tr_peerIo * io, const void * bytes, size_t byteCount, bool isPieceData )
{
struct evbuffer * buf = evbuffer_new( );
evbuffer_add( buf, bytes, byteCount );
typedef struct tr_peerIo
{
- tr_bool isEncrypted;
- tr_bool isIncoming;
- tr_bool peerIdIsSet;
- tr_bool extendedProtocolSupported;
- tr_bool fastExtensionSupported;
- tr_bool dhtSupported;
- tr_bool utpSupported;
+ bool isEncrypted;
+ bool isIncoming;
+ bool peerIdIsSet;
+ bool extendedProtocolSupported;
+ bool fastExtensionSupported;
+ bool dhtSupported;
+ bool utpSupported;
tr_priority_t priority;
int magicNumber;
uint32_t encryptionMode;
- tr_bool isSeed;
+ bool isSeed;
tr_port port;
int socket;
const struct tr_address * addr,
tr_port port,
const uint8_t * torrentHash,
- tr_bool isSeed,
- tr_bool utp );
+ bool isSeed,
+ bool utp );
tr_peerIo* tr_peerIoNewIncoming( tr_session * session,
#define PEER_IO_MAGIC_NUMBER 206745
-static inline tr_bool
+static inline bool
tr_isPeerIo( const tr_peerIo * io )
{
return ( io != NULL )
***
**/
-static inline void tr_peerIoEnableFEXT( tr_peerIo * io, tr_bool flag )
+static inline void tr_peerIoEnableFEXT( tr_peerIo * io, bool flag )
{
io->fastExtensionSupported = flag;
}
-static inline tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io )
+static inline bool tr_peerIoSupportsFEXT( const tr_peerIo * io )
{
return io->fastExtensionSupported;
}
-static inline void tr_peerIoEnableLTEP( tr_peerIo * io, tr_bool flag )
+static inline void tr_peerIoEnableLTEP( tr_peerIo * io, bool flag )
{
io->extendedProtocolSupported = flag;
}
-static inline tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io )
+static inline bool tr_peerIoSupportsLTEP( const tr_peerIo * io )
{
return io->extendedProtocolSupported;
}
-static inline void tr_peerIoEnableDHT( tr_peerIo * io, tr_bool flag )
+static inline void tr_peerIoEnableDHT( tr_peerIo * io, bool flag )
{
io->dhtSupported = flag;
}
-static inline tr_bool tr_peerIoSupportsDHT( const tr_peerIo * io )
+static inline bool tr_peerIoSupportsDHT( const tr_peerIo * io )
{
return io->dhtSupported;
}
-static inline tr_bool tr_peerIoSupportsUTP( const tr_peerIo * io )
+static inline bool tr_peerIoSupportsUTP( const tr_peerIo * io )
{
return io->dhtSupported;
}
int tr_peerIoReconnect( tr_peerIo * io );
-static inline tr_bool tr_peerIoIsIncoming( const tr_peerIo * io )
+static inline bool tr_peerIoIsIncoming( const tr_peerIo * io )
{
return io->isIncoming;
}
void tr_peerIoWriteBytes ( tr_peerIo * io,
const void * writeme,
size_t writemeLen,
- tr_bool isPieceData );
+ bool isPieceData );
void tr_peerIoWriteBuf ( tr_peerIo * io,
struct evbuffer * buf,
- tr_bool isPieceData );
+ bool isPieceData );
/**
***
void tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode );
-static inline tr_bool
+static inline bool
tr_peerIoIsEncrypted( const tr_peerIo * io )
{
return ( io != NULL ) && ( io->encryptionMode == PEER_ENCRYPTION_RC4 );
size_t byteCount,
int isPieceData );
-static inline tr_bool
+static inline bool
tr_peerIoHasBandwidthLeft( const tr_peerIo * io, tr_direction dir )
{
return tr_bandwidthClamp( &io->bandwidth, dir, 1024 ) > 0;
void tr_peerIoSetEnabled( tr_peerIo * io,
tr_direction dir,
- tr_bool isEnabled );
+ bool isEnabled );
int tr_peerIoFlush( tr_peerIo * io,
tr_direction dir,
CANCEL_HISTORY_SEC = 60
};
-const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, FALSE, 0 };
+const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, false, 0 };
/**
***
uint8_t flags; /* these match the added_f flags */
uint8_t flags2; /* flags that aren't defined in added_f */
int8_t seedProbability; /* how likely is this to be a seed... [0..100] or -1 for unknown */
- int8_t blocklisted; /* -1 for unknown, TRUE for blocklisted, FALSE for not blocklisted */
+ int8_t blocklisted; /* -1 for unknown, true for blocklisted, false for not blocklisted */
tr_port port;
- tr_bool utp_failed; /* We recently failed to connect over uTP */
+ bool utp_failed; /* We recently failed to connect over uTP */
uint16_t numFails;
time_t time; /* when the peer's connection status last changed */
time_t piece_data_time;
#ifdef NDEBUG
#define tr_isAtom(a) (TRUE)
#else
-static tr_bool
+static bool
tr_isAtom( const struct peer_atom * atom )
{
return ( atom != NULL )
tr_peer * optimistic; /* the optimistic peer, or NULL if none */
int optimisticUnchokeTimeScaler;
- tr_bool isRunning;
- tr_bool needsCompletenessCheck;
+ bool isRunning;
+ bool needsCompletenessCheck;
struct block_request * requests;
int requestCount;
return tr_ptrArrayFindSorted( &tt->pool, addr, comparePeerAtomToAddress );
}
-static tr_bool
+static bool
peerIsInUse( const Torrent * ct, const struct peer_atom * atom )
{
Torrent * t = (Torrent*) ct;
tr_free( peer );
}
-static tr_bool
+static bool
replicationExists( const Torrent * t )
{
return t->pieceReplication != NULL;
clientIsDownloadingFrom( const tr_torrent * tor, const tr_peer * peer )
{
if( !tr_torrentHasMetadata( tor ) )
- return TRUE;
+ return true;
return peer->clientIsInterested && !peer->clientIsChoked;
}
}
}
-static tr_bool
+static bool
isAtomBlocklisted( tr_session * session, struct peer_atom * atom )
{
if( atom->blocklisted < 0 )
atom->flags &= ~ADDED_F_SEED_FLAG;
}
-static inline tr_bool
+static inline bool
atomIsSeed( const struct peer_atom * atom )
{
return atom->seedProbability == 100;
}
-tr_bool
+bool
tr_peerMgrPeerIsSeed( const tr_torrent * tor,
const tr_address * addr )
{
- tr_bool isSeed = FALSE;
+ bool isSeed = false;
const Torrent * t = tor->torrentPeers;
const struct peer_atom * atom = getExistingAtom( t, addr );
}
void
-tr_peerMgrSetUtpFailed( tr_torrent *tor, const tr_address *addr, tr_bool failed )
+tr_peerMgrSetUtpFailed( tr_torrent *tor, const tr_address *addr, bool failed )
{
struct peer_atom * atom = getExistingAtom( tor->torrentPeers, addr );
/* insert the request to our array... */
{
- tr_bool exact;
+ bool exact;
const int pos = tr_lowerBound( &key, t->requests, t->requestCount,
sizeof( struct block_request ),
compareReqByBlock, &exact );
getBlockRequestPeers( Torrent * t, tr_block_index_t block,
tr_ptrArray * peerArr )
{
- tr_bool exact;
+ bool exact;
int i, pos;
struct block_request key;
pieceListResortPiece( Torrent * t, struct weighted_piece * p )
{
int pos;
- tr_bool isSorted = TRUE;
+ bool isSorted = true;
if( p == NULL )
return;
pos = p - t->pieces;
setComparePieceByWeightTorrent( t );
if( isSorted && ( pos > 0 ) && ( comparePieceByWeight( p-1, p ) > 0 ) )
- isSorted = FALSE;
+ isSorted = false;
if( isSorted && ( pos < t->pieceCount - 1 ) && ( comparePieceByWeight( p, p+1 ) > 0 ) )
- isSorted = FALSE;
+ isSorted = false;
if( t->pieceSortState != PIECES_SORTED_BY_WEIGHT )
{
pieceListSort( t, PIECES_SORTED_BY_WEIGHT);
- isSorted = TRUE;
+ isSorted = true;
}
/* if it's not sorted, move it around */
if( !isSorted )
{
- tr_bool exact;
+ bool exact;
const struct weighted_piece tmp = *p;
tr_removeElementFromArray( t->pieces,
setComparePieceByWeightTorrent( t );
while( --i >= 0 )
{
- tr_bool exact;
+ bool exact;
/* relative position! */
const int newpos = tr_lowerBound( &t->pieces[i], &t->pieces[i + 1],
*numgot = got;
}
-tr_bool
+bool
tr_peerMgrDidPeerRequest( const tr_torrent * tor,
const tr_peer * peer,
tr_block_index_t block )
break;
case TR_PEER_CLIENT_GOT_SUGGEST:
- peerSuggestedPiece( t, peer, e->pieceIndex, FALSE );
+ peerSuggestedPiece( t, peer, e->pieceIndex, false );
break;
case TR_PEER_CLIENT_GOT_ALLOWED_FAST:
- peerSuggestedPiece( t, peer, e->pieceIndex, TRUE );
+ peerSuggestedPiece( t, peer, e->pieceIndex, true );
break;
case TR_PEER_CLIENT_GOT_DATA:
removeRequestFromTables( t, block, p );
}
- tr_ptrArrayDestruct( &peerArr, FALSE );
+ tr_ptrArrayDestruct( &peerArr, false );
tr_historyAdd( &peer->blocksSentToClient, tr_time( ), 1 );
if( tr_cpPieceIsComplete( &tor->completion, e->pieceIndex ) )
{
const tr_piece_index_t p = e->pieceIndex;
- const tr_bool ok = tr_torrentCheckPiece( tor, p );
+ const bool ok = tr_torrentCheckPiece( tor, p );
tordbg( t, "[LAZY] checked just-completed piece %zu", (size_t)p );
}
}
- t->needsCompletenessCheck = TRUE;
+ t->needsCompletenessCheck = true;
}
break;
}
}
/* FIXME: this is kind of a mess. */
-static tr_bool
+static bool
myHandshakeDoneCB( tr_handshake * handshake,
tr_peerIo * io,
- tr_bool readAnythingFromPeer,
- tr_bool isConnected,
+ bool readAnythingFromPeer,
+ bool isConnected,
const uint8_t * peer_id,
void * vmanager )
{
- tr_bool ok = isConnected;
- tr_bool success = FALSE;
+ bool ok = isConnected;
+ bool success = false;
tr_port port;
const tr_address * addr;
tr_peerMgr * manager = vmanager;
tr_peerIoSetParent( peer->io, t->tor->bandwidth );
tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t );
- success = TRUE;
+ success = true;
}
}
}
peerPrefersCrypto( const tr_peer * peer )
{
if( peer->encryption_preference == ENCRYPTION_PREFERENCE_YES )
- return TRUE;
+ return true;
if( peer->encryption_preference == ENCRYPTION_PREFERENCE_NO )
- return FALSE;
+ return false;
return tr_peerIoIsEncrypted( peer->io );
}
ensureMgrTimersExist( t->manager );
- t->isRunning = TRUE;
+ t->isRunning = true;
t->maxPeers = t->tor->maxConnectedPeers;
t->pieceSortState = PIECES_UNSORTED;
{
int i, n;
- t->isRunning = FALSE;
+ t->isRunning = false;
replicationFree( t );
invalidatePieceSorting( t );
const int peerCount = tr_ptrArraySize( &tor->torrentPeers->peers );
const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase( &tor->torrentPeers->peers );
const float interval = tor->info.pieceCount / (float)tabCount;
- const tr_bool isSeed = tr_cpGetStatus( &tor->completion ) == TR_SEED;
+ const bool isSeed = tr_cpGetStatus( &tor->completion ) == TR_SEED;
for( i=0; i<tabCount; ++i )
{
return peer->io ? tr_peerIoGetPieceSpeed_Bps( peer->io, now, direction ) : 0.0;
}
-static tr_bool
+static bool
peerIsSeed( const tr_peer * peer )
{
if( peer->progress >= 1.0 )
- return TRUE;
+ return true;
if( peer->atom && atomIsSeed( peer->atom ) )
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
struct tr_peer_stat *
for( i=0; i<peerCount; ++i )
{
const tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
- tr_peerMsgsSetInterested( peer->msgs, FALSE );
+ tr_peerMsgsSetInterested( peer->msgs, false );
}
}
/* do we still want this piece and does the peer have it? */
-static tr_bool
+static bool
isPieceInteresting( const tr_torrent * tor, const tr_peer * peer, tr_piece_index_t index )
{
return ( !tor->info.pieces[index].dnd ) /* we want it */
}
/* does this peer have any pieces that we want? */
-static tr_bool
+static bool
isPeerInteresting( const tr_torrent * tor, const tr_peer * peer )
{
tr_piece_index_t i, n;
if ( tr_torrentIsSeed( tor ) )
- return FALSE;
+ return false;
if( !tr_torrentIsPieceTransferAllowed( tor, TR_PEER_TO_CLIENT ) )
- return FALSE;
+ return false;
for( i=0, n=tor->info.pieceCount; i<n; ++i )
if( isPieceInteresting( tor, peer, i ) )
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
/* determines who we send "interested" messages to */
if( !isPeerInteresting( t->tor, peer ) )
{
- tr_peerMsgsSetInterested( peer->msgs, FALSE );
+ tr_peerMsgsSetInterested( peer->msgs, false );
}
else
{
* and (2) which peers are the best candidates,
* Now it's time to update our `interest' flags. */
for( i=0; i<goodCount; ++i ) {
- const tr_bool b = t->interestedCount < maxPeers;
+ const bool b = t->interestedCount < maxPeers;
tr_peerMsgsSetInterested( good[i]->msgs, b );
if( b )
++t->interestedCount;
}
for( i=0; i<untestedCount; ++i ) {
- const tr_bool b = t->interestedCount < maxPeers;
+ const bool b = t->interestedCount < maxPeers;
tr_peerMsgsSetInterested( untested[i]->msgs, b );
if( b )
++t->interestedCount;
}
for( i=0; i<badCount; ++i ) {
- const tr_bool b = t->interestedCount < maxPeers;
+ const bool b = t->interestedCount < maxPeers;
tr_peerMsgsSetInterested( bad[i]->msgs, b );
if( b )
++t->interestedCount;
struct ChokeData
{
- tr_bool isInterested;
- tr_bool wasChoked;
- tr_bool isChoked;
+ bool isInterested;
+ bool wasChoked;
+ bool isChoked;
int rate;
int salt;
tr_peer * peer;
return Bps;
}
-static inline tr_bool
+static inline bool
isBandwidthMaxedOut( const tr_bandwidth * b,
const uint64_t now_msec, tr_direction dir )
{
if( !tr_bandwidthIsLimited( b, dir ) )
- return FALSE;
+ return false;
else {
const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir );
const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir );
struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
const tr_session * session = t->manager->session;
const int chokeAll = !tr_torrentIsPieceTransferAllowed( t->tor, TR_CLIENT_TO_PEER );
- const tr_bool isMaxedOut = isBandwidthMaxedOut( t->tor->bandwidth, now, TR_UP );
+ const bool isMaxedOut = isBandwidthMaxedOut( t->tor->bandwidth, now, TR_UP );
assert( torrentIsLocked( t ) );
if( peerIsSeed( peer ) ) /* choke seeds and partial seeds */
{
- tr_peerMsgsSetChoke( peer->msgs, TRUE );
+ tr_peerMsgsSetChoke( peer->msgs, true );
}
else if( chokeAll ) /* choke everyone if we're not uploading */
{
- tr_peerMsgsSetChoke( peer->msgs, TRUE );
+ tr_peerMsgsSetChoke( peer->msgs, true );
}
else if( peer != t->optimistic )
{
n->wasChoked = peer->peerIsChoked;
n->rate = getRate( t->tor, atom, now );
n->salt = tr_cryptoWeakRandInt( INT_MAX );
- n->isChoked = TRUE;
+ n->isChoked = true;
}
}
*/
unchokedInterested = 0;
for( i=0; i<size && unchokedInterested<session->uploadSlotsPerTorrent; ++i ) {
- choke[i].isChoked = isMaxedOut ? choke[i].wasChoked : FALSE;
+ choke[i].isChoked = isMaxedOut ? choke[i].wasChoked : false;
if( choke[i].isInterested )
++unchokedInterested;
}
if(( n = tr_ptrArraySize( &randPool )))
{
c = tr_ptrArrayNth( &randPool, tr_cryptoWeakRandInt( n ));
- c->isChoked = FALSE;
+ c->isChoked = false;
t->optimistic = c->peer;
t->optimisticUnchokeTimeScaler = OPTIMISTIC_UNCHOKE_MULTIPLIER;
}
****
***/
-static tr_bool
+static bool
shouldPeerBeClosed( const Torrent * t,
const tr_peer * peer,
int peerCount,
{
tordbg( t, "purging peer %s because its doPurge flag is set",
tr_atomAddrStr( atom ) );
- return TRUE;
+ return true;
}
/* disconnect if we're both seeds and enough time has passed for PEX */
if( idleTime > limit ) {
tordbg( t, "purging peer %s because it's been %d secs since we shared anything",
tr_atomAddrStr( atom ), idleTime );
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
static tr_peer **
time_t pieceDataTime;
time_t time;
int speed;
- tr_bool doPurge;
+ bool doPurge;
};
static int
tor = NULL;
while(( tor = tr_torrentNext( mgr->session, tor ))) {
if( tor->torrentPeers->needsCompletenessCheck ) {
- tor->torrentPeers->needsCompletenessCheck = FALSE;
+ tor->torrentPeers->needsCompletenessCheck = false;
tr_torrentRecheckCompleteness( tor );
}
}
***/
/* is this atom someone that we'd want to initiate a connection to? */
-static tr_bool
+static bool
isPeerCandidate( const tr_torrent * tor, struct peer_atom * atom, const time_t now )
{
/* not if we're both seeds */
if( tr_torrentIsSeed( tor ) && atomIsSeed( atom ) )
- return FALSE;
+ return false;
/* not if we've already got a connection to them... */
if( peerIsInUse( tor->torrentPeers, atom ) )
- return FALSE;
+ return false;
/* not if we just tried them already */
if( ( now - atom->time ) < getReconnectIntervalSecs( atom, now ) )
- return FALSE;
+ return false;
/* not if they're blocklisted */
if( isAtomBlocklisted( tor->session, atom ) )
- return FALSE;
+ return false;
/* not if they're banned... */
if( atom->flags2 & MYFLAG_BANNED )
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
struct peer_candidate
struct peer_atom * atom;
};
-static tr_bool
+static bool
torrentWasRecentlyStarted( const tr_torrent * tor )
{
return difftime( tr_time( ), tor->startDate ) < 120;
{
uint64_t i;
uint64_t score = 0;
- const tr_bool failed = atom->lastConnectionAt < atom->lastConnectionAttemptAt;
+ const bool failed = atom->lastConnectionAt < atom->lastConnectionAttemptAt;
/* prefer peers we've connected to, or never tried, over peers we failed to connect to. */
i = failed ? 1 : 0;
{
tr_peerIo * io;
const time_t now = tr_time( );
- tr_bool utp = tr_sessionIsUTPEnabled(mgr->session) && !atom->utp_failed;
+ bool utp = tr_sessionIsUTPEnabled(mgr->session) && !atom->utp_failed;
if( atom->fromFirst == TR_PEER_FROM_PEX )
/* PEX has explicit signalling for uTP support. If an atom
*/
typedef struct tr_peer
{
- tr_bool peerIsChoked;
- tr_bool peerIsInterested;
- tr_bool clientIsChoked;
- tr_bool clientIsInterested;
- tr_bool doPurge;
+ bool peerIsChoked;
+ bool peerIsInterested;
+ bool clientIsChoked;
+ bool clientIsInterested;
+ bool doPurge;
/* number of bad pieces they've contributed to */
uint8_t strikes;
void tr_peerDestruct( tr_torrent * tor, struct tr_peer * peer );
-static inline tr_bool
+static inline bool
tr_isPex( const tr_pex * pex )
{
return pex && tr_isAddress( &pex->addr );
void tr_peerMgrFree( tr_peerMgr * manager );
-tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
+bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
const tr_address * addr );
void tr_peerMgrSetUtpSupported( tr_torrent * tor,
void tr_peerMgrSetUtpFailed( tr_torrent *tor,
const tr_address *addr,
- tr_bool failed );
+ bool failed );
void tr_peerMgrGetNextRequests( tr_torrent * torrent,
tr_peer * peer,
tr_block_index_t * setme,
int * numgot );
-tr_bool tr_peerMgrDidPeerRequest( const tr_torrent * torrent,
- const tr_peer * peer,
- tr_block_index_t block );
+bool tr_peerMgrDidPeerRequest( const tr_torrent * torrent,
+ const tr_peer * peer,
+ tr_block_index_t block );
void tr_peerMgrRebuildRequests( tr_torrent * torrent );
*/
struct tr_peermsgs
{
- tr_bool peerSupportsPex;
- tr_bool peerSupportsMetadataXfer;
- tr_bool clientSentLtepHandshake;
- tr_bool peerSentLtepHandshake;
+ bool peerSupportsPex;
+ bool peerSupportsMetadataXfer;
+ bool clientSentLtepHandshake;
+ bool peerSentLtepHandshake;
- /*tr_bool haveFastSet;*/
+ /*bool haveFastSet;*/
int desiredRequestCount;
}
static void
-firePeerGotData( tr_peermsgs * msgs, uint32_t length, tr_bool wasPieceData )
+firePeerGotData( tr_peermsgs * msgs, uint32_t length, bool wasPieceData )
{
tr_peer_event e = TR_PEER_EVENT_INIT;
static void
updateFastSet( tr_peermsgs * msgs UNUSED )
{
- const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
+ const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
const int peerIsNeedy = msgs->peer->progress < 0.10;
if( fext && peerIsNeedy && !msgs->haveFastSet )
**/
static void
-sendInterest( tr_peermsgs * msgs, tr_bool clientIsInterested )
+sendInterest( tr_peermsgs * msgs, bool clientIsInterested )
{
struct evbuffer * out = msgs->outMessages;
sendInterest( msgs, isInterested );
}
-static tr_bool
+static bool
popNextMetadataRequest( tr_peermsgs * msgs, int * piece )
{
if( msgs->peerAskedForMetadataCount == 0 )
- return FALSE;
+ return false;
*piece = msgs->peerAskedForMetadata[0];
tr_removeElementFromArray( msgs->peerAskedForMetadata, 0, sizeof( int ),
msgs->peerAskedForMetadataCount-- );
- return TRUE;
+ return true;
}
-static tr_bool
+static bool
popNextRequest( tr_peermsgs * msgs, struct peer_request * setme )
{
if( msgs->peer->pendingReqsToClient == 0 )
- return FALSE;
+ return false;
*setme = msgs->peerAskedFor[0];
tr_removeElementFromArray( msgs->peerAskedFor, 0, sizeof( struct peer_request ),
msgs->peer->pendingReqsToClient-- );
- return TRUE;
+ return true;
}
static void
***
**/
-static tr_bool
+static bool
reqIsValid( const tr_peermsgs * peer,
uint32_t index,
uint32_t offset,
return tr_torrentReqIsValid( peer->torrent, index, offset, length );
}
-static tr_bool
+static bool
requestIsValid( const tr_peermsgs * msgs, const struct peer_request * req )
{
return reqIsValid( msgs, req->index, req->offset, req->length );
tr_benc val, *m;
char * buf;
int len;
- tr_bool allow_pex;
- tr_bool allow_metadata_xfer;
+ bool allow_pex;
+ bool allow_metadata_xfer;
struct evbuffer * out = msgs->outMessages;
const unsigned char * ipv6 = tr_globalIPv6();
it implies support for µTP, so use it to indicate that. */
tr_peerMgrSetUtpFailed( msgs->torrent,
tr_peerIoGetAddress( msgs->peer->io, NULL ),
- FALSE );
+ false );
}
}
static void
peerMadeRequest( tr_peermsgs * msgs, const struct peer_request * req )
{
- const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
+ const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
const int reqIsValid = requestIsValid( msgs, req );
const int clientHasPiece = reqIsValid && tr_cpPieceIsComplete( &msgs->torrent->completion, req->index );
const int peerIsChoked = msgs->peer->peerIsChoked;
- int allow = FALSE;
+ int allow = false;
if( !reqIsValid )
dbgmsg( msgs, "rejecting an invalid request." );
else if( msgs->peer->pendingReqsToClient + 1 >= REQQ )
dbgmsg( msgs, "rejecting request ... reqq is full" );
else
- allow = TRUE;
+ allow = true;
if( allow ) {
msgs->peerAskedFor[msgs->peer->pendingReqsToClient++] = *req;
}
}
-static tr_bool
+static bool
messageLengthIsCorrect( const tr_peermsgs * msg, uint8_t id, uint32_t len )
{
switch( id )
if( tr_torrentHasMetadata( msg->torrent ) )
return len == ( msg->torrent->info.pieceCount + 7u ) / 8u + 1u;
/* we don't know the piece count yet,
- so we can only guess whether to send TRUE or FALSE */
+ so we can only guess whether to send true or false */
if( msg->metadata_size_hint > 0 )
return len <= msg->metadata_size_hint;
- return TRUE;
+ return true;
case BT_REQUEST:
case BT_CANCEL:
return len >= 2;
default:
- return FALSE;
+ return false;
}
}
tr_sessionReleaseBuffer( getSession( msgs ) );
buf = NULL;
- fireClientGotData( msgs, n, TRUE );
+ fireClientGotData( msgs, n, true );
*setme_piece_bytes_read += n;
dbgmsg( msgs, "got %zu bytes for block %u:%u->%u ... %d remain",
n, req->index, req->offset, req->length,
#ifndef NDEBUG
const size_t startBufLen = evbuffer_get_length( inbuf );
#endif
- const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
+ const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
--msglen; /* id length */
/* log the raw data that was read */
if( ( ret != READ_ERR ) && ( evbuffer_get_length( in ) != inlen ) )
- fireClientGotData( msgs, inlen - evbuffer_get_length( in ), FALSE );
+ fireClientGotData( msgs, inlen - evbuffer_get_length( in ), false );
return ret;
}
tr_peerMsgsIsReadingBlock( const tr_peermsgs * msgs, tr_block_index_t block )
{
if( msgs->state != AWAITING_BT_PIECE )
- return FALSE;
+ return false;
return block == _tr_block( msgs->torrent,
msgs->incoming.blockReq.index,
int piece;
size_t bytesWritten = 0;
struct peer_request req;
- const tr_bool haveMessages = evbuffer_get_length( msgs->outMessages ) != 0;
- const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
+ const bool haveMessages = evbuffer_get_length( msgs->outMessages ) != 0;
+ const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
/**
*** Protocol messages
const size_t len = evbuffer_get_length( msgs->outMessages );
/* flush the protocol messages */
dbgmsg( msgs, "flushing outMessages... to %p (length is %zu)", msgs->peer->io, len );
- tr_peerIoWriteBuf( msgs->peer->io, msgs->outMessages, FALSE );
+ tr_peerIoWriteBuf( msgs->peer->io, msgs->outMessages, false );
msgs->clientSentAnythingAt = now;
msgs->outMessagesBatchedAt = 0;
msgs->outMessagesBatchPeriod = LOW_PRIORITY_INTERVAL_SECS;
{
char * data;
int dataLen;
- tr_bool ok = FALSE;
+ bool ok = false;
data = tr_torrentGetMetadataPiece( msgs->torrent, piece, &dataLen );
if( ( dataLen > 0 ) && ( data != NULL ) )
tr_free( payload );
tr_free( data );
- ok = TRUE;
+ ok = true;
}
if( !ok ) /* send a rejection message */
const size_t n = evbuffer_get_length( out );
dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length );
assert( n == msglen );
- tr_peerIoWriteBuf( msgs->peer->io, out, TRUE );
+ tr_peerIoWriteBuf( msgs->peer->io, out, true );
bytesWritten += n;
msgs->clientSentAnythingAt = now;
tr_historyAdd( &msgs->peer->blocksSentToPeer, tr_time( ), 1 );
if( fillOutputBuffer( msgs, now ) < 1 )
break;
- return TRUE; /* loop forever */
+ return true; /* loop forever */
}
void
static void
tellPeerWhatWeHave( tr_peermsgs * msgs )
{
- const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
+ const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
if( fext && ( tr_cpBlockBitset( &msgs->torrent->completion )->haveAll ) )
{
if( tr_peerIoSupportsUTP( peer->io ) ) {
const tr_address * addr = tr_peerIoGetAddress( peer->io, NULL );
tr_peerMgrSetUtpSupported( torrent, addr );
- tr_peerMgrSetUtpFailed( torrent, addr, FALSE );
+ tr_peerMgrSetUtpFailed( torrent, addr, false );
}
if( tr_peerIoSupportsLTEP( peer->io ) )
#endif
}
-static tr_bool
+static bool
tr_areThreadsEqual( tr_thread_id a, tr_thread_id b )
{
#ifdef WIN32
#endif
};
-tr_bool
+bool
tr_amInThread( const tr_thread * t )
{
return tr_areThreadsEqual( tr_getCurrentThread( ), t->thread );
static void
migrateFiles( const tr_session * session )
{
- static int migrated = FALSE;
- const tr_bool should_migrate = strstr( getOldConfigDir(), ".transmission" ) != NULL;
+ static int migrated = false;
+ const bool should_migrate = strstr( getOldConfigDir(), ".transmission" ) != NULL;
if( !migrated && should_migrate )
{
const char * oldDir;
const char * newDir;
- migrated = TRUE;
+ migrated = true;
oldDir = getOldTorrentsDir( );
newDir = tr_getTorrentDir( session );
CFStringGetFastestEncoding( appRef ));
char * appString = tr_malloc( appLength + 1 );
- tr_bool success = CFStringGetCString( appRef,
+ bool success = CFStringGetCString( appRef,
appString,
appLength + 1,
CFStringGetFastestEncoding( appRef ));
/** @brief Return nonzero if this function is being called from `thread'
@param thread the thread being tested */
-tr_bool tr_amInThread( const tr_thread * );
+bool tr_amInThread( const tr_thread * );
/***
****
struct tr_shared
{
- tr_bool isEnabled;
- tr_bool isShuttingDown;
- tr_bool doPortCheck;
+ bool isEnabled;
+ bool isShuttingDown;
+ bool doPortCheck;
tr_port_forwarding natpmpStatus;
tr_port_forwarding upnpStatus;
}
static void
-natPulse( tr_shared * s, tr_bool do_check )
+natPulse( tr_shared * s, bool do_check )
{
const tr_port private_peer_port = s->session->private_peer_port;
const int is_enabled = s->isEnabled && !s->isShuttingDown;
case TR_PORT_MAPPED:
/* if we're mapped, everything is fine... check back in 20 minutes
* to renew the port forwarding if it's expired */
- s->doPortCheck = TRUE;
+ s->doPortCheck = true;
sec = 60 * 20;
break;
/* do something */
natPulse( s, s->doPortCheck );
- s->doPortCheck = FALSE;
+ s->doPortCheck = false;
/* set up the timer for the next pulse */
set_evtimer_from_status( s );
tr_shared * s = tr_new0( tr_shared, 1 );
s->session = session;
- s->isEnabled = FALSE;
+ s->isEnabled = false;
s->upnpStatus = TR_PORT_UNMAPPED;
s->natpmpStatus = TR_PORT_UNMAPPED;
stop_forwarding( tr_shared * s )
{
tr_ninf( getKey( ), "%s", _( "Stopped" ) );
- natPulse( s, FALSE );
+ natPulse( s, false );
tr_natpmpClose( s->natpmp );
s->natpmp = NULL;
{
tr_shared * s = session->shared;
- s->isShuttingDown = TRUE;
+ s->isShuttingDown = true;
stop_forwarding( s );
s->session->shared = NULL;
tr_free( s );
}
void
-tr_sharedTraversalEnable( tr_shared * s, tr_bool isEnabled )
+tr_sharedTraversalEnable( tr_shared * s, bool isEnabled )
{
if(( s->isEnabled = isEnabled ))
start_timer( s );
if( s->isEnabled )
{
stop_timer( s );
- natPulse( s, FALSE );
+ natPulse( s, false );
start_timer( s );
}
}
-tr_bool
+bool
tr_sharedTraversalIsEnabled( const tr_shared * s )
{
return s->isEnabled;
void tr_sharedPortChanged( tr_session * );
-void tr_sharedTraversalEnable( tr_shared *, tr_bool isEnabled );
+void tr_sharedTraversalEnable( tr_shared *, bool isEnabled );
tr_port tr_sharedGetPeerPort( const tr_shared * s );
-tr_bool tr_sharedTraversalIsEnabled( const tr_shared * s );
+bool tr_sharedTraversalIsEnabled( const tr_shared * s );
int tr_sharedTraversalStatus( const tr_shared * );
const void * ptr,
int compare( const void *,
const void * ),
- tr_bool * exact_match )
+ bool * exact_match )
{
int len = t->n_items;
int first = 0;
else if( !c )
{
if( exact_match )
- *exact_match = TRUE;
+ *exact_match = true;
return middle;
break;
}
}
if( exact_match )
- *exact_match = FALSE;
+ *exact_match = false;
return first;
}
const void * ptr,
int compare(const void*, const void*) )
{
- tr_bool match;
+ bool match;
const int pos = tr_ptrArrayLowerBound( t, ptr, compare, &match );
return match ? t->items[pos] : NULL;
int compare(const void*, const void*) )
{
void * ret = NULL;
- tr_bool match;
+ bool match;
const int pos = tr_ptrArrayLowerBound( t, ptr, compare, &match );
if( match )
/** @brief Return True if the array has no pointers
@return True if the array has no pointers */
-static inline tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a )
+static inline bool tr_ptrArrayEmpty( const tr_ptrArray * a )
{
return tr_ptrArraySize(a) == 0;
}
int tr_ptrArrayLowerBound( const tr_ptrArray * array,
const void * key,
int compare( const void * arrayItem, const void * key ),
- tr_bool * exact_match );
+ bool * exact_match );
/** @brief Insert a pointer into the array at the position determined by the sort function
@return the index of the stored pointer */
if( dndCount )
{
- tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE );
+ tr_torrentInitFileDLs ( tor, dnd, dndCount, false );
tr_tordbg( tor, "Resume file found %d files listed as dnd",
dndCount );
}
if( dlCount )
{
- tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE );
+ tr_torrentInitFileDLs ( tor, dl, dlCount, true );
tr_tordbg( tor,
"Resume file found %d files marked for download",
dlCount );
loadSingleSpeedLimit( tr_benc * d, tr_direction dir, tr_torrent * tor )
{
int64_t i;
- tr_bool boolVal;
+ bool boolVal;
if( tr_bencDictFindInt( d, KEY_SPEED_Bps, &i ) )
tr_torrentSetSpeedLimit_Bps( tor, dir, i );
const tr_piece * pend;
time_t oldest_nonzero = now;
time_t newest = 0;
- tr_bool has_zero = FALSE;
+ bool has_zero = false;
const time_t mtime = tr_torrentGetFileMTime( tor, fi );
const tr_file * f = &inf->files[fi];
for( p=&inf->pieces[f->firstPiece], pend=&inf->pieces[f->lastPiece]; p!=pend; ++p )
{
if( !p->timeChecked )
- has_zero = TRUE;
+ has_zero = true;
else if( oldest_nonzero > p->timeChecked )
oldest_nonzero = p->timeChecked;
if( newest < p->timeChecked )
{
int64_t i;
const char * str;
- uint64_t fieldsLoaded = 0;
char * filename;
tr_benc top;
- tr_bool boolVal;
- const tr_bool wasDirty = tor->isDirty;
+ bool boolVal;
+ uint64_t fieldsLoaded = 0;
+ const bool wasDirty = tor->isDirty;
assert( tr_isTorrent( tor ) );
if( fields & TR_FR_RUN )
{
- uint8_t isPaused;
+ bool isPaused;
if( !tr_ctorGetPaused( ctor, mode, &isPaused ) )
{
tor->isRunning = !isPaused;
struct tr_rpc_server
{
- tr_bool isEnabled;
- tr_bool isPasswordEnabled;
- tr_bool isWhitelistEnabled;
+ bool isEnabled;
+ bool isPasswordEnabled;
+ bool isWhitelistEnabled;
tr_port port;
char * url;
struct in_addr bindAddress;
time_t sessionIdExpiresAt;
#ifdef HAVE_ZLIB
- tr_bool isStreamInitialized;
+ bool isStreamInitialized;
z_stream stream;
#endif
};
{
int i;
int n;
- tr_bool hasSessionId = FALSE;
+ bool hasSessionId = false;
tr_ptrArray parts = TR_PTR_ARRAY_INIT;
const char * query = strchr( req->uri, '?' );
- const tr_bool paused = query && strstr( query + 1, "paused=true" );
+ const bool paused = query && strstr( query + 1, "paused=true" );
extract_parts_from_multipart( req->input_headers, req->input_buffer, &parts );
n = tr_ptrArraySize( &parts );
int body_len = p->body_len;
tr_benc top, *args;
tr_benc test;
- tr_bool have_source = FALSE;
+ bool have_source = false;
char * body = p->body;
if( body_len >= 2 && !memcmp( &body[body_len - 2], "\r\n", 2 ) )
if( tr_urlIsValid( body, body_len ) )
{
tr_bencDictAddRaw( args, "filename", body, body_len );
- have_source = TRUE;
+ have_source = true;
}
else if( !tr_bencLoad( body, body_len, &test, NULL ) )
{
char * b64 = tr_base64_encode( body, body_len, NULL );
tr_bencDictAddStr( args, "metainfo", b64 );
tr_free( b64 );
- have_source = TRUE;
+ have_source = true;
}
if( have_source )
{
int compressionLevel;
- server->isStreamInitialized = TRUE;
+ server->isStreamInitialized = true;
server->stream.zalloc = (alloc_func) Z_NULL;
server->stream.zfree = (free_func) Z_NULL;
server->stream.opaque = (voidpf) Z_NULL;
}
-static tr_bool
+static bool
isAddressAllowed( const tr_rpc_server * server,
const char * address )
{
tr_list * l;
if( !server->isWhitelistEnabled )
- return TRUE;
+ return true;
for( l=server->whitelist; l!=NULL; l=l->next )
if( tr_wildmat( address, l->data ) )
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
-static tr_bool
+static bool
test_session_id( struct tr_rpc_server * server, struct evhttp_request * req )
{
const char * ours = get_current_session_id( server );
const char * theirs = evhttp_find_header( req->input_headers, TR_RPC_SESSION_ID_HEADER );
- const tr_bool success = theirs && !strcmp( theirs, ours );
+ const bool success = theirs && !strcmp( theirs, ours );
return success;
}
void
tr_rpcSetEnabled( tr_rpc_server * server,
- tr_bool isEnabled )
+ bool isEnabled )
{
server->isEnabled = isEnabled;
tr_runInEventThread( server->session, onEnabledChanged, server );
}
-tr_bool
+bool
tr_rpcIsEnabled( const tr_rpc_server * server )
{
return server->isEnabled;
void
tr_rpcSetWhitelistEnabled( tr_rpc_server * server,
- tr_bool isEnabled )
+ bool isEnabled )
{
server->isWhitelistEnabled = isEnabled != 0;
}
-tr_bool
+bool
tr_rpcGetWhitelistEnabled( const tr_rpc_server * server )
{
return server->isWhitelistEnabled;
}
void
-tr_rpcSetPasswordEnabled( tr_rpc_server * server,
- tr_bool isEnabled )
+tr_rpcSetPasswordEnabled( tr_rpc_server * server, bool isEnabled )
{
server->isPasswordEnabled = isEnabled;
dbgmsg( "setting 'password enabled' to %d", (int)isEnabled );
}
-tr_bool
+bool
tr_rpcIsPasswordEnabled( const tr_rpc_server * server )
{
return server->isPasswordEnabled;
tr_rpcInit( tr_session * session, tr_benc * settings )
{
tr_rpc_server * s;
- tr_bool found;
- tr_bool boolVal;
+ bool found;
+ bool boolVal;
int64_t i;
const char *str;
tr_address address;
void tr_rpcClose( tr_rpc_server ** freeme );
-void tr_rpcSetEnabled( tr_rpc_server * server,
- tr_bool isEnabled );
+void tr_rpcSetEnabled( tr_rpc_server * server, bool isEnabled );
-tr_bool tr_rpcIsEnabled( const tr_rpc_server * server );
+bool tr_rpcIsEnabled( const tr_rpc_server * server );
-void tr_rpcSetPort( tr_rpc_server * server,
- tr_port port );
+void tr_rpcSetPort( tr_rpc_server * server, tr_port port );
tr_port tr_rpcGetPort( const tr_rpc_server * server );
-void tr_rpcSetUrl( tr_rpc_server * server,
- const char * url );
+void tr_rpcSetUrl( tr_rpc_server * server, const char * url );
const char * tr_rpcGetUrl( const tr_rpc_server * server );
char ** allocme_errmsg );
void tr_rpcSetWhitelistEnabled( tr_rpc_server * server,
- tr_bool isEnabled );
+ bool isEnabled );
-tr_bool tr_rpcGetWhitelistEnabled( const tr_rpc_server * server );
+bool tr_rpcGetWhitelistEnabled( const tr_rpc_server * server );
void tr_rpcSetWhitelist( tr_rpc_server * server,
const char * whitelist );
const char* tr_rpcGetUsername( const tr_rpc_server * server );
-void tr_rpcSetPasswordEnabled( tr_rpc_server * server,
- tr_bool isEnabled );
+void tr_rpcSetPasswordEnabled( tr_rpc_server * server, bool isEnabled );
-tr_bool tr_rpcIsPasswordEnabled( const tr_rpc_server * session );
+bool tr_rpcIsPasswordEnabled( const tr_rpc_server * session );
const char* tr_rpcGetBindAddress( const tr_rpc_server * server );
if( tor->isRunning )
{
- tor->isStopping = TRUE;
+ tor->isStopping = true;
notify( session, TR_RPC_TORRENT_STOPPED, tor );
}
}
int i;
int torrentCount;
tr_rpc_callback_type type;
- tr_bool deleteFlag = FALSE;
+ bool deleteFlag = false;
tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount );
assert( idle_data == NULL );
return errmsg;
}
-static tr_bool
+static bool
findAnnounceUrl( const tr_tracker_info * t, int n, const char * url, int * pos )
{
int i;
- tr_bool found = FALSE;
+ bool found = false;
for( i=0; i<n; ++i )
{
if( !strcmp( t[i].announce, url ) )
{
- found = TRUE;
+ found = true;
if( pos ) *pos = i;
break;
}
int tier;
tr_benc * val;
tr_tracker_info * trackers;
- tr_bool changed = FALSE;
+ bool changed = false;
const tr_info * inf = tr_torrentInfo( tor );
const char * errmsg = NULL;
trackers[n].tier = ++tier; /* add a new tier */
trackers[n].announce = tr_strdup( announce );
++n;
- changed = TRUE;
+ changed = true;
}
}
int i;
tr_benc * pair[2];
tr_tracker_info * trackers;
- tr_bool changed = FALSE;
+ bool changed = false;
const tr_info * inf = tr_torrentInfo( tor );
const int n = inf->trackerCount;
const char * errmsg = NULL;
{
tr_free( trackers[pos].announce );
trackers[pos].announce = tr_strdup( newval );
- changed = TRUE;
+ changed = true;
}
i += 2;
int * tids;
tr_benc * val;
tr_tracker_info * trackers;
- tr_bool changed = FALSE;
+ bool changed = false;
const tr_info * inf = tr_torrentInfo( tor );
const char * errmsg = NULL;
continue;
tr_removeElementFromArray( trackers, tids[t], sizeof( tr_tracker_info ), n-- );
dup = tids[t];
- changed = TRUE;
+ changed = true;
}
if( !changed )
double d;
tr_benc * files;
tr_benc * trackers;
- tr_bool boolVal;
+ bool boolVal;
tr_torrent * tor = torrents[i];
if( tr_bencDictFindInt( args_in, "bandwidthPriority", &tmp ) )
if( tr_isPriority( tmp ) )
tr_torrentSetPriority( tor, tmp );
if( !errmsg && tr_bencDictFindList( args_in, "files-unwanted", &files ) )
- errmsg = setFileDLs( tor, FALSE, files );
+ errmsg = setFileDLs( tor, false, files );
if( !errmsg && tr_bencDictFindList( args_in, "files-wanted", &files ) )
- errmsg = setFileDLs( tor, TRUE, files );
+ errmsg = setFileDLs( tor, true, files );
if( tr_bencDictFindInt( args_in, "peer-limit", &tmp ) )
tr_torrentSetPeerLimit( tor, tmp );
if( !errmsg && tr_bencDictFindList( args_in, "priority-high", &files ) )
}
else
{
- tr_bool move = FALSE;
+ bool move = false;
int i, torrentCount;
tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount );
static void
portTested( tr_session * session UNUSED,
- tr_bool did_connect UNUSED,
- tr_bool did_timeout UNUSED,
+ bool did_connect UNUSED,
+ bool did_timeout UNUSED,
long response_code,
const void * response,
size_t response_byte_count,
}
else /* success */
{
- const tr_bool isOpen = response_byte_count && *(char*)response == '1';
+ const bool isOpen = response_byte_count && *(char*)response == '1';
tr_bencDictAddBool( data->args_out, "port-is-open", isOpen );
tr_snprintf( result, sizeof( result ), "success" );
}
static void
gotNewBlocklist( tr_session * session,
- tr_bool did_connect UNUSED,
- tr_bool did_timeout UNUSED,
+ bool did_connect UNUSED,
+ bool did_timeout UNUSED,
long response_code,
const void * response,
size_t response_byte_count,
static void
gotMetadataFromURL( tr_session * session UNUSED,
- tr_bool did_connect UNUSED,
- tr_bool did_timeout UNUSED,
+ bool did_connect UNUSED,
+ bool did_timeout UNUSED,
long response_code,
const void * response,
size_t response_byte_count,
tr_free( data );
}
-static tr_bool
+static bool
isCurlURL( const char * filename )
{
if( filename == NULL )
- return FALSE;
+ return false;
return !strncmp( filename, "ftp://", 6 ) ||
!strncmp( filename, "http://", 7 ) ||
else
{
int64_t i;
- tr_bool boolVal;
+ bool boolVal;
tr_benc * l;
const char * str;
const char * cookies = NULL;
if( tr_bencDictFindList( args_in, "files-unwanted", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
- tr_ctorSetFilesWanted( ctor, files, fileCount, FALSE );
+ tr_ctorSetFilesWanted( ctor, files, fileCount, false );
tr_free( files );
}
if( tr_bencDictFindList( args_in, "files-wanted", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
- tr_ctorSetFilesWanted( ctor, files, fileCount, TRUE );
+ tr_ctorSetFilesWanted( ctor, files, fileCount, true );
tr_free( files );
}
{
int64_t i;
double d;
- tr_bool boolVal;
+ bool boolVal;
const char * str;
assert( idle_data == NULL );
static struct method
{
const char * name;
- tr_bool immediate;
+ bool immediate;
handler func;
}
methods[] =
{
- { "port-test", FALSE, portTest },
- { "blocklist-update", FALSE, blocklistUpdate },
- { "session-close", TRUE, sessionClose },
- { "session-get", TRUE, sessionGet },
- { "session-set", TRUE, sessionSet },
- { "session-stats", TRUE, sessionStats },
- { "torrent-add", FALSE, torrentAdd },
- { "torrent-get", TRUE, torrentGet },
- { "torrent-remove", TRUE, torrentRemove },
- { "torrent-set", TRUE, torrentSet },
- { "torrent-set-location", TRUE, torrentSetLocation },
- { "torrent-start", TRUE, torrentStart },
- { "torrent-stop", TRUE, torrentStop },
- { "torrent-verify", TRUE, torrentVerify },
- { "torrent-reannounce", TRUE, torrentReannounce }
+ { "port-test", false, portTest },
+ { "blocklist-update", false, blocklistUpdate },
+ { "session-close", true, sessionClose },
+ { "session-get", true, sessionGet },
+ { "session-set", true, sessionSet },
+ { "session-stats", true, sessionStats },
+ { "torrent-add", false, torrentAdd },
+ { "torrent-get", true, torrentGet },
+ { "torrent-remove", true, torrentRemove },
+ { "torrent-set", true, torrentSet },
+ { "torrent-set-location", true, torrentSetLocation },
+ { "torrent-start", true, torrentStart },
+ { "torrent-stop", true, torrentStop },
+ { "torrent-verify", true, torrentVerify },
+ { "torrent-reannounce", true, torrentReannounce }
};
static void
{
#ifdef TR_LIGHTWEIGHT
DEFAULT_CACHE_SIZE_MB = 2,
- DEFAULT_PREFETCH_ENABLED = FALSE,
+ DEFAULT_PREFETCH_ENABLED = false,
#else
DEFAULT_CACHE_SIZE_MB = 4,
- DEFAULT_PREFETCH_ENABLED = TRUE,
+ DEFAULT_PREFETCH_ENABLED = true,
#endif
SAVE_INTERVAL_SECS = 360
};
/* bind an ipv4 port to listen for incoming peers... */
b = session->public_ipv4;
- b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, FALSE );
+ b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, false );
if( b->socket >= 0 ) {
b->ev = event_new( session->event_base, b->socket, EV_READ | EV_PERSIST, accept_incoming_peer, session );
event_add( b->ev, NULL );
/* and do the exact same thing for ipv6, if it's supported... */
if( tr_net_hasIPv6( session->private_peer_port ) ) {
b = session->public_ipv6;
- b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, FALSE );
+ b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, false );
if( b->socket >= 0 ) {
b->ev = event_new( session->event_base, b->socket, EV_READ | EV_PERSIST, accept_incoming_peer, session );
event_add( b->ev, NULL );
}
const tr_address*
-tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type, tr_bool * is_default_value )
+tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type, bool * is_default_value )
{
const char * default_value;
const struct tr_bindinfo * bindinfo;
assert( tr_bencIsDict( d ) );
tr_bencDictReserve( d, 60 );
- tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false );
tr_bencDictAddStr ( d, TR_PREFS_KEY_BLOCKLIST_URL, "http://www.example.com/blocklist" );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, DEFAULT_CACHE_SIZE_MB );
- tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, TRUE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, TRUE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, true );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, true );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, false );
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, 100 );
- tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, false );
tr_bencDictAddInt ( d, TR_PREFS_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION );
tr_bencDictAddInt ( d, TR_PREFS_KEY_IDLE_LIMIT, 30 );
- tr_bencDictAddBool( d, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, false );
tr_bencDictAddStr ( d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_getDefaultDownloadDir( ) );
- tr_bencDictAddBool( d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MSGLEVEL, TR_MSG_INF );
tr_bencDictAddInt ( d, TR_PREFS_KEY_OPEN_FILE_LIMIT, atoi( TR_DEFAULT_OPEN_FILE_LIMIT_STR ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi( TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi( TR_DEFAULT_PEER_LIMIT_TORRENT_STR ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT, atoi( TR_DEFAULT_PEER_PORT_STR ) );
- tr_bencDictAddBool( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, false );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, 49152 );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, 65535 );
tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_SOCKET_TOS, TR_DEFAULT_PEER_SOCKET_TOS_STR );
- tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, TRUE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, true );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, true );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION, TR_PREALLOCATE_SPARSE );
tr_bencDictAddBool( d, TR_PREFS_KEY_PREFETCH_ENABLED, DEFAULT_PREFETCH_ENABLED );
tr_bencDictAddReal( d, TR_PREFS_KEY_RATIO, 2.0 );
- tr_bencDictAddBool( d, TR_PREFS_KEY_RATIO_ENABLED, FALSE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES, TRUE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_RATIO_ENABLED, false );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES, true );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, false );
tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_BIND_ADDRESS, "0.0.0.0" );
- tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_ENABLED, false );
tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_PASSWORD, "" );
tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_USERNAME, "" );
tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_WHITELIST, TR_DEFAULT_RPC_WHITELIST );
- tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, TRUE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, true );
tr_bencDictAddInt ( d, TR_PREFS_KEY_RPC_PORT, atoi( TR_DEFAULT_RPC_PORT_STR ) );
tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_URL, TR_DEFAULT_RPC_URL_STR );
tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, "" );
- tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, FALSE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, false );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, false );
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_KBps, 50 ); /* half the regular */
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, 50 ); /* half the regular */
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, 540 ); /* 9am */
- tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, false );
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END, 1020 ); /* 5pm */
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, TR_SCHED_ALL );
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_KBps, 100 );
- tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, false );
tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK, 022 );
tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, 14 );
tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4, TR_DEFAULT_BIND_ADDRESS_IPV4 );
tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6, TR_DEFAULT_BIND_ADDRESS_IPV6 );
- tr_bencDictAddBool( d, TR_PREFS_KEY_START, TRUE );
- tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, FALSE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_START, true );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, false );
}
void
tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, tr_sessionGetDeleteSource( s ) );
}
-tr_bool
+bool
tr_sessionLoadSettings( tr_benc * d, const char * configDir, const char * appName )
{
int err = 0;
tr_benc fileSettings;
tr_benc sessionDefaults;
tr_benc tmp;
- tr_bool success = FALSE;
+ bool success = false;
assert( tr_bencIsDict( d ) );
{
tr_session * session;
const char * configDir;
- tr_bool done;
- tr_bool messageQueuingEnabled;
+ bool done;
+ bool messageQueuingEnabled;
tr_benc * clientSettings;
};
tr_session *
tr_sessionInit( const char * tag,
const char * configDir,
- tr_bool messageQueuingEnabled,
+ bool messageQueuingEnabled,
tr_benc * clientSettings )
{
int64_t i;
assert( session->events != NULL );
/* run the rest in the libtransmission thread */
- data.done = FALSE;
+ data.done = false;
data.session = session;
data.configDir = configDir;
data.messageQueuingEnabled = messageQueuingEnabled;
/* cleanup */
tr_bencFree( &settings );
- data->done = TRUE;
+ data->done = true;
}
static void turtleBootstrap( tr_session *, struct tr_turtle_info * );
{
int64_t i;
double d;
- tr_bool boolVal;
+ bool boolVal;
const char * str;
struct tr_bindinfo b;
struct init_data * data = vdata;
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, &str ) )
tr_sessionSetTorrentDoneScript( session, str );
- data->done = TRUE;
+ data->done = true;
}
void
tr_sessionSet( tr_session * session, struct tr_benc * settings )
{
struct init_data data;
- data.done = FALSE;
+ data.done = false;
data.session = session;
data.clientSettings = settings;
***/
void
-tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, tr_bool b )
+tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, bool b )
{
assert( tr_isSession( session ) );
assert( tr_isBool( b ) );
session->isIncompleteFileNamingEnabled = b;
}
-tr_bool
+bool
tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_sessionSetIncompleteDirEnabled( tr_session * session, tr_bool b )
+tr_sessionSetIncompleteDirEnabled( tr_session * session, bool b )
{
assert( tr_isSession( session ) );
assert( tr_isBool( b ) );
session->isIncompleteDirEnabled = b;
}
-tr_bool
+bool
tr_sessionIsIncompleteDirEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
assert( !session->bufferInUse );
assert( tr_amInEventThread( session ) );
- session->bufferInUse = TRUE;
+ session->bufferInUse = true;
return session->buffer;
}
assert( session->bufferInUse );
assert( tr_amInEventThread( session ) );
- session->bufferInUse = FALSE;
+ session->bufferInUse = false;
}
void
tr_lockUnlock( session->lock );
}
-tr_bool
+bool
tr_sessionIsLocked( const tr_session * session )
{
return tr_isSession( session ) && tr_lockHave( session->lock );
void
tr_sessionSetPeerPortRandomOnStart( tr_session * session,
- tr_bool random )
+ bool random )
{
assert( tr_isSession( session ) );
session->isPortRandom = random;
}
-tr_bool
+bool
tr_sessionGetPeerPortRandomOnStart( tr_session * session )
{
assert( tr_isSession( session ) );
***/
void
-tr_sessionSetRatioLimited( tr_session * session, tr_bool isLimited )
+tr_sessionSetRatioLimited( tr_session * session, bool isLimited )
{
assert( tr_isSession( session ) );
session->desiredRatio = desiredRatio;
}
-tr_bool
+bool
tr_sessionIsRatioLimited( const tr_session * session )
{
assert( tr_isSession( session ) );
***/
void
-tr_sessionSetIdleLimited( tr_session * session, tr_bool isLimited )
+tr_sessionSetIdleLimited( tr_session * session, bool isLimited )
{
assert( tr_isSession( session ) );
session->idleLimitMinutes = idleMinutes;
}
-tr_bool
+bool
tr_sessionIsIdleLimited( const tr_session * session )
{
assert( tr_isSession( session ) );
****
***/
-tr_bool
+bool
tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme_Bps )
{
- int isLimited = TRUE;
+ int isLimited = true;
if( !tr_isSession( session ) )
- return FALSE;
+ return false;
if( tr_sessionUsesAltSpeed( session ) )
*setme_Bps = tr_sessionGetAltSpeed_Bps( session, dir );
else if( tr_sessionIsSpeedLimited( session, dir ) )
*setme_Bps = tr_sessionGetSpeedLimit_Bps( session, dir );
else
- isLimited = FALSE;
+ isLimited = false;
return isLimited;
}
-tr_bool
+bool
tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
tr_direction dir,
double * setme_KBps )
{
int Bps = 0;
- const tr_bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps );
+ const bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps );
*setme_KBps = toSpeedKBps( Bps );
return is_active;
}
updateBandwidth( tr_session * session, tr_direction dir )
{
int limit_Bps = 0;
- const tr_bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps );
- const tr_bool zeroCase = isLimited && !limit_Bps;
+ const bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps );
+ const bool zeroCase = isLimited && !limit_Bps;
tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase );
static void
useAltSpeed( tr_session * s, struct tr_turtle_info * t,
- tr_bool enabled, tr_bool byUser )
+ bool enabled, bool byUser )
{
assert( tr_isSession( s ) );
assert( t != NULL );
*/
static void
testTurtleTime( const struct tr_turtle_info * t,
- tr_bool * enabled,
- tr_bool * changed )
+ bool * enabled,
+ bool * changed )
{
- tr_bool e;
+ bool e;
struct tm tm;
size_t minute_of_the_week;
const time_t now = tr_time( );
static void
turtleCheckClock( tr_session * s, struct tr_turtle_info * t )
{
- tr_bool enabled;
- tr_bool changed;
+ bool enabled;
+ bool changed;
assert( t->isClockEnabled );
if( changed )
{
tr_inf( "Time to turn %s turtle mode!", (enabled?"on":"off") );
- useAltSpeed( s, t, enabled, FALSE );
+ useAltSpeed( s, t, enabled, false );
}
}
static void
turtleBootstrap( tr_session * session, struct tr_turtle_info * turtle )
{
- turtle->changedByUser = FALSE;
+ turtle->changedByUser = false;
tr_bitfieldConstruct( &turtle->minutes, MINUTES_PER_WEEK );
}
void
-tr_sessionLimitSpeed( tr_session * s, tr_direction d, tr_bool b )
+tr_sessionLimitSpeed( tr_session * s, tr_direction d, bool b )
{
assert( tr_isSession( s ) );
assert( tr_isDirection( d ) );
updateBandwidth( s, d );
}
-tr_bool
+bool
tr_sessionIsSpeedLimited( const tr_session * s, tr_direction d )
{
assert( tr_isSession( s ) );
if( t->isClockEnabled )
{
- tr_bool enabled, changed;
+ bool enabled, changed;
testTurtleTime( t, &enabled, &changed );
- useAltSpeed( s, t, enabled, TRUE );
+ useAltSpeed( s, t, enabled, true );
}
}
void
-tr_sessionUseAltSpeedTime( tr_session * s, tr_bool b )
+tr_sessionUseAltSpeedTime( tr_session * s, bool b )
{
struct tr_turtle_info * t = &s->turtle;
}
}
-tr_bool
+bool
tr_sessionUsesAltSpeedTime( const tr_session * s )
{
assert( tr_isSession( s ) );
}
void
-tr_sessionUseAltSpeed( tr_session * session, tr_bool enabled )
+tr_sessionUseAltSpeed( tr_session * session, bool enabled )
{
- useAltSpeed( session, &session->turtle, enabled, TRUE );
+ useAltSpeed( session, &session->turtle, enabled, true );
}
-tr_bool
+bool
tr_sessionUsesAltSpeed( const tr_session * s )
{
assert( tr_isSession( s ) );
***/
void
-tr_sessionSetPaused( tr_session * session, tr_bool isPaused )
+tr_sessionSetPaused( tr_session * session, bool isPaused )
{
assert( tr_isSession( session ) );
session->pauseAddedTorrent = isPaused;
}
-tr_bool
+bool
tr_sessionGetPaused( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_sessionSetDeleteSource( tr_session * session, tr_bool deleteSource )
+tr_sessionSetDeleteSource( tr_session * session, bool deleteSource )
{
assert( tr_isSession( session ) );
session->deleteSourceTorrent = deleteSource;
}
-tr_bool
+bool
tr_sessionGetDeleteSource( const tr_session * session )
{
assert( tr_isSession( session ) );
tr_fdClose( session );
- session->isClosed = TRUE;
+ session->isClosed = true;
}
static int
tr_eventClose( session );
while( session->events != NULL )
{
- static tr_bool forced = FALSE;
+ static bool forced = false;
dbgmsg( "waiting for libtransmission thread to finish... now %zu deadline %zu", (size_t)time(NULL), (size_t)deadline );
tr_wait_msec( 500 );
if( deadlineReached( deadline ) && !forced )
{
dbgmsg( "calling event_loopbreak()" );
- forced = TRUE;
+ forced = true;
event_base_loopbreak( session->event_base );
}
if( deadlineReached( deadline+3 ) )
assert( tr_isSession( session ) );
- tr_ctorSetSave( ctor, FALSE ); /* since we already have them */
+ tr_ctorSetSave( ctor, false ); /* since we already have them */
if( !stat( dirname, &sb )
&& S_ISDIR( sb.st_mode )
***/
void
-tr_sessionSetPexEnabled( tr_session * session,
- tr_bool enabled )
+tr_sessionSetPexEnabled( tr_session * session, bool enabled )
{
assert( tr_isSession( session ) );
session->isPexEnabled = enabled != 0;
}
-tr_bool
+bool
tr_sessionIsPexEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
return session->isPexEnabled;
}
-tr_bool
+bool
tr_sessionAllowsDHT( const tr_session * session UNUSED )
{
return tr_sessionIsDHTEnabled( session );
}
-tr_bool
+bool
tr_sessionIsDHTEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_sessionSetDHTEnabled( tr_session * session, tr_bool enabled )
+tr_sessionSetDHTEnabled( tr_session * session, bool enabled )
{
assert( tr_isSession( session ) );
assert( tr_isBool( enabled ) );
****
***/
-tr_bool
+bool
tr_sessionIsUTPEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
#ifdef WITH_UTP
return session->isUTPEnabled;
#else
- return FALSE;
+ return false;
#endif
}
}
void
-tr_sessionSetUTPEnabled( tr_session * session, tr_bool enabled )
+tr_sessionSetUTPEnabled( tr_session * session, bool enabled )
{
assert( tr_isSession( session ) );
assert( tr_isBool( enabled ) );
}
void
-tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled )
+tr_sessionSetLPDEnabled( tr_session * session, bool enabled )
{
assert( tr_isSession( session ) );
assert( tr_isBool( enabled ) );
tr_runInEventThread( session, toggleLPDImpl, session );
}
-tr_bool
+bool
tr_sessionIsLPDEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
return session->isLPDEnabled;
}
-tr_bool
+bool
tr_sessionAllowsLPD( const tr_session * session )
{
return tr_sessionIsLPDEnabled( session );
struct port_forwarding_data
{
- tr_bool enabled;
+ bool enabled;
struct tr_shared * shared;
};
}
void
-tr_sessionSetPortForwardingEnabled( tr_session * session, tr_bool enabled )
+tr_sessionSetPortForwardingEnabled( tr_session * session, bool enabled )
{
struct port_forwarding_data * d;
d = tr_new0( struct port_forwarding_data, 1 );
tr_runInEventThread( session, setPortForwardingEnabled, d );
}
-tr_bool
+bool
tr_sessionIsPortForwardingEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
char * dirname;
DIR * odir = NULL;
tr_list * list = NULL;
- const tr_bool isEnabled = session->isBlocklistEnabled;
+ const bool isEnabled = session->isBlocklistEnabled;
/* walk through the directory and find blocklists */
dirname = tr_buildPath( session->configDir, "blocklists", NULL );
return n;
}
-tr_bool
+bool
tr_blocklistIsEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_blocklistSetEnabled( tr_session * session,
- tr_bool isEnabled )
+tr_blocklistSetEnabled( tr_session * session, bool isEnabled )
{
tr_list * l;
_tr_blocklistSetEnabled( l->data, isEnabled );
}
-tr_bool
+bool
tr_blocklistExists( const tr_session * session )
{
assert( tr_isSession( session ) );
return ruleCount;
}
-tr_bool
+bool
tr_sessionIsAddressBlocked( const tr_session * session,
const tr_address * addr )
{
for( l = session->blocklists; l; l = l->next )
if( _tr_blocklistHasAddress( l->data, addr ) )
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
void
lookup = tr_new0( tr_benc, 1 );
tr_bencInitDict( lookup, 0 );
ctor = tr_ctorNew( session );
- tr_ctorSetSave( ctor, FALSE ); /* since we already have them */
+ tr_ctorSetSave( ctor, false ); /* since we already have them */
if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && ( ( odir = opendir( dirname ) ) ) )
{
struct dirent *d;
***/
void
-tr_sessionSetRPCEnabled( tr_session * session,
- tr_bool isEnabled )
+tr_sessionSetRPCEnabled( tr_session * session, bool isEnabled )
{
assert( tr_isSession( session ) );
tr_rpcSetEnabled( session->rpcServer, isEnabled );
}
-tr_bool
+bool
tr_sessionIsRPCEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_sessionSetRPCWhitelistEnabled( tr_session * session,
- tr_bool isEnabled )
+tr_sessionSetRPCWhitelistEnabled( tr_session * session, bool isEnabled )
{
assert( tr_isSession( session ) );
tr_rpcSetWhitelistEnabled( session->rpcServer, isEnabled );
}
-tr_bool
+bool
tr_sessionGetRPCWhitelistEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_sessionSetRPCPasswordEnabled( tr_session * session,
- tr_bool isEnabled )
+tr_sessionSetRPCPasswordEnabled( tr_session * session, bool isEnabled )
{
assert( tr_isSession( session ) );
tr_rpcSetPasswordEnabled( session->rpcServer, isEnabled );
}
-tr_bool
+bool
tr_sessionIsRPCPasswordEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
*****
****/
-tr_bool
+bool
tr_sessionIsTorrentDoneScriptEnabled( const tr_session * session )
{
assert( tr_isSession( session ) );
}
void
-tr_sessionSetTorrentDoneScriptEnabled( tr_session * session, tr_bool isEnabled )
+tr_sessionSetTorrentDoneScriptEnabled( tr_session * session, bool isEnabled )
{
assert( tr_isSession( session ) );
assert( tr_isBool( isEnabled ) );
int speedLimit_Bps[2];
/* is turtle mode on right now? */
- tr_bool isEnabled;
+ bool isEnabled;
/* does turtle mode turn itself on and off at given times? */
- tr_bool isClockEnabled;
+ bool isClockEnabled;
/* when clock mode is on, minutes after midnight to turn on turtle mode */
int beginMinute;
/* the callback's changedByUser argument.
* indicates whether the change came from the user or from the clock. */
- tr_bool changedByUser;
+ bool changedByUser;
/* bitfield of all the minutes in a week.
* Each bit's value indicates whether the scheduler wants turtle
/** @brief handle to an active libtransmission session */
struct tr_session
{
- tr_bool isPortRandom;
- tr_bool isPexEnabled;
- tr_bool isDHTEnabled;
- tr_bool isUTPEnabled;
- tr_bool isLPDEnabled;
- tr_bool isBlocklistEnabled;
- tr_bool isPrefetchEnabled;
- tr_bool isTorrentDoneScriptEnabled;
- tr_bool isClosed;
- tr_bool isIncompleteFileNamingEnabled;
- tr_bool isRatioLimited;
- tr_bool isIdleLimited;
- tr_bool isIncompleteDirEnabled;
- tr_bool pauseAddedTorrent;
- tr_bool deleteSourceTorrent;
+ bool isPortRandom;
+ bool isPexEnabled;
+ bool isDHTEnabled;
+ bool isUTPEnabled;
+ bool isLPDEnabled;
+ bool isBlocklistEnabled;
+ bool isPrefetchEnabled;
+ bool isTorrentDoneScriptEnabled;
+ bool isClosed;
+ bool isIncompleteFileNamingEnabled;
+ bool isRatioLimited;
+ bool isIdleLimited;
+ bool isIncompleteDirEnabled;
+ bool pauseAddedTorrent;
+ bool deleteSourceTorrent;
tr_benc removedTorrents;
int umask;
int speedLimit_Bps[2];
- tr_bool speedLimitEnabled[2];
+ bool speedLimitEnabled[2];
struct tr_turtle_info turtle;
* @see SESSION_BUFFER_SIZE */
void * buffer;
- tr_bool bufferInUse;
+ bool bufferInUse;
tr_web_config_func * curl_easy_config_func;
return session->peer_id;
}
-tr_bool tr_sessionAllowsDHT( const tr_session * session );
+bool tr_sessionAllowsDHT( const tr_session * session );
-tr_bool tr_sessionAllowsLPD( const tr_session * session );
+bool tr_sessionAllowsLPD( const tr_session * session );
const char * tr_sessionFindTorrentFile( const tr_session * session,
const char * hashString );
const char * hashString,
const char * filename );
-tr_bool tr_sessionIsAddressBlocked( const tr_session * session,
+bool tr_sessionIsAddressBlocked( const tr_session * session,
const struct tr_address * addr );
void tr_sessionLock( tr_session * );
void tr_sessionUnlock( tr_session * );
-tr_bool tr_sessionIsLocked( const tr_session * );
+bool tr_sessionIsLocked( const tr_session * );
const struct tr_address* tr_sessionGetPublicAddress( const tr_session * session,
int tr_af_type,
- tr_bool * is_default_value );
+ bool * is_default_value );
struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
void tr_sessionReleaseBuffer( tr_session * session );
-static inline tr_bool tr_isSession( const tr_session * session )
+static inline bool tr_isSession( const tr_session * session )
{
return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );
}
-static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m )
+static inline bool tr_isPreallocationMode( tr_preallocation_mode m )
{
return ( m == TR_PREALLOCATE_NONE )
|| ( m == TR_PREALLOCATE_SPARSE )
|| ( m == TR_PREALLOCATE_FULL );
}
-static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m )
+static inline bool tr_isEncryptionMode( tr_encryption_mode m )
{
return ( m == TR_CLEAR_PREFERRED )
|| ( m == TR_ENCRYPTION_PREFERRED )
|| ( m == TR_ENCRYPTION_REQUIRED );
}
-static inline tr_bool tr_isPriority( tr_priority_t p )
+static inline bool tr_isPriority( tr_priority_t p )
{
return ( p == TR_PRI_LOW )
|| ( p == TR_PRI_NORMAL )
void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
void tr_sessionSetAltSpeed_Bps ( tr_session *, tr_direction, int Bps );
-tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
- tr_direction dir,
- int * setme );
+bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
+ tr_direction dir,
+ int * setme );
#endif
tr_session_stats single;
tr_session_stats old;
time_t startTime;
- tr_bool isDirty;
+ bool isDirty;
};
static char*
loadCumulativeStats( const tr_session * session,
tr_session_stats * setme )
{
- int loaded = FALSE;
- char * filename;
tr_benc top;
+ char * filename;
+ bool loaded = false;
filename = getFilename( session );
loaded = !tr_bencLoadFile( &top, TR_FMT_JSON, filename );
tr_session_stats cumulative = STATS_INIT;
tr_sessionGetCumulativeStats( session, &cumulative );
saveCumulativeStats( session, &cumulative );
- h->isDirty = FALSE;
+ h->isDirty = false;
}
}
if( ( s = getStats( session ) ) )
{
s->single.uploadedBytes += bytes;
- s->isDirty = TRUE;
+ s->isDirty = true;
}
}
if( ( s = getStats( session ) ) )
{
s->single.downloadedBytes += bytes;
- s->isDirty = TRUE;
+ s->isDirty = true;
}
}
struct optional_args
{
- tr_bool isSet_paused;
- tr_bool isSet_connected;
- tr_bool isSet_downloadDir;
+ bool isSet_paused;
+ bool isSet_connected;
+ bool isSet_downloadDir;
- tr_bool isPaused;
+ bool isPaused;
uint16_t peerLimit;
char * downloadDir;
};
struct tr_ctor
{
const tr_session * session;
- tr_bool saveInOurTorrentsDir;
- tr_bool doDelete;
+ bool saveInOurTorrentsDir;
+ bool doDelete;
tr_priority_t bandwidthPriority;
- tr_bool isSet_metainfo;
- tr_bool isSet_delete;
+ bool isSet_metainfo;
+ bool isSet_delete;
tr_benc metainfo;
char * sourceFile;
tr_ctorSetFilesWanted( tr_ctor * ctor,
const tr_file_index_t * files,
tr_file_index_t fileCount,
- tr_bool wanted )
+ bool wanted )
{
tr_file_index_t ** myfiles = wanted ? &ctor->want : &ctor->notWant;
tr_file_index_t * mycount = wanted ? &ctor->wantSize : &ctor->notWantSize;
tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor )
{
if( ctor->notWantSize )
- tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, FALSE );
+ tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, false );
if( ctor->wantSize )
- tr_torrentInitFileDLs( tor, ctor->want, ctor->wantSize, TRUE );
+ tr_torrentInitFileDLs( tor, ctor->want, ctor->wantSize, true );
}
/***
***/
void
-tr_ctorSetDeleteSource( tr_ctor * ctor,
- tr_bool deleteSource )
+tr_ctorSetDeleteSource( tr_ctor * ctor, bool deleteSource )
{
ctor->doDelete = deleteSource != 0;
ctor->isSet_delete = 1;
}
int
-tr_ctorGetDeleteSource( const tr_ctor * ctor,
- uint8_t * setme )
+tr_ctorGetDeleteSource( const tr_ctor * ctor, bool * setme )
{
int err = 0;
***/
void
-tr_ctorSetSave( tr_ctor * ctor,
- tr_bool saveInOurTorrentsDir )
+tr_ctorSetSave( tr_ctor * ctor, bool saveInOurTorrentsDir )
{
ctor->saveInOurTorrentsDir = saveInOurTorrentsDir != 0;
}
void
tr_ctorSetPaused( tr_ctor * ctor,
tr_ctorMode mode,
- tr_bool isPaused )
+ bool isPaused )
{
struct optional_args * args = &ctor->optionalArgs[mode];
}
int
-tr_ctorGetPaused( const tr_ctor * ctor,
- tr_ctorMode mode,
- uint8_t * setmeIsPaused )
+tr_ctorGetPaused( const tr_ctor * ctor, tr_ctorMode mode, bool * setmeIsPaused )
{
int err = 0;
const struct optional_args * args = &ctor->optionalArgs[mode];
****
***/
-static tr_bool
+static bool
isPriority( int i )
{
return (i==TR_PRI_LOW) || (i==TR_PRI_NORMAL) || (i==TR_PRI_HIGH);
tr_ctorSetPeerLimit( ctor, TR_FALLBACK, session->peerLimitPerTorrent );
tr_ctorSetDownloadDir( ctor, TR_FALLBACK, session->downloadDir );
}
- tr_ctorSetSave( ctor, TRUE );
+ tr_ctorSetSave( ctor, true );
return ctor;
}
if( !tor->infoDictOffsetIsCached )
{
tor->infoDictOffset = findInfoDictOffset( tor );
- tor->infoDictOffsetIsCached = TRUE;
+ tor->infoDictOffsetIsCached = true;
}
}
/* are we done? */
if( m->piecesNeededCount == 0 )
{
- tr_bool success = FALSE;
- tr_bool checksumPassed = FALSE;
- tr_bool metainfoParsed = FALSE;
+ bool success = false;
+ bool checksumPassed = false;
+ bool metainfoParsed = false;
uint8_t sha1[SHA_DIGEST_LENGTH];
/* we've got a complete set of metainfo... see if it passes the checksum test */
if( !tr_bencLoadFile( &newMetainfo, TR_FMT_BENC, path ) )
{
- tr_bool hasInfo;
+ bool hasInfo;
tr_info info;
int infoDictLength;
if( success && !tr_getBlockSize( info.pieceSize ) )
{
tr_torrentSetLocalError( tor, "%s", _( "Magnet torrent's metadata is not usable" ) );
- success = FALSE;
+ success = false;
}
if( success )
}
}
-tr_bool
+bool
tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme_piece )
{
- tr_bool have_request = FALSE;
+ bool have_request = false;
struct tr_incomplete_metadata * m;
assert( tr_isTorrent( tor ) );
dbgmsg( tor, "next piece to request: %d", piece );
*setme_piece = piece;
- have_request = TRUE;
+ have_request = true;
}
return have_request;
if( name && *name )
{
evbuffer_add_printf( s, "%s", "&dn=" );
- tr_http_escape( s, tr_torrentName( tor ), -1, TRUE );
+ tr_http_escape( s, tr_torrentName( tor ), -1, true );
}
for( i=0; i<tor->info.trackerCount; ++i )
{
evbuffer_add_printf( s, "%s", "&tr=" );
- tr_http_escape( s, tor->info.trackers[i].announce, -1, TRUE );
+ tr_http_escape( s, tor->info.trackers[i].announce, -1, true );
}
return evbuffer_free_to_str( s );
void tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, int len );
-tr_bool tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme );
+bool tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme );
void tr_torrentSetMetadataSizeHint( tr_torrent * tor, int metadata_size );
return NULL;
}
-tr_bool
+bool
tr_torrentIsPieceTransferAllowed( const tr_torrent * tor,
tr_direction direction )
{
int limit;
- tr_bool allowed = TRUE;
+ bool allowed = true;
if( tr_torrentUsesSpeedLimit( tor, direction ) )
if( tr_torrentGetSpeedLimit_Bps( tor, direction ) <= 0 )
- allowed = FALSE;
+ allowed = false;
if( tr_torrentUsesSessionLimits( tor ) )
if( tr_sessionGetActiveSpeedLimit_Bps( tor->session, direction, &limit ) )
if( limit <= 0 )
- allowed = FALSE;
+ allowed = false;
return allowed;
}
}
void
-tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use )
+tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, bool do_use )
{
assert( tr_isTorrent( tor ) );
assert( tr_isDirection( dir ) );
tr_torrentSetDirty( tor );
}
-tr_bool
+bool
tr_torrentUsesSpeedLimit( const tr_torrent * tor, tr_direction dir )
{
assert( tr_isTorrent( tor ) );
}
void
-tr_torrentUseSessionLimits( tr_torrent * tor, tr_bool doUse )
+tr_torrentUseSessionLimits( tr_torrent * tor, bool doUse )
{
- tr_bool changed;
+ bool changed;
assert( tr_isTorrent( tor ) );
tr_torrentSetDirty( tor );
}
-tr_bool
+bool
tr_torrentUsesSessionLimits( const tr_torrent * tor )
{
assert( tr_isTorrent( tor ) );
return tor->desiredRatio;
}
-tr_bool
+bool
tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio )
{
- tr_bool isLimited;
+ bool isLimited;
switch( tr_torrentGetRatioMode( tor ) )
{
case TR_RATIOLIMIT_SINGLE:
- isLimited = TRUE;
+ isLimited = true;
if( ratio )
*ratio = tr_torrentGetRatioLimit( tor );
break;
break;
default: /* TR_RATIOLIMIT_UNLIMITED */
- isLimited = FALSE;
+ isLimited = false;
break;
}
/* returns true if the seed ratio applies --
* it applies if the torrent's a seed AND it has a seed ratio set */
-static tr_bool
+static bool
tr_torrentGetSeedRatioBytes( tr_torrent * tor,
uint64_t * setmeLeft,
uint64_t * setmeGoal )
{
double seedRatio;
- tr_bool seedRatioApplies = FALSE;
+ bool seedRatioApplies = false;
if( tr_torrentGetSeedRatio( tor, &seedRatio ) )
{
return seedRatioApplies;
}
-static tr_bool
+static bool
tr_torrentIsSeedRatioDone( tr_torrent * tor )
{
uint64_t bytesLeft;
return tor->idleLimitMinutes;
}
-tr_bool
+bool
tr_torrentGetSeedIdle( const tr_torrent * tor, uint16_t * idleMinutes )
{
- tr_bool isLimited;
+ bool isLimited;
switch( tr_torrentGetIdleMode( tor ) )
{
case TR_IDLELIMIT_SINGLE:
- isLimited = TRUE;
+ isLimited = true;
if( idleMinutes )
*idleMinutes = tr_torrentGetIdleLimit( tor );
break;
break;
default: /* TR_IDLELIMIT_UNLIMITED */
- isLimited = FALSE;
+ isLimited = false;
break;
}
return isLimited;
}
-static tr_bool
+static bool
tr_torrentIsSeedIdleLimitDone( tr_torrent * tor )
{
uint16_t idleMinutes;
{
tr_torinf( tor, "Seed ratio reached; pausing torrent" );
- tor->isStopping = TRUE;
+ tor->isStopping = true;
/* maybe notify the client */
if( tor->ratio_limit_hit_func != NULL )
{
tr_torinf( tor, "Seeding idle limit reached; pausing torrent" );
- tor->isStopping = TRUE;
- tor->finishedSeedingByIdle = TRUE;
+ tor->isStopping = true;
+ tor->finishedSeedingByIdle = true;
/* maybe notify the client */
if( tor->idle_limit_hit_func != NULL )
tr_torerr( tor, "%s", tor->errorString );
if( tor->isRunning )
- tor->isStopping = TRUE;
+ tor->isStopping = true;
}
static void
{
size_t i;
const int8_t seedProbability = event->seedProbability;
- const tr_bool allAreSeeds = seedProbability == 100;
+ const bool allAreSeeds = seedProbability == 100;
if( allAreSeeds )
tr_tordbg( tor, "Got %zu seeds from tracker", event->pexCount );
tr_torrentFireMetadataCompleted( tor );
}
-static tr_bool
+static bool
hasAnyLocalData( const tr_torrent * tor )
{
tr_file_index_t i;
- tr_bool has_local_data = FALSE;
+ bool has_local_data = false;
const tr_file_index_t n = tor->info.fileCount;
for( i=0; i<n && !has_local_data; ++i )
char * filename = tr_torrentFindFile( tor, i );
if( filename && !stat( filename, &sb ) )
- has_local_data = TRUE;
+ has_local_data = true;
tr_free( filename );
}
return has_local_data;
}
-static tr_bool
+static bool
setLocalErrorIfFilesDisappeared( tr_torrent * tor )
{
- const tr_bool disappeared = ( tr_cpHaveTotal( &tor->completion ) > 0 ) && !hasAnyLocalData( tor );
+ const bool disappeared = ( tr_cpHaveTotal( &tor->completion ) > 0 ) && !hasAnyLocalData( tor );
if( disappeared )
{
int doStart;
uint64_t loaded;
const char * dir;
- tr_bool isNewTorrent;
+ bool isNewTorrent;
struct stat st;
static int nextUniqueId = 1;
tr_session * session = tr_ctorGetSession( ctor );
tor->error = TR_STAT_OK;
- tor->finishedSeedingByIdle = FALSE;
+ tor->finishedSeedingByIdle = false;
tr_peerMgrAddTorrent( session->peerMgr, tor );
if( !( loaded & TR_FR_SPEEDLIMIT ) )
{
- tr_torrentUseSpeedLimit( tor, TR_UP, FALSE );
+ tr_torrentUseSpeedLimit( tor, TR_UP, false );
tr_torrentSetSpeedLimit_Bps( tor, TR_UP, tr_sessionGetSpeedLimit_Bps( tor->session, TR_UP ) );
- tr_torrentUseSpeedLimit( tor, TR_DOWN, FALSE );
+ tr_torrentUseSpeedLimit( tor, TR_DOWN, false );
tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, tr_sessionGetSpeedLimit_Bps( tor->session, TR_DOWN ) );
- tr_torrentUseSessionLimits( tor, TRUE );
+ tr_torrentUseSessionLimits( tor, true );
}
if( !( loaded & TR_FR_RATIOLIMIT ) )
static tr_parse_result
torrentParseImpl( const tr_ctor * ctor, tr_info * setmeInfo,
- tr_bool * setmeHasInfo, int * dictLength )
+ bool * setmeHasInfo, int * dictLength )
{
int doFree;
- tr_bool didParse;
- tr_bool hasInfo = FALSE;
+ bool didParse;
+ bool hasInfo = false;
tr_info tmp;
const tr_benc * metainfo;
tr_session * session = tr_ctorGetSession( ctor );
tr_torrentNew( const tr_ctor * ctor, int * setmeError )
{
int len;
- tr_bool hasInfo;
+ bool hasInfo;
tr_info tmpInfo;
tr_parse_result r;
tr_torrent * tor = NULL;
tr_runInEventThread( tor->session, tr_torrentManualUpdateImpl, tor );
}
-tr_bool
+bool
tr_torrentCanManualUpdate( const tr_torrent * tor )
{
return ( tr_isTorrent( tor ) )
uint64_t now;
uint64_t seedRatioBytesLeft;
uint64_t seedRatioBytesGoal;
- tr_bool seedRatioApplies;
+ bool seedRatioApplies;
uint16_t seedIdleMinutes;
if( !tor )
const tr_file_index_t n = tor->info.fileCount;
tr_file_stat * files = tr_new0( tr_file_stat, n );
tr_file_stat * walk = files;
- const tr_bool isSeed = tor->completeness == TR_SEED;
+ const bool isSeed = tor->completeness == TR_SEED;
assert( tr_isTorrent( tor ) );
void
tr_torrentSetHasPiece( tr_torrent * tor,
tr_piece_index_t pieceIndex,
- tr_bool has )
+ bool has )
{
assert( tr_isTorrent( tor ) );
assert( pieceIndex < tor->info.pieceCount );
tr_torrentRecheckCompleteness( tor );
now = tr_time( );
- tor->isRunning = TRUE;
+ tor->isRunning = true;
tor->completeness = tr_cpGetStatus( &tor->completion );
tor->startDate = tor->anyDate = now;
tr_torrentClearError( tor );
- tor->finishedSeedingByIdle = FALSE;
+ tor->finishedSeedingByIdle = false;
tr_torrentResetTransferStats( tor );
tr_announcerTorrentStarted( tor );
/* verifying right now... wait until that's done so
* we'll know what completeness to use/announce */
if( tor->verifyState != TR_VERIFY_NONE ) {
- tor->startAfterVerify = TRUE;
+ tor->startAfterVerify = true;
return;
}
tr_torrentRecheckCompleteness( tor );
if( tor->startAfterVerify ) {
- tor->startAfterVerify = FALSE;
+ tor->startAfterVerify = false;
torrentStart( tor );
}
}
/* if the torrent's running, stop it & set the restart-after-verify flag */
if( tor->startAfterVerify || tor->isRunning ) {
/* don't clobber isStopping */
- const tr_bool startAfter = tor->isStopping ? FALSE : TRUE;
+ const bool startAfter = tor->isStopping ? false : true;
tr_torrentStop( tor );
tor->startAfterVerify = startAfter;
}
if( setLocalErrorIfFilesDisappeared( tor ) )
- tor->startAfterVerify = FALSE;
+ tor->startAfterVerify = false;
else
tr_verifyAdd( tor, torrentRecheckDoneCB );
if( tor->isDirty )
{
- tor->isDirty = FALSE;
+ tor->isDirty = false;
tr_torrentSaveResume( tor );
}
}
struct remove_data
{
tr_torrent * tor;
- tr_bool deleteFlag;
+ bool deleteFlag;
tr_fileFunc * deleteFunc;
};
void
tr_torrentRemove( tr_torrent * tor,
- tr_bool deleteFlag,
+ bool deleteFlag,
tr_fileFunc deleteFunc )
{
struct remove_data * data;
static void
fireCompletenessChange( tr_torrent * tor,
tr_completeness status,
- tr_bool wasRunning )
+ bool wasRunning )
{
assert( ( status == TR_LEECH )
|| ( status == TR_SEED )
if( completeness != tor->completeness )
{
const int recentChange = tor->downloadedCur != 0;
- const tr_bool wasLeeching = !tr_torrentIsSeed( tor );
- const tr_bool wasRunning = tor->isRunning;
+ const bool wasLeeching = !tr_torrentIsSeed( tor );
+ const bool wasRunning = tor->isRunning;
if( recentChange )
{
}
if( tor->currentDir == tor->incompleteDir )
- tr_torrentSetLocation( tor, tor->downloadDir, TRUE, NULL, NULL );
+ tr_torrentSetLocation( tor, tor->downloadDir, true, NULL, NULL );
if( tr_sessionIsTorrentDoneScriptEnabled( tor->session ) )
torrentCallScript( tor, tr_sessionGetTorrentDoneScript( tor->session ) );
tr_torrentInitFileDLs( tr_torrent * tor,
const tr_file_index_t * files,
tr_file_index_t fileCount,
- tr_bool doDownload )
+ bool doDownload )
{
tr_file_index_t i;
tr_torrentSetFileDLs( tr_torrent * tor,
const tr_file_index_t * files,
tr_file_index_t fileCount,
- tr_bool doDownload )
+ bool doDownload )
{
assert( tr_isTorrent( tor ) );
tr_torrentLock( tor );
return ret;
}
-tr_bool
+bool
tr_torrentReqIsValid( const tr_torrent * tor,
tr_piece_index_t index,
uint32_t offset,
tor->info.pieces[i].timeChecked = when;
}
-tr_bool
+bool
tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex )
{
- const tr_bool pass = tr_ioTestPiece( tor, pieceIndex );
+ const bool pass = tr_ioTestPiece( tor, pieceIndex );
tr_deeplog_tor( tor, "[LAZY] tr_torrentCheckPiece tested piece %zu, pass==%d", (size_t)pieceIndex, (int)pass );
tr_torrentSetHasPiece( tor, pieceIndex, pass );
return mtime;
}
-tr_bool
+bool
tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t p )
{
uint64_t unused;
/* if we've never checked this piece, then it needs to be checked */
if( !inf->pieces[p].timeChecked )
- return TRUE;
+ return true;
/* If we think we've completed one of the files in this piece,
* but it's been modified since we last checked it,
for( ; f < inf->fileCount && pieceHasFile( p, &inf->files[f] ); ++f )
if( tr_cpFileIsComplete( &tor->completion, f ) )
if( tr_torrentGetFileMTime( tor, f ) > inf->pieces[p].timeChecked )
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
/***
return a - b;
}
-tr_bool
+bool
tr_torrentSetAnnounceList( tr_torrent * tor,
const tr_tracker_info * trackers_in,
int trackerCount )
{
int i;
tr_benc metainfo;
- tr_bool ok = TRUE;
+ bool ok = true;
tr_tracker_info * trackers;
tr_torrentLock( tor );
/* look for bad URLs */
for( i=0; ok && i<trackerCount; ++i )
if( !tr_urlIsValidTracker( trackers[i].announce ) )
- ok = FALSE;
+ ok = false;
/* save to the .torrent file */
if( ok && !tr_bencLoadFile( &metainfo, TR_FMT_BENC, tor->info.torrent ) )
{
- tr_bool hasInfo;
+ bool hasInfo;
tr_info tmpInfo;
/* remove the old fields */
if( ( tor->error == TR_STAT_TRACKER_WARNING )
|| ( tor->error == TR_STAT_TRACKER_ERROR ) )
{
- tr_bool clear = TRUE;
+ bool clear = true;
for( i=0; clear && i<trackerCount; ++i )
if( !strcmp( trackers[i].announce, tor->errorTracker ) )
- clear = FALSE;
+ clear = false;
if( clear )
tr_torrentClearError( tor );
else if( S_ISREG( sb.st_mode ) && ( sb.st_size > 0 ) )
{
const char * sub = buf + strlen( tor->currentDir ) + strlen( TR_PATH_DELIMITER_STR );
- const tr_bool isTorrentFile = tr_ptrArrayFindSorted( torrentFiles, sub, vstrcmp ) != NULL;
+ const bool isTorrentFile = tr_ptrArrayFindSorted( torrentFiles, sub, vstrcmp ) != NULL;
if( !isTorrentFile )
addDirtyFile( root, buf, dirtyFolders );
}
struct LocationData
{
- tr_bool move_from_old_location;
+ bool move_from_old_location;
volatile int * setme_state;
volatile double * setme_progress;
char * location;
static void
setLocation( void * vdata )
{
- tr_bool err = FALSE;
+ bool err = false;
struct LocationData * data = vdata;
tr_torrent * tor = data->tor;
- const tr_bool do_move = data->move_from_old_location;
+ const bool do_move = data->move_from_old_location;
const char * location = data->location;
double bytesHandled = 0;
if( do_move && !tr_is_same_file( oldpath, newpath ) )
{
- tr_bool renamed = FALSE;
+ bool renamed = false;
errno = 0;
tr_torinf( tor, "moving \"%s\" to \"%s\"", oldpath, newpath );
if( tr_moveFile( oldpath, newpath, &renamed ) )
{
- err = TRUE;
+ err = true;
tr_torerr( tor, "error moving \"%s\" to \"%s\": %s",
oldpath, newpath, tr_strerror( errno ) );
}
void
tr_torrentSetLocation( tr_torrent * tor,
const char * location,
- tr_bool move_from_old_location,
+ bool move_from_old_location,
volatile double * setme_progress,
volatile int * setme_state )
{
****
***/
-static tr_bool
+static bool
fileExists( const char * filename )
{
struct stat sb;
- const tr_bool ok = !stat( filename, &sb );
+ const bool ok = !stat( filename, &sb );
return ok;
}
-tr_bool
+bool
tr_torrentFindFile2( const tr_torrent * tor, tr_file_index_t fileNum,
const char ** base, char ** subpath )
{
**/
void tr_ctorSetSave( tr_ctor * ctor,
- tr_bool saveMetadataInOurTorrentsDir );
+ bool saveMetadataInOurTorrentsDir );
int tr_ctorGetSave( const tr_ctor * ctor );
/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
void tr_torrentInitFileDLs( tr_torrent * tor,
const tr_file_index_t * files,
- tr_file_index_t fileCount,
- tr_bool do_download );
+ tr_file_index_t fileCount,
+ bool do_download );
void tr_torrentRecheckCompleteness( tr_torrent * );
void tr_torrentSetHasPiece( tr_torrent * tor,
tr_piece_index_t pieceIndex,
- tr_bool has );
+ bool has );
void tr_torrentChangeMyPort( tr_torrent * session );
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session,
const uint8_t * hash );
-tr_bool tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
+bool tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
tr_direction direction );
tr_piece_index_t index,
uint32_t offset );
-tr_bool tr_torrentReqIsValid( const tr_torrent * tor,
+bool tr_torrentReqIsValid( const tr_torrent * tor,
tr_piece_index_t index,
uint32_t offset,
uint32_t length );
time_t dhtAnnounceAt;
time_t dhtAnnounce6At;
- tr_bool dhtAnnounceInProgress;
- tr_bool dhtAnnounce6InProgress;
+ bool dhtAnnounceInProgress;
+ bool dhtAnnounce6InProgress;
time_t lpdAnnounceAt;
tr_torrent_idle_limit_hit_func * idle_limit_hit_func;
void * idle_limit_hit_func_user_data;
- tr_bool isRunning;
- tr_bool isStopping;
- tr_bool isDeleting;
- tr_bool startAfterVerify;
- tr_bool isDirty;
+ bool isRunning;
+ bool isStopping;
+ bool isDeleting;
+ bool startAfterVerify;
+ bool isDirty;
- tr_bool infoDictOffsetIsCached;
+ bool infoDictOffsetIsCached;
uint16_t maxConnectedPeers;
uint16_t idleLimitMinutes;
tr_idlelimit idleLimitMode;
- tr_bool finishedSeedingByIdle;
+ bool finishedSeedingByIdle;
};
static inline tr_torrent*
tr_sessionLock( tor->session );
}
-static inline tr_bool tr_torrentIsLocked( const tr_torrent * tor )
+static inline bool tr_torrentIsLocked( const tr_torrent * tor )
{
return tr_sessionIsLocked( tor->session );
}
tr_sessionUnlock( tor->session );
}
-static inline tr_bool
+static inline bool
tr_torrentExists( const tr_session * session, const uint8_t * torrentHash )
{
return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
}
-static inline tr_bool
+static inline bool
tr_torrentIsSeed( const tr_torrent * tor )
{
return tor->completeness != TR_LEECH;
}
-static inline tr_bool tr_torrentIsPrivate( const tr_torrent * tor )
+static inline bool tr_torrentIsPrivate( const tr_torrent * tor )
{
return ( tor != NULL ) && tor->info.isPrivate;
}
-static inline tr_bool tr_torrentAllowsPex( const tr_torrent * tor )
+static inline bool tr_torrentAllowsPex( const tr_torrent * tor )
{
return ( tor != NULL )
&& ( tor->session->isPexEnabled )
&& ( !tr_torrentIsPrivate( tor ) );
}
-static inline tr_bool tr_torrentAllowsDHT( const tr_torrent * tor )
+static inline bool tr_torrentAllowsDHT( const tr_torrent * tor )
{
return ( tor != NULL )
&& ( tr_sessionAllowsDHT( tor->session ) )
&& ( !tr_torrentIsPrivate( tor ) );
}
-static inline tr_bool tr_torrentAllowsLPD( const tr_torrent * tor )
+static inline bool tr_torrentAllowsLPD( const tr_torrent * tor )
{
return ( tor != NULL )
&& ( tr_sessionAllowsLPD( tor->session ) )
TORRENT_MAGIC_NUMBER = 95549
};
-static inline tr_bool tr_isTorrent( const tr_torrent * tor )
+static inline bool tr_isTorrent( const tr_torrent * tor )
{
return ( tor != NULL )
&& ( tor->magicNumber == TORRENT_MAGIC_NUMBER )
{
assert( tr_isTorrent( tor ) );
- tor->isDirty = TRUE;
+ tor->isDirty = true;
}
uint32_t tr_getBlockSize( uint32_t pieceSize );
* @param subpath on success, this pointer is assigned a newly-allocated
* string holding the second half of the filename.
*/
-tr_bool tr_torrentFindFile2( const tr_torrent *, tr_file_index_t fileNo,
- const char ** base, char ** subpath );
+bool tr_torrentFindFile2( const tr_torrent *, tr_file_index_t fileNo,
+ const char ** base, char ** subpath );
/* Returns a newly-allocated version of the tr_file.name string
/**
* @return true if this piece needs to be tested
*/
-tr_bool tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t pieceIndex );
+bool tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t pieceIndex );
/**
* @brief Test a piece against its info dict checksum
* @return true if the piece's passes the checksum test
*/
-tr_bool tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex );
+bool tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex );
time_t tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i );
{
tr_benc benc;
int rc;
- tr_bool have_id = FALSE;
+ bool have_id = false;
char * dat_file;
uint8_t * nodes = NULL, * nodes6 = NULL;
const uint8_t * raw;
session = NULL;
}
-tr_bool
+bool
tr_dhtEnabled( const tr_session * ss )
{
return ss && ( ss == session );
tr_dhtAddNode( tr_session * ss,
const tr_address * address,
tr_port port,
- tr_bool bootstrap )
+ bool bootstrap )
{
int af = address->type == TR_AF_INET ? AF_INET : AF_INET6;
}
static int
-tr_dhtAnnounce(tr_torrent *tor, int af, tr_bool announce)
+tr_dhtAnnounce(tr_torrent *tor, int af, bool announce)
{
int rc, status, numnodes, ret = 0;
af == AF_INET6 ? " IPv6" : "",
tr_dhtPrintableStatus(status), numnodes);
if(af == AF_INET)
- tor->dhtAnnounceInProgress = TRUE;
+ tor->dhtAnnounceInProgress = true;
else
- tor->dhtAnnounce6InProgress = TRUE;
+ tor->dhtAnnounce6InProgress = true;
ret = 1;
} else {
tr_torerr(tor, "%sDHT announce failed (%s, %d nodes): %s",
int tr_dhtInit( tr_session * );
void tr_dhtUninit( tr_session * );
-tr_bool tr_dhtEnabled( const tr_session * );
+bool tr_dhtEnabled( const tr_session * );
tr_port tr_dhtPort ( tr_session * );
int tr_dhtStatus( tr_session *, int af, int * setme_nodeCount );
const char *tr_dhtPrintableStatus(int status);
-int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, tr_bool bootstrap );
+int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, bool bootstrap );
void tr_dhtUpkeep( tr_session * );
void tr_dhtCallback(unsigned char *buf, int buflen,
struct sockaddr *from, socklen_t fromlen,
session = NULL;
}
-tr_bool tr_lpdEnabled( const tr_session* ss )
+bool
+tr_lpdEnabled( const tr_session* ss )
{
return ss && ( ss == session );
}
* @brief Announce the given torrent on the local network
*
* @param[in] t Torrent to announce
-* @return Returns TRUE on success
+* @return Returns true on success
*
* Send a query for torrent t out to the LPD multicast group (or the LAN, for that
* matter). A listening client on the same network might react by adding us to his
* peer pool for torrent t.
*/
-tr_bool tr_lpdSendAnnounce( const tr_torrent* t )
+bool
+tr_lpdSendAnnounce( const tr_torrent* t )
{
size_t i;
const char fmt[] =
char query[lpd_maxDatagramLength + 1] = { };
if( t == NULL )
- return FALSE;
+ return false;
/* make sure the hash string is normalized, just in case */
for( i = 0; i < sizeof hashString; i++ )
(const struct sockaddr*) &lpd_mcastAddr, sizeof lpd_mcastAddr );
if( res != len )
- return FALSE;
+ return false;
}
tr_tordbg( t, "LPD announce message away" );
- return TRUE;
+ return true;
}
/**
/* $Id$ */
-int tr_lpdInit( tr_session*, tr_address* );
+int tr_lpdInit( tr_session*, tr_address* );
void tr_lpdUninit( tr_session* );
-
-tr_bool tr_lpdEnabled( const tr_session* );
-
-tr_bool tr_lpdSendAnnounce( const tr_torrent* );
+bool tr_lpdEnabled( const tr_session* );
+bool tr_lpdSendAnnounce( const tr_torrent* );
/**
* @defgroup Preproc Helper macros
void
tr_udpSetSocketBuffers(tr_session *session)
{
- tr_bool utp = tr_sessionIsUTPEnabled(session);
+ bool utp = tr_sessionIsUTPEnabled(session);
if(session->udp_socket >= 0)
set_socket_buffers(session->udp_socket, utp);
if(session->udp6_socket >= 0)
IPv6 address, if I may say so myself. */
static void
-rebind_ipv6(tr_session *ss, tr_bool force)
+rebind_ipv6(tr_session *ss, bool force)
{
- tr_bool is_default;
+ bool is_default;
const struct tr_address * public_addr;
struct sockaddr_in6 sin6;
const unsigned char *ipv6 = tr_globalIPv6();
void
tr_udpInit(tr_session *ss)
{
- tr_bool is_default;
+ bool is_default;
const struct tr_address * public_addr;
struct sockaddr_in sin;
int rc;
ipv6:
if(tr_globalIPv6())
- rebind_ipv6(ss, TRUE);
+ rebind_ipv6(ss, true);
if(ss->udp6_socket >= 0) {
ss->udp6_event =
event_new(ss->event_base, ss->udp6_socket, EV_READ | EV_PERSIST,
void tr_udpUninit( tr_session * );
void tr_udpSetSocketBuffers(tr_session *);
-tr_bool tau_handle_message( tr_session * session,
- const uint8_t * msg, size_t msglen );
+bool tau_handle_message( tr_session * session,
+ const uint8_t * msg, size_t msglen );
#endif /* #ifndef TR_UDP_H */
tr_nerr( MY_NAME, "UTP_RBDrained(%p, %zu) was called.", socket, count );
dbgmsg( "UTP_RBDrained(%p, %zu) was called.", socket, count );
assert( 0 ); /* FIXME: this is too much for the long term, but probably needed in the short term */
- return FALSE;
+ return false;
}
int tr_utpPacket(const unsigned char *buf UNUSED, size_t buflen UNUSED,
****
***/
-#include <stdbool.h>
#include <inttypes.h> /* uintN_t */
#include <time.h> /* time_t */
+#ifdef HAVE_STDBOOL_H
+ #include <stdbool.h>
+#elif !defined(__bool_true_false_are_defined)
+ #define bool uint8_t
+ #define true 1
+ #define false 0
+#endif
+
#ifndef PRId64
#define PRId64 "lld"
#endif
* if we ever need to grow past that, change this to uint64_t ;) */
typedef uint32_t tr_block_index_t;
typedef uint16_t tr_port;
-typedef uint8_t tr_bool;
typedef struct tr_ctor tr_ctor;
typedef struct tr_info tr_info;
* @param dictionary pointer to an uninitialized tr_benc
* @param configDir the configuration directory to find settings.json
* @param appName if configDir is empty, appName is used to find the default dir.
- * @return success TRUE if the settings were loaded, FALSE otherwise
+ * @return success true if the settings were loaded, false otherwise
* @see tr_sessionGetDefaultSettings()
* @see tr_sessionInit()
* @see tr_sessionSaveSettings()
*/
-tr_bool tr_sessionLoadSettings( struct tr_benc * dictionary,
- const char * configDir,
- const char * appName );
+bool tr_sessionLoadSettings( struct tr_benc * dictionary,
+ const char * configDir,
+ const char * appName );
/**
* Add the session's configuration settings to the benc dictionary
*/
tr_session * tr_sessionInit( const char * tag,
const char * configDir,
- tr_bool messageQueueingEnabled,
+ bool messageQueueingEnabled,
struct tr_benc * settings );
/** @brief Update a session's settings from a benc dictionary
const char* tr_sessionGetIncompleteDir( const tr_session * session );
/** @brief enable or disable use of the incomplete download folder */
-void tr_sessionSetIncompleteDirEnabled( tr_session * session, tr_bool );
+void tr_sessionSetIncompleteDirEnabled( tr_session * session, bool );
/** @brief get whether or not the incomplete download folder is enabled */
-tr_bool tr_sessionIsIncompleteDirEnabled( const tr_session * session );
+bool tr_sessionIsIncompleteDirEnabled( const tr_session * session );
/**
*
* @see tr_sessionIsIncompleteFileNamingEnabled()
*/
-void tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, tr_bool );
+void tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, bool );
/** @brief return true if files will end in ".part" until they're complete */
-tr_bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session );
+bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session );
/**
* @brief Set whether or not RPC calls are allowed in this session.
* queried by tr_sessionIsRPCEnabled().
*/
void tr_sessionSetRPCEnabled( tr_session * session,
- tr_bool isEnabled );
+ bool isEnabled );
/** @brief Get whether or not RPC calls are allowed in this session.
@see tr_sessionInit()
@see tr_sessionSetRPCEnabled() */
-tr_bool tr_sessionIsRPCEnabled( const tr_session * session );
+bool tr_sessionIsRPCEnabled( const tr_session * session );
/** @brief Specify which port to listen for RPC requests on.
@see tr_sessionInit()
const char* tr_sessionGetRPCWhitelist( const tr_session * );
void tr_sessionSetRPCWhitelistEnabled( tr_session * session,
- tr_bool isEnabled );
+ bool isEnabled );
-tr_bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session );
+bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session );
void tr_sessionSetRPCPassword( tr_session * session,
const char * password );
const char* tr_sessionGetRPCUsername( const tr_session * session );
void tr_sessionSetRPCPasswordEnabled( tr_session * session,
- tr_bool isEnabled );
+ bool isEnabled );
-tr_bool tr_sessionIsRPCPasswordEnabled( const tr_session * session );
+bool tr_sessionIsRPCPasswordEnabled( const tr_session * session );
const char* tr_sessionGetRPCBindAddress( const tr_session * session );
* PEX is always disabled in private torrents regardless of this.
* In public torrents, PEX is enabled by default.
*/
-void tr_sessionSetPexEnabled( tr_session * session, tr_bool isEnabled );
-tr_bool tr_sessionIsPexEnabled( const tr_session * session );
+void tr_sessionSetPexEnabled( tr_session * session, bool isEnabled );
+bool tr_sessionIsPexEnabled( const tr_session * session );
-tr_bool tr_sessionIsDHTEnabled( const tr_session * session );
-void tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
+bool tr_sessionIsDHTEnabled( const tr_session * session );
+void tr_sessionSetDHTEnabled( tr_session * session, bool );
-tr_bool tr_sessionIsUTPEnabled( const tr_session * session );
-void tr_sessionSetUTPEnabled( tr_session * session, tr_bool );
+bool tr_sessionIsUTPEnabled( const tr_session * session );
+void tr_sessionSetUTPEnabled( tr_session * session, bool );
-tr_bool tr_sessionIsLPDEnabled( const tr_session * session );
-void tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled );
+bool tr_sessionIsLPDEnabled( const tr_session * session );
+void tr_sessionSetLPDEnabled( tr_session * session, bool enabled );
-void tr_sessionSetCacheLimit_MB( tr_session * session, int mb );
-int tr_sessionGetCacheLimit_MB( const tr_session * session );
+void tr_sessionSetCacheLimit_MB( tr_session * session, int mb );
+int tr_sessionGetCacheLimit_MB( const tr_session * session );
tr_encryption_mode tr_sessionGetEncryption( tr_session * session );
void tr_sessionSetEncryption( tr_session * session,
*/
void tr_sessionSetPortForwardingEnabled( tr_session * session,
- tr_bool enabled );
+ bool enabled );
-tr_bool tr_sessionIsPortForwardingEnabled( const tr_session * session );
+bool tr_sessionIsPortForwardingEnabled( const tr_session * session );
void tr_sessionSetPeerPort( tr_session * session,
tr_port port);
tr_port tr_sessionSetPeerPortRandom( tr_session * session );
-void tr_sessionSetPeerPortRandomOnStart( tr_session * session,
- tr_bool random );
+void tr_sessionSetPeerPortRandomOnStart( tr_session * session, bool random );
-tr_bool tr_sessionGetPeerPortRandomOnStart( tr_session * session );
+bool tr_sessionGetPeerPortRandomOnStart( tr_session * session );
typedef enum
{
**** Primary session speed limits
***/
-void tr_sessionSetSpeedLimit_KBps ( tr_session *, tr_direction, int KBps );
-int tr_sessionGetSpeedLimit_KBps ( const tr_session *, tr_direction );
+void tr_sessionSetSpeedLimit_KBps ( tr_session *, tr_direction, int KBps );
+int tr_sessionGetSpeedLimit_KBps ( const tr_session *, tr_direction );
-void tr_sessionLimitSpeed ( tr_session *, tr_direction, tr_bool );
-tr_bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction );
+void tr_sessionLimitSpeed ( tr_session *, tr_direction, bool );
+bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction );
/***
void tr_sessionSetAltSpeed_KBps ( tr_session *, tr_direction, int Bps );
int tr_sessionGetAltSpeed_KBps ( const tr_session *, tr_direction );
-void tr_sessionUseAltSpeed ( tr_session *, tr_bool );
-tr_bool tr_sessionUsesAltSpeed ( const tr_session * );
+void tr_sessionUseAltSpeed ( tr_session *, bool );
+bool tr_sessionUsesAltSpeed ( const tr_session * );
-void tr_sessionUseAltSpeedTime ( tr_session *, tr_bool );
-tr_bool tr_sessionUsesAltSpeedTime ( const tr_session * );
+void tr_sessionUseAltSpeedTime ( tr_session *, bool );
+bool tr_sessionUsesAltSpeedTime ( const tr_session * );
void tr_sessionSetAltSpeedBegin ( tr_session *, int minsSinceMidnight );
int tr_sessionGetAltSpeedBegin ( const tr_session * );
tr_sched_day tr_sessionGetAltSpeedDay ( const tr_session * );
typedef void ( tr_altSpeedFunc )( tr_session *,
- tr_bool active,
- tr_bool userDriven,
+ bool active,
+ bool userDriven,
void * );
void tr_sessionClearAltSpeedFunc ( tr_session * );
void tr_sessionSetAltSpeedFunc ( tr_session *, tr_altSpeedFunc *, void * );
-tr_bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
- tr_direction dir,
- double * setme );
+bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
+ tr_direction dir,
+ double * setme );
/***
****
double tr_sessionGetRawSpeed_KBps ( const tr_session *, tr_direction );
-void tr_sessionSetRatioLimited ( tr_session *, tr_bool isLimited );
-tr_bool tr_sessionIsRatioLimited ( const tr_session * );
+void tr_sessionSetRatioLimited ( tr_session *, bool isLimited );
+bool tr_sessionIsRatioLimited ( const tr_session * );
void tr_sessionSetRatioLimit ( tr_session *, double desiredRatio );
double tr_sessionGetRatioLimit ( const tr_session * );
-void tr_sessionSetIdleLimited ( tr_session *, tr_bool isLimited );
-tr_bool tr_sessionIsIdleLimited ( const tr_session * );
+void tr_sessionSetIdleLimited ( tr_session *, bool isLimited );
+bool tr_sessionIsIdleLimited ( const tr_session * );
void tr_sessionSetIdleLimit ( tr_session *, uint16_t idleMinutes );
uint16_t tr_sessionGetIdleLimit ( const tr_session * );
void tr_sessionSetPeerLimitPerTorrent( tr_session *, uint16_t maxPeers );
uint16_t tr_sessionGetPeerLimitPerTorrent( const tr_session * );
-void tr_sessionSetPaused ( tr_session *, tr_bool isPaused );
-tr_bool tr_sessionGetPaused ( const tr_session * );
+void tr_sessionSetPaused ( tr_session *, bool isPaused );
+bool tr_sessionGetPaused ( const tr_session * );
-void tr_sessionSetDeleteSource ( tr_session *, tr_bool deleteSource );
-tr_bool tr_sessionGetDeleteSource ( const tr_session * );
+void tr_sessionSetDeleteSource ( tr_session *, bool deleteSource );
+bool tr_sessionGetDeleteSource ( const tr_session * );
tr_priority_t tr_torrentGetPriority( const tr_torrent * );
void tr_torrentSetPriority( tr_torrent *, tr_priority_t );
***
**/
-tr_bool tr_sessionIsTorrentDoneScriptEnabled( const tr_session * );
+bool tr_sessionIsTorrentDoneScriptEnabled( const tr_session * );
-void tr_sessionSetTorrentDoneScriptEnabled( tr_session *, tr_bool isEnabled );
+void tr_sessionSetTorrentDoneScriptEnabled( tr_session *, bool isEnabled );
const char * tr_sessionGetTorrentDoneScript( const tr_session * );
}
tr_msg_list;
-void tr_setMessageQueuing( tr_bool isEnabled );
+void tr_setMessageQueuing( bool isEnabled );
-tr_bool tr_getMessageQueuing( void );
+bool tr_getMessageQueuing( void );
tr_msg_list * tr_getQueuedMessages( void );
int tr_blocklistGetRuleCount ( const tr_session * session );
-tr_bool tr_blocklistExists ( const tr_session * session );
+bool tr_blocklistExists ( const tr_session * session );
-tr_bool tr_blocklistIsEnabled ( const tr_session * session );
+bool tr_blocklistIsEnabled ( const tr_session * session );
void tr_blocklistSetEnabled ( tr_session * session,
- tr_bool isEnabled );
+ bool isEnabled );
/** @brief The blocklist that ges updated when an RPC client
invokes the "blocklist-update" method */
/** @brief Set whether or not to delete the source .torrent file
when the torrent is added. (Default: False) */
-void tr_ctorSetDeleteSource( tr_ctor * ctor, tr_bool doDelete );
+void tr_ctorSetDeleteSource( tr_ctor * ctor, bool doDelete );
/** @brief Set the constructor's metainfo from a magnet link */
int tr_ctorSetMetainfoFromMagnetLink( tr_ctor * ctor, const char * magnet );
(Default: not paused) */
void tr_ctorSetPaused( tr_ctor * ctor,
tr_ctorMode mode,
- tr_bool isPaused );
+ bool isPaused );
/** @brief Set the priorities for files in a torrent */
void tr_ctorSetFilePriorities( tr_ctor * ctor,
void tr_ctorSetFilesWanted( tr_ctor * ctor,
const tr_file_index_t * fileIndices,
tr_file_index_t fileCount,
- tr_bool wanted );
+ bool wanted );
/** @brief Get this peer constructor's peer limit */
/** @brief Get the "isPaused" flag from this peer constructor */
int tr_ctorGetPaused( const tr_ctor * ctor,
tr_ctorMode mode,
- tr_bool * setmeIsPaused );
+ bool * setmeIsPaused );
/** @brief Get the download path from this peer constructor */
int tr_ctorGetDownloadDir( const tr_ctor * ctor,
/** @brief Get the "delete .torrent file" flag from this peer constructor */
int tr_ctorGetDeleteSource( const tr_ctor * ctor,
- tr_bool * setmeDoDelete );
+ bool * setmeDoDelete );
/** @brief Get the tr_session poiner from this peer constructor */
tr_session* tr_ctorGetSession( const tr_ctor * ctor );
/** @brief Removes our .torrent and .resume files for
this torrent, then calls tr_torrentFree(). */
void tr_torrentRemove( tr_torrent * torrent,
- tr_bool removeLocalData,
+ bool removeLocalData,
tr_fileFunc removeFunc );
/** @brief Start a torrent */
*/
void tr_torrentSetLocation( tr_torrent * torrent,
const char * location,
- tr_bool move_from_previous_location,
+ bool move_from_previous_location,
volatile double * setme_progress,
volatile int * setme_state );
void tr_torrentSetSpeedLimit_KBps ( tr_torrent *, tr_direction, int KBps );
int tr_torrentGetSpeedLimit_KBps ( const tr_torrent *, tr_direction );
-void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, tr_bool );
-tr_bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction );
+void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, bool );
+bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction );
-void tr_torrentUseSessionLimits ( tr_torrent *, tr_bool );
-tr_bool tr_torrentUsesSessionLimits ( const tr_torrent * );
+void tr_torrentUseSessionLimits ( tr_torrent *, bool );
+bool tr_torrentUsesSessionLimits ( const tr_torrent * );
/****
double tr_torrentGetRatioLimit( const tr_torrent * tor );
-tr_bool tr_torrentGetSeedRatio( const tr_torrent *, double * ratio );
+bool tr_torrentGetSeedRatio( const tr_torrent *, double * ratio );
/****
uint16_t tr_torrentGetIdleLimit( const tr_torrent * tor );
-tr_bool tr_torrentGetSeedIdle( const tr_torrent *, uint16_t * minutes );
+bool tr_torrentGetSeedIdle( const tr_torrent *, uint16_t * minutes );
/****
***** Peer Limits
void tr_torrentSetFileDLs( tr_torrent * torrent,
const tr_file_index_t * files,
tr_file_index_t fileCount,
- tr_bool do_download );
+ bool do_download );
const tr_info * tr_torrentInfo( const tr_torrent * torrent );
* and reassigns 'id'.
* @param trackerCount size of the `trackers' array
*/
-tr_bool
+bool
tr_torrentSetAnnounceList( tr_torrent * torrent,
const tr_tracker_info * trackers,
int trackerCount );
*/
typedef void ( tr_torrent_completeness_func )( tr_torrent * torrent,
tr_completeness completeness,
- tr_bool wasRunning,
+ bool wasRunning,
void * user_data );
typedef void ( tr_torrent_ratio_limit_hit_func )( tr_torrent * torrent,
void tr_torrentManualUpdate( tr_torrent * torrent );
-tr_bool tr_torrentCanManualUpdate( const tr_torrent * torrent );
+bool tr_torrentCanManualUpdate( const tr_torrent * torrent );
/***
**** tr_peer_stat
typedef struct tr_peer_stat
{
- tr_bool isUTP;
+ bool isUTP;
- tr_bool isEncrypted;
- tr_bool isDownloadingFrom;
- tr_bool isUploadingTo;
- tr_bool isSeed;
+ bool isEncrypted;
+ bool isDownloadingFrom;
+ bool isUploadingTo;
+ bool isSeed;
- tr_bool peerIsChoked;
- tr_bool peerIsInterested;
- tr_bool clientIsChoked;
- tr_bool clientIsInterested;
- tr_bool isIncoming;
+ bool peerIsChoked;
+ bool peerIsInterested;
+ bool clientIsChoked;
+ bool clientIsInterested;
+ bool isIncoming;
uint8_t from;
tr_port port;
int downloadCount;
/* whether or not we've ever sent this tracker an announcement */
- tr_bool hasAnnounced;
+ bool hasAnnounced;
/* whether or not we've ever scraped to this tracker */
- tr_bool hasScraped;
+ bool hasScraped;
/* human-readable string identifying the tracker */
char host[1024];
/* Transmission uses one tracker per tier,
* and the others are kept as backups */
- tr_bool isBackup;
+ bool isBackup;
/* is the tracker announcing, waiting, queued, etc */
tr_tracker_state announceState;
/* whether or not the last announce was a success.
if "hasAnnounced" is false, this field is undefined */
- tr_bool lastAnnounceSucceeded;
+ bool lastAnnounceSucceeded;
/* whether or not the last announce timed out. */
- tr_bool lastAnnounceTimedOut;
+ bool lastAnnounceTimedOut;
/* when the last announce was completed.
if "hasAnnounced" is false, this field is undefined */
/* whether or not the last scrape was a success.
if "hasAnnounced" is false, this field is undefined */
- tr_bool lastScrapeSucceeded;
+ bool lastScrapeSucceeded;
/* whether or not the last scrape timed out. */
- tr_bool lastScrapeTimedOut;
+ bool lastScrapeTimedOut;
/* when the last scrape was completed.
if "hasScraped" is false, this field is undefined */
char hashString[2 * SHA_DIGEST_LENGTH + 1];
/* Flags */
- tr_bool isPrivate;
- tr_bool isMultifile;
+ bool isPrivate;
+ bool isMultifile;
};
-static inline tr_bool tr_torrentHasMetadata( const tr_torrent * tor )
+static inline bool tr_torrentHasMetadata( const tr_torrent * tor )
{
return tr_torrentInfo( tor )->fileCount > 0;
}
/** A torrent is considered finished if it has met its seed ratio.
As a result, only paused torrents can be finished. */
- tr_bool finished;
+ bool finished;
}
tr_stat;
/** @} */
/** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */
-static inline tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; }
+static inline bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; }
-/** @brief Sanity checker to test that a bool is TRUE or FALSE */
-static inline tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; }
+/** @brief Sanity checker to test that a bool is true or false */
+static inline bool tr_isBool( bool b ) { return b==1 || b==0; }
#ifdef __cplusplus
}
/* set the struct's fields */
eh->base = base;
eh->session->event_base = base;
- eh->session->evdns_base = evdns_base_new( base, TRUE );
+ eh->session->evdns_base = evdns_base_new( base, true );
eh->session->events = eh;
/* listen to the pipe's read fd */
{
assert( tr_isSession( session ) );
- session->events->die = TRUE;
+ session->events->die = true;
tr_deepLog( __FILE__, __LINE__, NULL, "closing trevent pipe" );
tr_netCloseSocket( session->events->fds[1] );
}
***
**/
-tr_bool
+bool
tr_amInEventThread( const tr_session * session )
{
assert( tr_isSession( session ) );
/**
**/
-void tr_eventInit( tr_session * );
+void tr_eventInit( tr_session * );
-void tr_eventClose( tr_session * );
+void tr_eventClose( tr_session * );
-tr_bool tr_amInEventThread( const tr_session * );
+bool tr_amInEventThread( const tr_session * );
-void tr_runInEventThread( tr_session *, void func( void* ), void * user_data );
+void tr_runInEventThread( tr_session *, void func( void* ), void * user_data );
#endif
struct tr_upnp
{
- tr_bool hasDiscovered;
+ bool hasDiscovered;
struct UPNPUrls urls;
struct IGDdatas data;
int port;
portStr, "UDP", intClient, intPort ) != UPNPCOMMAND_SUCCESS )
{
tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
- handle->isMapped = FALSE;
+ handle->isMapped = false;
}
}
int i;
const int A[] = { 1, 2, 3, 3, 3, 5, 8 };
const int expected_pos[] = { 0, 1, 2, 5, 5, 6, 6, 6, 7, 7 };
- const int expected_exact[] = { TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE };
+ const int expected_exact[] = { true, true, true, false, true, false, false, true, false, false };
const int N = sizeof(A) / sizeof(A[0]);
for( i=1; i<=10; ++i )
{
- tr_bool exact;
+ bool exact;
const int pos = tr_lowerBound( &i, A, N, sizeof(int), compareInts, &exact );
#if 0
time_t __tr_current_time = 0;
tr_msg_level __tr_message_level = TR_MSG_ERR;
-static tr_bool messageQueuing = FALSE;
+static bool messageQueuing = false;
static tr_msg_list * messageQueue = NULL;
static tr_msg_list ** messageQueueTail = &messageQueue;
static int messageQueueCount = 0;
#ifndef WIN32
/* make null versions of these win32 functions */
- static inline int IsDebuggerPresent( void ) { return FALSE; }
+ static inline int IsDebuggerPresent( void ) { return false; }
static inline void OutputDebugString( const void * unused UNUSED ) { }
#endif
void*
tr_getLog( void )
{
- static tr_bool initialized = FALSE;
+ static bool initialized = false;
static FILE * file = NULL;
if( !initialized )
default:
file = NULL; break;
}
- initialized = TRUE;
+ initialized = true;
}
return file;
}
void
-tr_setMessageQueuing( tr_bool enabled )
+tr_setMessageQueuing( bool enabled )
{
messageQueuing = enabled;
}
-tr_bool
+bool
tr_getMessageQueuing( void )
{
return messageQueuing != 0;
return buf;
}
-tr_bool
+bool
tr_deepLoggingIsActive( void )
{
static int8_t deepLoggingIsActive = -1;
return str;
}
-tr_bool
+bool
tr_str_has_suffix( const char *str, const char *suffix )
{
size_t str_len;
size_t suffix_len;
if( !str )
- return FALSE;
+ return false;
if( !suffix )
- return TRUE;
+ return true;
str_len = strlen( str );
suffix_len = strlen( suffix );
if( str_len < suffix_len )
- return FALSE;
+ return false;
return !evutil_ascii_strncasecmp( str + str_len - suffix_len, suffix, suffix_len );
}
****
***/
-static tr_bool
+static bool
isValidURLChars( const char * url, int url_len )
{
const char * c;
"{}|\\^[]`"; /* unwise */
if( url == NULL )
- return FALSE;
+ return false;
for( c=url, end=c+url_len; c && *c && c!=end; ++c )
if( !strchr( rfc2396_valid_chars, *c ) )
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
-/** @brief return TRUE if the URL is a http or https or UDP one that Transmission understands */
-tr_bool
+/** @brief return true if the URL is a http or https or UDP one that Transmission understands */
+bool
tr_urlIsValidTracker( const char * url )
{
- tr_bool valid;
+ bool valid;
char * scheme = NULL;
const int len = url ? strlen(url) : 0;
return valid;
}
-/** @brief return TRUE if the URL is a http or https or ftp or sftp one that Transmission understands */
-tr_bool
+/** @brief return true if the URL is a http or https or ftp or sftp one that Transmission understands */
+bool
tr_urlIsValid( const char * url, int url_len )
{
- tr_bool valid;
+ bool valid;
char * scheme = NULL;
if( ( url_len < 0 ) && ( url != NULL ) )
url_len = strlen( url );
return valid;
}
-tr_bool
+bool
tr_addressIsIP( const char * address )
{
tr_address tempAddr;
size_t nmemb,
size_t size,
int (* compar)(const void* key, const void* arrayMember),
- tr_bool * exact_match )
+ bool * exact_match )
{
size_t first = 0;
const char * cbase = base;
- tr_bool exact = FALSE;
+ bool exact = false;
while( nmemb != 0 )
{
if( c <= 0 ) {
if( c == 0 )
- exact = TRUE;
+ exact = true;
nmemb = half;
} else {
first = middle + 1;
* This should be a single number (ex. "6") or a range (ex. "6-9").
* Anything else is an error and will return failure.
*/
-static tr_bool
+static bool
parseNumberSection( const char * str, int len, struct number_range * setme )
{
long a, b;
- tr_bool success;
+ bool success;
char * end;
const int error = errno;
char * tmp = tr_strndup( str, len );
errno = 0;
a = b = strtol( tmp, &end, 10 );
if( errno || ( end == tmp ) ) {
- success = FALSE;
+ success = false;
} else if( *end != '-' ) {
- success = TRUE;
+ success = true;
} else {
const char * pch = end + 1;
b = strtol( pch, &end, 10 );
if( errno || ( pch == end ) )
- success = FALSE;
+ success = false;
else if( *end ) /* trailing data */
- success = FALSE;
+ success = false;
else
- success = TRUE;
+ success = true;
}
tr_free( tmp );
char * str = tr_strndup( str_in, len );
const char * walk;
tr_list * ranges = NULL;
- tr_bool success = TRUE;
+ bool success = true;
walk = str;
while( walk && *walk && success ) {
***/
int
-tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed )
+tr_moveFile( const char * oldpath, const char * newpath, bool * renamed )
{
int in;
int out;
return 0;
}
-tr_bool
+bool
tr_is_same_file( const char * filename1, const char * filename2 )
{
struct stat sb1, sb2;
* @{
*/
-#ifndef FALSE
- #define FALSE 0
-#endif
-
-#ifndef TRUE
- #define TRUE 1
-#endif
-
#ifndef UNUSED
#ifdef __GNUC__
#define UNUSED __attribute__ ( ( unused ) )
return __tr_message_level;
}
-static inline tr_bool tr_msgLoggingIsActive( tr_msg_level level )
+static inline bool tr_msgLoggingIsActive( tr_msg_level level )
{
return tr_getMessageLevel() >= level;
}
void* tr_getLog( void );
/** @brief return true if deep logging has been enabled by the user; false otherwise */
-tr_bool tr_deepLoggingIsActive( void );
+bool tr_deepLoggingIsActive( void );
void tr_deepLog( const char * file,
int line,
* @brief Rich Salz's classic implementation of shell-style pattern matching for ?, \, [], and * characters.
* @return 1 if the pattern matches, 0 if it doesn't, or -1 if an error occured
*/
-int tr_wildmat( const char * text, const char * pattern ) TR_GNUC_NONNULL(1,2);
+bool tr_wildmat( const char * text, const char * pattern ) TR_GNUC_NONNULL(1,2);
/** @brief Portability wrapper for basename() that uses the system implementation if available */
char* tr_basename( const char * path ) TR_GNUC_MALLOC;
size_t nmemb,
size_t size,
int (* compar)(const void* key, const void* arrayMember),
- tr_bool * exact_match ) TR_GNUC_HOT TR_GNUC_NONNULL(1,5,6);
+ bool * exact_match ) TR_GNUC_HOT TR_GNUC_NONNULL(1,5,6);
/**
char* tr_strstrip( char * str );
/** @brief Returns true if the string ends with the specified case-insensitive suffix */
-tr_bool tr_str_has_suffix( const char *str, const char *suffix );
+bool tr_str_has_suffix( const char *str, const char *suffix );
/** @brief Portability wrapper for memmem() that uses the system implementation if available */
void tr_hex_to_sha1( uint8_t * out, const char * hex ) TR_GNUC_NONNULL(1,2);
/** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */
-tr_bool tr_addressIsIP( const char * address );
+bool tr_addressIsIP( const char * address );
-/** @brief return TRUE if the url is a http or https url that Transmission understands */
-tr_bool tr_urlIsValidTracker( const char * url ) TR_GNUC_NONNULL(1);
+/** @brief return true if the url is a http or https url that Transmission understands */
+bool tr_urlIsValidTracker( const char * url ) TR_GNUC_NONNULL(1);
-/** @brief return TRUE if the url is a [ http, https, ftp, ftps ] url that Transmission understands */
-tr_bool tr_urlIsValid( const char * url, int url_len ) TR_GNUC_NONNULL(1);
+/** @brief return true if the url is a [ http, https, ftp, ftps ] url that Transmission understands */
+bool tr_urlIsValid( const char * url, int url_len ) TR_GNUC_NONNULL(1);
/** @brief parse a URL into its component parts
@return zero on success or an error number if an error occurred */
* @return 0 on success; otherwise, return -1 and set errno
*/
int tr_moveFile( const char * oldpath, const char * newpath,
- tr_bool * renamed ) TR_GNUC_NONNULL(1,2);
+ bool * renamed ) TR_GNUC_NONNULL(1,2);
/** @brief Test to see if the two filenames point to the same file. */
-tr_bool tr_is_same_file( const char * filename1, const char * filename2 );
+bool tr_is_same_file( const char * filename1, const char * filename2 );
/** @brief convenience function to remove an item from an array */
void tr_removeElementFromArray( void * array,
MSEC_TO_SLEEP_PER_SECOND_DURING_VERIFY = 100
};
-static tr_bool
-verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
+static bool
+verifyTorrent( tr_torrent * tor, bool * stopFlag )
{
time_t end;
SHA_CTX sha;
int fd = -1;
int64_t filePos = 0;
- tr_bool changed = 0;
- tr_bool hadPiece = 0;
+ bool changed = 0;
+ bool hadPiece = 0;
time_t lastSleptAt = 0;
uint32_t piecePos = 0;
tr_file_index_t fileIndex = 0;
if( leftInPiece == 0 )
{
time_t now;
- tr_bool hasPiece;
+ bool hasPiece;
uint8_t hash[SHA_DIGEST_LENGTH];
SHA1_Final( hash, &sha );
static struct verify_node currentNode;
static tr_list * verifyList = NULL;
static tr_thread * verifyThread = NULL;
-static tr_bool stopCurrent = FALSE;
+static bool stopCurrent = false;
static tr_lock*
getVerifyLock( void )
struct verify_node * node;
tr_lockLock( getVerifyLock( ) );
- stopCurrent = FALSE;
+ stopCurrent = false;
node = (struct verify_node*) verifyList ? verifyList->data : NULL;
if( node == NULL )
{
if( tor == currentNode.torrent )
{
- stopCurrent = TRUE;
+ stopCurrent = true;
while( stopCurrent )
{
tr_lockUnlock( lock );
{
tr_lockLock( getVerifyLock( ) );
- stopCurrent = TRUE;
+ stopCurrent = true;
tr_list_free( &verifyList, tr_free );
tr_lockUnlock( getVerifyLock( ) );
{
long code;
long timeout_secs;
- tr_bool did_connect;
- tr_bool did_timeout;
+ bool did_connect;
+ bool did_timeout;
struct evbuffer * response;
struct evbuffer * freebuf;
char * url;
sockoptfunction( void * vtask, curl_socket_t fd, curlsocktype purpose UNUSED )
{
struct tr_web_task * task = vtask;
- const tr_bool isScrape = strstr( task->url, "scrape" ) != NULL;
- const tr_bool isAnnounce = strstr( task->url, "announce" ) != NULL;
+ const bool isScrape = strstr( task->url, "scrape" ) != NULL;
+ const bool isAnnounce = strstr( task->url, "announce" ) != NULL;
/* announce and scrape requests have tiny payloads. */
if( isScrape || isAnnounce )
createEasy( tr_session * s, struct tr_web_task * task )
{
const tr_address * addr;
- tr_bool is_default_value;
+ bool is_default_value;
CURL * e = curl_easy_init( );
const long verbose = getenv( "TR_CURL_VERBOSE" ) != NULL;
char * cookie_filename = tr_buildPath( s->configDir, "cookies.txt", NULL );
void
tr_http_escape( struct evbuffer * out,
- const char * str, int len, tr_bool escape_slashes )
+ const char * str, int len, bool escape_slashes )
{
const char * end;
void tr_webClose( tr_session * session, tr_web_close_mode close_mode );
typedef void ( tr_web_done_func )( tr_session * session,
- tr_bool timeout_flag,
- tr_bool did_connect_flag,
+ bool timeout_flag,
+ bool did_connect_flag,
long response_code,
const void * response,
size_t response_byte_count,
void * done_func_user_data,
struct evbuffer * buffer );
-void tr_http_escape( struct evbuffer *out, const char *str, int len, tr_bool escape_slashes );
+void tr_http_escape( struct evbuffer *out, const char *str, int len, bool escape_slashes );
void tr_http_escape_sha1( char * out, const uint8_t * sha1_digest );
char * base_url;
size_t base_url_len;
int torrent_id;
- tr_bool is_stopping;
+ bool is_stopping;
int consecutive_failures;
};
tr_peer_event e = TR_PEER_EVENT_INIT;
e.eventType = TR_PEER_CLIENT_GOT_DATA;
e.length = length;
- e.wasPieceData = TRUE;
+ e.wasPieceData = true;
publish( w, &e );
}
if( ( info->n_added > 0 ) && !w->is_stopping )
{
- tr_bandwidthUsed( &w->bandwidth, TR_DOWN, info->n_added, TRUE, tr_time_msec( ) );
+ tr_bandwidthUsed( &w->bandwidth, TR_DOWN, info->n_added, true, tr_time_msec( ) );
fire_client_got_data( w, info->n_added );
}
}
static void task_request_next_chunk( struct tr_webseed_task * task );
-static tr_bool
+static bool
webseed_has_tasks( const tr_webseed * w )
{
return w->tasks != NULL;
static void
web_response_func( tr_session * session,
- tr_bool did_connect UNUSED,
- tr_bool did_timeout UNUSED,
+ bool did_connect UNUSED,
+ bool did_timeout UNUSED,
long response_code,
const void * response UNUSED,
size_t response_byte_count UNUSED,
/* if url ends with a '/', add the torrent name */
if( w->base_url[w->base_url_len - 1] == '/' && file->name )
- tr_http_escape( out, file->name, strlen(file->name), FALSE );
+ tr_http_escape( out, file->name, strlen(file->name), false );
return evbuffer_free_to_str( out );
}
}
}
-tr_bool
+bool
tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps )
{
- const tr_bool is_active = webseed_has_tasks( w );
+ const bool is_active = webseed_has_tasks( w );
*setme_Bps = is_active ? tr_bandwidthGetPieceSpeed_Bps( &w->bandwidth, now, TR_DOWN ) : 0;
return is_active;
}
-tr_bool
+bool
tr_webseedIsActive( const tr_webseed * w )
{
int Bps = 0;
/* construct parent class */
tr_peerConstruct( peer );
- peer->peerIsChoked = TRUE;
+ peer->peerIsChoked = true;
peer->clientIsInterested = !tr_torrentIsSeed( tor );
peer->client = tr_strdup( "webseed" );
tr_bitsetSetHaveAll( &peer->have );
if( w )
{
if( webseed_has_tasks( w ) )
- w->is_stopping = TRUE;
+ w->is_stopping = true;
else
webseed_free( w );
}
void tr_webseedFree( tr_webseed * );
/** @return true if a request is being processed, or false if idle */
-tr_bool tr_webseedGetSpeed_Bps( const tr_webseed * w,
+bool tr_webseedGetSpeed_Bps( const tr_webseed * w,
uint64_t now,
int * setme_Bps );
/** @return true if a request is being processed, or false if idle */
-tr_bool tr_webseedIsActive( const tr_webseed * w );
+bool tr_webseedIsActive( const tr_webseed * w );
#endif
** explanation is from Lars:
** The precondition that must be fulfilled is that DoMatch will consume
** at least one character in text. This is true if *p is neither '*' nor
-** '\0'.) The last return has ABORT instead of FALSE to avoid quadratic
+** '\0'.) The last return has ABORT instead of false to avoid quadratic
** behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With
-** FALSE, each star-loop has to run to the end of the text; with ABORT
+** false, each star-loop has to run to the end of the text; with ABORT
** only the last one does.
**
** Once the control of one instance of DoMatch enters the star-loop, that
-** instance will return either TRUE or ABORT, and any calling instance
+** instance will return either true or ABORT, and any calling instance
** will therefore return immediately after (without calling recursively
** again). In effect, only one star-loop is ever active. It would be
** possible to modify the code to maintain this context explicitly,
/*
-** Match text and p, return TRUE, FALSE, or ABORT.
+** Match text and p, return true, false, or ABORT.
*/
static int
DoMatch( const char * text, const char * p )
/* FALLTHROUGH */
default:
if (*text != *p)
- return FALSE;
+ return false;
continue;
case '?':
/* Match anything. */
continue;
if (*p == '\0')
/* Trailing star matches everything. */
- return TRUE;
+ return true;
while (*text)
- if ((matched = DoMatch(text++, p)) != FALSE)
+ if ((matched = DoMatch(text++, p)) != false)
return matched;
return ABORT;
case '[':
- reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
+ reverse = p[1] == NEGATE_CLASS ? true : false;
if (reverse)
/* Inverted character class. */
p++;
- for (last = 0400, matched = FALSE; *++p && *p != ']'; last = *p)
+ for (last = 0400, matched = false; *++p && *p != ']'; last = *p)
/* This next line requires a good C compiler. */
if (*p == '-' ? *text <= *++p && *text >= last : *text == *p)
- matched = TRUE;
+ matched = true;
if (matched == reverse)
- return FALSE;
+ return false;
continue;
}
}
#ifdef MATCH_TAR_PATTERN
if (*text == '/')
- return TRUE;
+ return true;
#endif /* MATCH_TAR_ATTERN */
return *text == '\0';
}
-/*
-** User-level routine. Returns TRUE or FALSE.
-*/
-int
+/* User-level routine. returns whether or not 'text' and 'p' matched */
+bool
tr_wildmat(const char * text, const char * p )
{
if (p[0] == '*' && p[1] == '\0')
- return TRUE;
+ return true;
- return DoMatch(text, p) == TRUE;
+ return DoMatch(text, p) == true;
}
#define DONATE_NAG_TIME (60 * 60 * 24 * 7)
-static void altSpeedToggledCallback(tr_session * handle UNUSED, tr_bool active, tr_bool byUser, void * controller)
+static void altSpeedToggledCallback(tr_session * handle UNUSED, bool active, bool byUser, void * controller)
{
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [[NSNumber alloc] initWithBool: active], @"Active",
[[NSNumber alloc] initWithBool: byUser], @"ByUser", nil];
@end
-void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, tr_bool wasRunning, void * torrentData)
+void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, bool wasRunning, void * torrentData)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
typedef char * str;
#ifndef __cplusplus
-typedef uint8 bool;
+#include <stdbool.h>
#endif
#endif //__UTYPES_H__
#define MAX_TRACKERS 128
static tr_tracker_info trackers[MAX_TRACKERS];
static int trackerCount = 0;
-static tr_bool isPrivate = FALSE;
-static tr_bool showVersion = FALSE;
+static bool isPrivate = false;
+static bool showVersion = false;
const char * comment = NULL;
const char * outfile = NULL;
const char * infile = NULL;
{
switch( c )
{
- case 'V': showVersion = TRUE; break;
- case 'p': isPrivate = TRUE; break;
+ case 'V': showVersion = true; break;
+ case 'p': isPrivate = true; break;
case 'o': outfile = optarg; break;
case 'c': comment = optarg; break;
case 't': if( trackerCount + 1 < MAX_TRACKERS ) {
#define MY_NAME "transmission-edit"
static int fileCount = 0;
-static tr_bool showVersion = FALSE;
+static bool showVersion = false;
static const char ** files = NULL;
static const char * add = NULL;
static const char * deleteme = NULL;
if( c != TR_OPT_UNK ) return 1;
replace[1] = optarg;
break;
- case 'V': showVersion = TRUE;
+ case 'V': showVersion = true;
break;
case TR_OPT_UNK: files[fileCount++] = optarg; break;
default: return 1;
return 0;
}
-static tr_bool
+static bool
removeURL( tr_benc * metainfo, const char * url )
{
const char * str;
tr_benc * announce_list;
- tr_bool changed = FALSE;
+ bool changed = false;
if( tr_bencDictFindStr( metainfo, "announce", &str ) && !strcmp( str, url ) )
{
printf( "\tRemoved \"%s\" from \"announce\"\n", str );
tr_bencDictRemove( metainfo, "announce" );
- changed = TRUE;
+ changed = true;
}
if( tr_bencDictFindList( metainfo, "announce-list", &announce_list ) )
{
printf( "\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, (tierIndex+1) );
tr_bencListRemove( tier, nodeIndex );
- changed = TRUE;
+ changed = true;
}
else ++nodeIndex;
}
return evbuffer_free_to_str( buf );
}
-static tr_bool
+static bool
replaceURL( tr_benc * metainfo, const char * in, const char * out )
{
const char * str;
tr_benc * announce_list;
- tr_bool changed = FALSE;
+ bool changed = false;
if( tr_bencDictFindStr( metainfo, "announce", &str ) && strstr( str, in ) )
{
printf( "\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr );
tr_bencDictAddStr( metainfo, "announce", newstr );
tr_free( newstr );
- changed = TRUE;
+ changed = true;
}
if( tr_bencDictFindList( metainfo, "announce-list", &announce_list ) )
tr_bencFree( node );
tr_bencInitStr( node, newstr, -1 );
tr_free( newstr );
- changed = TRUE;
+ changed = true;
}
}
}
return changed;
}
-static tr_bool
+static bool
addURL( tr_benc * metainfo, const char * url )
{
const char * str;
tr_benc * announce_list;
- tr_bool changed = FALSE;
- tr_bool match = FALSE;
+ bool changed = false;
+ bool match = false;
/* maybe add it to "announce" */
if( !tr_bencDictFindStr( metainfo, "announce", &str ) )
{
printf( "\tAdded \"%s\" in \"announce\"\n", url );
tr_bencDictAddStr( metainfo, "announce", url );
- changed = TRUE;
+ changed = true;
}
/* see if it's already in announce-list */
int nodeCount = 0;
while(( node = tr_bencListChild( tier, nodeCount++ )))
if( tr_bencGetStr( node, &str ) && !strcmp( str, url ) )
- match = TRUE;
+ match = true;
}
}
tier = tr_bencListAddList( announce_list, 1 );
tr_bencListAddStr( tier, url );
printf( "\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_bencListSize( announce_list ) );
- changed = TRUE;
+ changed = true;
}
return changed;
for( i=0; i<fileCount; ++i )
{
tr_benc top;
- tr_bool changed = FALSE;
+ bool changed = false;
const char * filename = files[i];
printf( "%s\n", filename );
return "Usage: " MY_NAME " [options] <.torrent file>";
}
-static tr_bool scrapeFlag = FALSE;
-static tr_bool showVersion = FALSE;
+static bool scrapeFlag = false;
+static bool showVersion = false;
const char * filename = NULL;
static int
{
switch( c )
{
- case 's': scrapeFlag = TRUE; break;
- case 'V': showVersion = TRUE; break;
+ case 's': scrapeFlag = true; break;
+ case 'V': showVersion = true; break;
case TR_OPT_UNK: filename = optarg; break;
default: return 1;
}
{
tr_benc top;
tr_benc * files;
- tr_bool matched = FALSE;
+ bool matched = false;
const char * begin = (const char*) evbuffer_pullup( buf, -1 );
const char * end = begin + evbuffer_get_length( buf );
tr_bencDictFindInt( val, "complete", &seeders );
tr_bencDictFindInt( val, "incomplete", &leechers );
printf( "%d seeders, %d leechers\n", (int)seeders, (int)leechers );
- matched = TRUE;
+ matched = true;
}
}
}