summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
authorerdgeist <>2009-03-17 23:57:20 +0000
committererdgeist <>2009-03-17 23:57:20 +0000
commitc7ed890222939ff9d9a3b575eb83f216ccfebe9e (patch)
tree09bcb2adbb64b2c3eb53bf20145262d13b258284 /opentracker.c
parenta58bce83ad91fa264a79c9a9acc9358bb2aa5661 (diff)
Fix white spaces
Introduce loading tracker states with -l Alter tracker state to a human readable form
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c45
1 files changed, 41 insertions, 4 deletions
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 ) {
51 if( s == SIGINT ) { 51 if( s == SIGINT ) {
52 /* Any new interrupt signal quits the application */ 52 /* Any new interrupt signal quits the application */
53 signal( SIGINT, SIG_DFL); 53 signal( SIGINT, SIG_DFL);
54 54
55 /* Tell all other threads to not acquire any new lock on a bucket 55 /* Tell all other threads to not acquire any new lock on a bucket
56 but cancel their operations and return */ 56 but cancel their operations and return */
57 g_opentracker_running = 0; 57 g_opentracker_running = 0;
@@ -250,7 +250,7 @@ static int64_t ot_try_bind( ot_ip6 ip, uint16_t port, PROTO_FLAG proto ) {
250#else 250#else
251 if( ip6_isv4mapped(ip) ) { 251 if( ip6_isv4mapped(ip) ) {
252 exerr( "V6 Tracker is V6 only!" ); 252 exerr( "V6 Tracker is V6 only!" );
253 } 253 }
254#endif 254#endif
255 255
256#ifdef _DEBUG 256#ifdef _DEBUG
@@ -261,7 +261,7 @@ static int64_t ot_try_bind( ot_ip6 ip, uint16_t port, PROTO_FLAG proto ) {
261 snprintf( _debug + off, sizeof(_debug)-off, "]:%d...", port); 261 snprintf( _debug + off, sizeof(_debug)-off, "]:%d...", port);
262 fputs( _debug, stderr ); 262 fputs( _debug, stderr );
263#endif 263#endif
264 264
265 if( socket_bind6_reuse( sock, ip, port, 0 ) == -1 ) 265 if( socket_bind6_reuse( sock, ip, port, 0 ) == -1 )
266 panic( "socket_bind6_reuse" ); 266 panic( "socket_bind6_reuse" );
267 267
@@ -394,6 +394,42 @@ int parse_configfile( char * config_filename ) {
394 return bound; 394 return bound;
395} 395}
396 396
397void load_state(const char * const state_filename ) {
398 FILE * state_filehandle;
399 char inbuf[512];
400 ot_hash infohash;
401 unsigned long long base, downcount;
402 int consumed;
403
404 state_filehandle = fopen( state_filename, "r" );
405
406 if( state_filehandle == NULL ) {
407 fprintf( stderr, "Warning: Can't open config file: %s.", state_filename );
408 return;
409 }
410
411 /* We do ignore anything that is not of the form "^[:xdigit:]:\d+:\d+" */
412 while( fgets( inbuf, sizeof(inbuf), state_filehandle ) ) {
413 int i;
414 for( i=0; i<(int)sizeof(ot_hash); ++i ) {
415 int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] );
416 if( eger < 0 )
417 continue;
418 infohash[i] = eger;
419 }
420
421 if( i != (int)sizeof(ot_hash) ) continue;
422 i *= 2;
423
424 if( inbuf[ i++ ] != ':' || !( consumed = scan_ulonglong( inbuf+i, &base ) ) ) continue;
425 i += consumed;
426 if( inbuf[ i++ ] != ':' || !( consumed = scan_ulonglong( inbuf+i, &downcount ) ) ) continue;
427 add_torrent_from_saved_state( infohash, base, downcount );
428 }
429
430 fclose( state_filehandle );
431}
432
397int drop_privileges (const char * const serverdir) { 433int drop_privileges (const char * const serverdir) {
398 struct passwd *pws = NULL; 434 struct passwd *pws = NULL;
399 435
@@ -448,7 +484,7 @@ int main( int argc, char **argv ) {
448#endif 484#endif
449 485
450while( scanon ) { 486while( scanon ) {
451 switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:v" 487 switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:l:v"
452#ifdef WANT_ACCESSLIST_BLACK 488#ifdef WANT_ACCESSLIST_BLACK
453"b:" 489"b:"
454#elif defined( WANT_ACCESSLIST_WHITE ) 490#elif defined( WANT_ACCESSLIST_WHITE )
@@ -477,6 +513,7 @@ while( scanon ) {
477#endif 513#endif
478 case 'd': set_config_option( &g_serverdir, optarg ); break; 514 case 'd': set_config_option( &g_serverdir, optarg ); break;
479 case 'r': set_config_option( &g_redirecturl, optarg ); break; 515 case 'r': set_config_option( &g_redirecturl, optarg ); break;
516 case 'l': load_state( optarg ); break;
480 case 'A': 517 case 'A':
481 if( !scan_ip6( optarg, tmpip )) { usage( argv[0] ); exit( 1 ); } 518 if( !scan_ip6( optarg, tmpip )) { usage( argv[0] ); exit( 1 ); }
482 accesslist_blessip( tmpip, 0xffff ); /* Allow everything for now */ 519 accesslist_blessip( tmpip, 0xffff ); /* Allow everything for now */