From c7ed890222939ff9d9a3b575eb83f216ccfebe9e Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 17 Mar 2009 23:57:20 +0000 Subject: Fix white spaces Introduce loading tracker states with -l Alter tracker state to a human readable form --- opentracker.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'opentracker.c') diff --git a/opentracker.c b/opentracker.c index c67e331..a82518d 100644 --- a/opentracker.c +++ b/opentracker.c @@ -51,7 +51,7 @@ static void signal_handler( int s ) { if( s == SIGINT ) { /* Any new interrupt signal quits the application */ signal( SIGINT, SIG_DFL); - + /* Tell all other threads to not acquire any new lock on a bucket but cancel their operations and return */ g_opentracker_running = 0; @@ -250,7 +250,7 @@ static int64_t ot_try_bind( ot_ip6 ip, uint16_t port, PROTO_FLAG proto ) { #else if( ip6_isv4mapped(ip) ) { exerr( "V6 Tracker is V6 only!" ); - } + } #endif #ifdef _DEBUG @@ -261,7 +261,7 @@ static int64_t ot_try_bind( ot_ip6 ip, uint16_t port, PROTO_FLAG proto ) { snprintf( _debug + off, sizeof(_debug)-off, "]:%d...", port); fputs( _debug, stderr ); #endif - + if( socket_bind6_reuse( sock, ip, port, 0 ) == -1 ) panic( "socket_bind6_reuse" ); @@ -394,6 +394,42 @@ int parse_configfile( char * config_filename ) { return bound; } +void load_state(const char * const state_filename ) { + FILE * state_filehandle; + char inbuf[512]; + ot_hash infohash; + unsigned long long base, downcount; + int consumed; + + state_filehandle = fopen( state_filename, "r" ); + + if( state_filehandle == NULL ) { + fprintf( stderr, "Warning: Can't open config file: %s.", state_filename ); + return; + } + + /* We do ignore anything that is not of the form "^[:xdigit:]:\d+:\d+" */ + while( fgets( inbuf, sizeof(inbuf), state_filehandle ) ) { + int i; + for( i=0; i<(int)sizeof(ot_hash); ++i ) { + int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] ); + if( eger < 0 ) + continue; + infohash[i] = eger; + } + + if( i != (int)sizeof(ot_hash) ) continue; + i *= 2; + + if( inbuf[ i++ ] != ':' || !( consumed = scan_ulonglong( inbuf+i, &base ) ) ) continue; + i += consumed; + if( inbuf[ i++ ] != ':' || !( consumed = scan_ulonglong( inbuf+i, &downcount ) ) ) continue; + add_torrent_from_saved_state( infohash, base, downcount ); + } + + fclose( state_filehandle ); +} + int drop_privileges (const char * const serverdir) { struct passwd *pws = NULL; @@ -448,7 +484,7 @@ int main( int argc, char **argv ) { #endif while( scanon ) { - switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:v" + switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:l:v" #ifdef WANT_ACCESSLIST_BLACK "b:" #elif defined( WANT_ACCESSLIST_WHITE ) @@ -477,6 +513,7 @@ while( scanon ) { #endif case 'd': set_config_option( &g_serverdir, optarg ); break; case 'r': set_config_option( &g_redirecturl, optarg ); break; + case 'l': load_state( optarg ); break; case 'A': if( !scan_ip6( optarg, tmpip )) { usage( argv[0] ); exit( 1 ); } accesslist_blessip( tmpip, 0xffff ); /* Allow everything for now */ -- cgit v1.2.3