diff options
-rw-r--r-- | opentracker.c | 14 | ||||
-rw-r--r-- | trackerlogic.h | 3 |
2 files changed, 14 insertions, 3 deletions
diff --git a/opentracker.c b/opentracker.c index 9c36361..00210d2 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -40,7 +40,8 @@ static unsigned long long ot_full_scrape_size = 0; | |||
40 | static time_t ot_start_time; | 40 | static time_t ot_start_time; |
41 | static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; | 41 | static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; |
42 | static const size_t SUCCESS_HTTP_SIZE_OFF = 17; | 42 | static const size_t SUCCESS_HTTP_SIZE_OFF = 17; |
43 | static char g_adminip[4] = {0,0,0,0}; | 43 | static uint32_t g_adminip_addresses[OT_ADMINIP_MAX]; |
44 | static unsigned int g_adminip_count = 0; | ||
44 | time_t g_now; | 45 | time_t g_now; |
45 | 46 | ||
46 | #if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER ) | 47 | #if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER ) |
@@ -90,7 +91,8 @@ struct http_data { | |||
90 | unsigned char ip[4]; | 91 | unsigned char ip[4]; |
91 | STRUCT_HTTP_FLAG flag; | 92 | STRUCT_HTTP_FLAG flag; |
92 | }; | 93 | }; |
93 | #define NOTBLESSED( h ) byte_diff( &h->ip, 4, g_adminip ) | 94 | #define NOTBLESSED( h ) (!bsearch( &h->ip, g_adminip_addresses, g_adminip_count, 4, ot_ip_compare )) |
95 | static int ot_ip_compare( const void *a, const void *b ) { return memcmp( a,b,4 ); } | ||
94 | 96 | ||
95 | /* Prototypes */ | 97 | /* Prototypes */ |
96 | 98 | ||
@@ -954,7 +956,6 @@ int main( int argc, char **argv ) { | |||
954 | "h" ) ) { | 956 | "h" ) ) { |
955 | case -1 : scanon = 0; break; | 957 | case -1 : scanon = 0; break; |
956 | case 'i': scan_ip4( optarg, serverip ); break; | 958 | case 'i': scan_ip4( optarg, serverip ); break; |
957 | case 'A': scan_ip4( optarg, g_adminip ); break; | ||
958 | #ifdef WANT_BLACKLISTING | 959 | #ifdef WANT_BLACKLISTING |
959 | case 'b': accesslist_filename = optarg; break; | 960 | case 'b': accesslist_filename = optarg; break; |
960 | #elif defined( WANT_CLOSED_TRACKER ) | 961 | #elif defined( WANT_CLOSED_TRACKER ) |
@@ -963,12 +964,19 @@ int main( int argc, char **argv ) { | |||
963 | case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break; | 964 | case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break; |
964 | case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break; | 965 | case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break; |
965 | case 'd': serverdir = optarg; break; | 966 | case 'd': serverdir = optarg; break; |
967 | case 'A': | ||
968 | if( g_adminip_count < OT_ADMINIP_MAX ) | ||
969 | scan_ip4( optarg, (char*)(g_adminip_addresses + g_adminip_count++) ); | ||
970 | break; | ||
966 | case 'h': help( argv[0] ); exit( 0 ); | 971 | case 'h': help( argv[0] ); exit( 0 ); |
967 | default: | 972 | default: |
968 | case '?': usage( argv[0] ); exit( 1 ); | 973 | case '?': usage( argv[0] ); exit( 1 ); |
969 | } | 974 | } |
970 | } | 975 | } |
971 | 976 | ||
977 | /* Sort our admin ips for quick lookup */ | ||
978 | qsort( g_adminip_addresses, g_adminip_count, 4, ot_ip_compare ); | ||
979 | |||
972 | /* Bind to our default tcp/udp ports */ | 980 | /* Bind to our default tcp/udp ports */ |
973 | if( !ot_sockets_count ) { | 981 | if( !ot_sockets_count ) { |
974 | ot_try_bind( serverip, 6969, 1 ); | 982 | ot_try_bind( serverip, 6969, 1 ); |
diff --git a/trackerlogic.h b/trackerlogic.h index ccd3465..9cbffc1 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -42,6 +42,9 @@ typedef struct { | |||
42 | 42 | ||
43 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) | 43 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) |
44 | 44 | ||
45 | /* Number of tracker admin ip addresses allowed */ | ||
46 | #define OT_ADMINIP_MAX 64 | ||
47 | |||
45 | /* We maintain a list of 4096 pointers to sorted list of ot_torrent structs | 48 | /* We maintain a list of 4096 pointers to sorted list of ot_torrent structs |
46 | Sort key is, of course, its hash */ | 49 | Sort key is, of course, its hash */ |
47 | #define OT_BUCKET_COUNT 1024 | 50 | #define OT_BUCKET_COUNT 1024 |