]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Allow for more than one admin ip address
authorerdgeist <>
Thu, 1 Nov 2007 20:13:03 +0000 (20:13 +0000)
committererdgeist <>
Thu, 1 Nov 2007 20:13:03 +0000 (20:13 +0000)
opentracker.c
trackerlogic.h

index 9c3636160c7f065284eb8c765d72455c0bd7482a..00210d287931849f1698144fa12e79d217ee0f8e 100644 (file)
@@ -40,7 +40,8 @@ static unsigned long long ot_full_scrape_size = 0;
 static time_t ot_start_time;
 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};
+static uint32_t g_adminip_addresses[OT_ADMINIP_MAX];
+static unsigned int g_adminip_count = 0;
 time_t g_now;
 
 #if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER )
@@ -90,7 +91,8 @@ struct http_data {
   unsigned char    ip[4];
   STRUCT_HTTP_FLAG flag;
 };
-#define NOTBLESSED( h ) byte_diff( &h->ip, 4, g_adminip )
+#define NOTBLESSED( h ) (!bsearch( &h->ip, g_adminip_addresses, g_adminip_count, 4, ot_ip_compare ))
+static int ot_ip_compare( const void *a, const void *b ) { return memcmp( a,b,4 ); }
 
 /* Prototypes */
 
@@ -954,7 +956,6 @@ int main( int argc, char **argv ) {
     "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': accesslist_filename = optarg; break;
 #elif defined( WANT_CLOSED_TRACKER )
@@ -963,12 +964,19 @@ int main( int argc, char **argv ) {
       case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break;
       case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break;
       case 'd': serverdir = optarg; break;
+      case 'A':
+        if( g_adminip_count < OT_ADMINIP_MAX )
+          scan_ip4( optarg, (char*)(g_adminip_addresses + g_adminip_count++) );
+        break;
       case 'h': help( argv[0] ); exit( 0 );
       default:
       case '?': usage( argv[0] ); exit( 1 );
     }
   }
 
+  /* Sort our admin ips for quick lookup */
+  qsort( g_adminip_addresses, g_adminip_count, 4, ot_ip_compare );
+
   /* Bind to our default tcp/udp ports */
   if( !ot_sockets_count ) {
     ot_try_bind( serverip, 6969, 1 );
index ccd34659878c1fccc13f40434c243c67d12ace9e..9cbffc15665fb5cec95c7de1d3f7e4ae63781f6a 100644 (file)
@@ -42,6 +42,9 @@ typedef struct {
 
 #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) )
 
+/* Number of tracker admin ip addresses allowed */
+#define OT_ADMINIP_MAX 64
+
 /* We maintain a list of 4096 pointers to sorted list of ot_torrent structs
    Sort key is, of course, its hash */
 #define OT_BUCKET_COUNT 1024