static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80;
static const size_t SUCCESS_HTTP_SIZE_OFF = 17;
static char g_adminip[4] = {0,0,0,0};
-#ifdef WANT_BLACKLISTING
-static char *blacklist_filename = NULL;
+
+#if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER )
+ #error WANT_BLACKLISTING and WANT_CLOSED_TRACKER are exclusive.
+#endif
+#if defined ( WANT_BLACKLISTING ) || defined (WANT_CLOSED_TRACKER )
+static char *accesslist_filename = NULL;
+#define WANT_ACCESS_CONTROL
#endif
/* To always have space for error messages ;) */
}
static void usage( char *name ) {
- fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]\n", name );
+ fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]"
+#ifdef WANT_BLACKLISTING
+ " [-b blacklistfile]"
+#elif defined ( WANT_CLOSED_TRACKER )
+ " [-w whitelistfile]"
+#endif
+ "\n", name );
}
#define HELPLINE(opt,desc) fprintf(stderr, "\t%-10s%s\n",opt,desc)
HELPLINE("-A ip","bless an ip address as admin address (e.g. to allow syncs from this address)");
#ifdef WANT_BLACKLISTING
HELPLINE("-b file","specify blacklist file.");
+#elif defined( WANT_CLOSED_TRACKER )
+ HELPLINE("-w file","specify whitelist file.");
#endif
fprintf( stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -i 10.1.1.23 -p 2710 -p 80\n" );
++ot_sockets_count;
}
-#ifdef WANT_BLACKLISTING
-/* Read initial black list */
-void read_blacklist_file( int foo ) {
- FILE * blacklist_filehandle;
+#ifdef WANT_ACCESS_CONTROL
+/* Read initial access list */
+void read_accesslist_file( int foo ) {
+ FILE * accesslist_filehandle;
ot_hash infohash;
foo = foo;
- signal( SIGHUP, SIG_IGN );
- blacklist_filehandle = fopen( blacklist_filename, "r" );
+ accesslist_filehandle = fopen( accesslist_filename, "r" );
- /* Free blacklist vector in trackerlogic.c*/
- blacklist_reset();
+ /* Free accesslist vector in trackerlogic.c*/
+ accesslist_reset();
- if( blacklist_filehandle == NULL ) {
- fprintf( stderr, "Warning: Can't open blacklist file: %s (but will try to create it later, if necessary and possible).", blacklist_filename );
- signal( SIGHUP, read_blacklist_file );
+ if( accesslist_filehandle == NULL ) {
+ fprintf( stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).", accesslist_filename );
return;
}
/* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */
- while( fgets( static_inbuf, sizeof(static_inbuf), blacklist_filehandle ) ) {
+ while( fgets( static_inbuf, sizeof(static_inbuf), accesslist_filehandle ) ) {
int i;
for( i=0; i<20; ++i ) {
int eger = 16 * scan_fromhex( static_inbuf[ 2*i ] ) + scan_fromhex( static_inbuf[ 1 + 2*i ] );
if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 )
goto ignore_line;
- /* Append blacklist to blacklist vector */
- blacklist_addentry( &infohash );
+ /* Append accesslist to accesslist vector */
+ accesslist_addentry( &infohash );
ignore_line:
continue;
}
- fclose( blacklist_filehandle );
- signal( SIGHUP, read_blacklist_file );
+ fclose( accesslist_filehandle );
}
#endif
int scanon = 1;
while( scanon ) {
- switch( getopt( argc, argv, ":i:p:A:P:d:b:h" ) ) {
+ switch( getopt( argc, argv, ":i:p:A:P:d:"
+#ifdef WANT_BLACKLISTING
+"b:"
+#elif defined( WANT_CLOSED_TRACKER )
+"w:"
+#endif
+ "h" ) ) {
case -1 : scanon = 0; break;
case 'i': scan_ip4( optarg, serverip ); break;
case 'A': scan_ip4( optarg, g_adminip ); break;
#ifdef WANT_BLACKLISTING
- case 'b': blacklist_filename = optarg; break;
+ case 'b': accesslist_filename = optarg; break;
+#elif defined( WANT_CLOSED_TRACKER )
+ case 'w': accesslist_filename = optarg; break;
#endif
case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break;
case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break;
}
endpwent();
-#ifdef WANT_BLACKLISTING
+#ifdef WANT_ACCESS_CONTROL
/* Passing "0" since read_blacklist_file also is SIGHUP handler */
- if( blacklist_filename ) {
- read_blacklist_file( 0 );
- signal( SIGHUP, read_blacklist_file );
+ if( accesslist_filename ) {
+ read_accesslist_file( 0 );
+ signal( SIGHUP, read_accesslist_file );
}
#endif
/* GLOBAL VARIABLES */
static ot_vector all_torrents[256];
static ot_vector changeset;
-#ifdef WANT_BLACKLISTING
-static ot_vector blacklist;
+#if defined ( WANT_BLACKLISTING ) || defined( WANT_CLOSED_TRACKER )
+static ot_vector accesslist;
+#define WANT_ACCESS_CONTROL
#endif
size_t changeset_size = 0;
ot_vector *torrents_list = &all_torrents[*hash[0]], *peer_pool;
int base_pool = 0;
-#ifdef WANT_BLACKLISTING
- binary_search( hash, blacklist.data, blacklist.size, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &exactmatch );
- if( exactmatch )
+#ifdef WANT_ACCESS_CONTROL
+ binary_search( hash, accesslist.data, accesslist.size, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &exactmatch );
+
+#ifdef WANT_CLOSED_TRACKER
+ exactmatch = !exactmatch;
+#endif
+
+ if( !exactmatch )
return NULL;
#endif
changeset_size = 0;
}
-#ifdef WANT_BLACKLISTING
-void blacklist_reset( void ) {
- free( blacklist.data );
- byte_zero( &blacklist, sizeof( blacklist ) );
+#ifdef WANT_ACCESS_CONTROL
+void accesslist_reset( void ) {
+ free( accesslist.data );
+ byte_zero( &accesslist, sizeof( accesslist ) );
}
-int blacklist_addentry( ot_hash *infohash ) {
+int accesslist_addentry( ot_hash *infohash ) {
int em;
- void *insert = vector_find_or_insert( &blacklist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &em );
+ void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &em );
if( !insert )
return -1;