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 )
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 */
"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 )
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 );
#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