Browse Source

New Makefile, incorporated some patches sent to me by Robin H. Johnson

dynamic-accesslists
erdgeist 18 years ago
parent
commit
5c18293c9c
  1. 40
      Makefile
  2. 23
      opentracker.c
  3. 2
      scan_urlencoded_query.c
  4. 19
      trackerlogic.c

40
Makefile

@ -1,15 +1,37 @@ @@ -1,15 +1,37 @@
CC?=gcc
FEATURES=#-DWANT_IP_FROM_QUERY_STRING -DWANT_BLACKLIST -DWANT_CLOSED_TRACKER -D_DEBUG_HTTPERROR
#DEBUG_OPTS=-g -ggdb -pg # -fprofile-arcs -ftest-coverage
DEBUG_OPTS=-s -Os
CFLAGS+=-I../libowfat -Wall -pipe# -pedantic -ansi
FEATURES=#-DWANT_IP_FROM_QUERY_STRING -D_DEBUG_HTTPERROR
OPTS_debug=-g -ggdb #-pg # -fprofile-arcs -ftest-coverage
OPTS_production=-s -Os
CFLAGS+=-I../libowfat -Wall -pipe -Wextra #-pedantic #-ansi
LDFLAGS+=-L../libowfat/ -lowfat
BINARY = opentracker
HEADERS=trackerlogic.h scan_urlencoded_query.h
SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c
all: $(BINARY) $(BINARY).debug
CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES)
CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES)
OBJECTS_debug = $(SOURCES:%.c=%.debug.o)
OBJECTS_production = $(SOURCES:%.c=%.production.o)
$(OBJECTS_debug) $(OBJECTS_production): $(HEADERS)
%.production.o : CFLAGS := $(CFLAGS_production)
%.debug.o : CFLAGS := $(CFLAGS_debug)
opentracker: $(SOURCES) $(HEADERS)
$(CC) $(SOURCES) -o opentracker $(CFLAGS) $(FEATURES) $(DEBUG_OPTS) $(LDFLAGS)
%.production.o : %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
%.debug.o : %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
clean:
rm -rf opentracker
$(BINARY): $(OBJECTS_production)
$(CC) $^ -o $@ $(CFLAGS_production) $(LDFLAGS)
$(BINARY).debug: $(OBJECTS_debug)
$(CC) $^ -o $@ $(CFLAGS_debug) $(LDFLAGS)
clean:
rm -rf opentracker *.o *~

23
opentracker.c

@ -154,7 +154,7 @@ static void senddata( const int64 s, char *buffer, size_t size ) { @@ -154,7 +154,7 @@ static void senddata( const int64 s, char *buffer, size_t size ) {
array_reset( &h->request );
written_size = write( s, buffer, size );
if( ( written_size < 0 ) || ( written_size == size ) ) {
if( ( written_size < 0 ) || ( (size_t)written_size == size ) ) {
free( h ); io_close( s );
} else {
char * outbuf = malloc( size - written_size );
@ -594,15 +594,15 @@ static void handle_timeouted( void ) { @@ -594,15 +594,15 @@ static void handle_timeouted( void ) {
}
static void handle_udp4( int64 serversocket ) {
ot_peer peer;
ot_torrent *torrent;
ot_hash *hash = NULL;
char remoteip[4];
unsigned long *inpacket = (unsigned long*)static_inbuf;
unsigned long *outpacket = (unsigned long*)static_outbuf;
unsigned long numwant, left, event;
uint16 port, remoteport;
size_t r, r_out;
ot_peer peer;
ot_torrent *torrent;
ot_hash *hash = NULL;
char remoteip[4];
ot_dword *inpacket = (ot_dword*)static_inbuf;
ot_dword *outpacket = (ot_dword*)static_outbuf;
ot_dword numwant, left, event;
ot_word port, remoteport;
size_t r, r_out;
r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport);
@ -627,8 +627,9 @@ static void handle_udp4( int64 serversocket ) { @@ -627,8 +627,9 @@ static void handle_udp4( int64 serversocket ) {
numwant = 200;
/* We do only want to know, if it is zero */
left = inpacket[64/4] | inpacket[68/4];
event = ntohl( inpacket[80/4] );
port = *(unsigned short*)( static_inbuf + 96 );
port = *(ot_word*)( static_inbuf + 96 );
hash = (ot_hash*)( static_inbuf + 16 );
OT_SETIP( &peer, remoteip );

2
scan_urlencoded_query.c

@ -73,7 +73,7 @@ ssize_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] ) { @@ -73,7 +73,7 @@ ssize_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] ) {
for( i=0; i<4; ++i ) {
ssize_t j = scan_fixed_int( data, len, &u );
if( j == len ) return len;
if( j == (ssize_t)len ) return len;
ip[i] = u;
data += len - j;
len = j;

19
trackerlogic.c

@ -243,9 +243,9 @@ size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply @@ -243,9 +243,9 @@ size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply
if( is_tcp )
r += sprintf( r, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers%zd:", seed_count, peer_count-seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM, 6*amount );
else {
*(unsigned long*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
*(unsigned long*)(r+4) = htonl( peer_count );
*(unsigned long*)(r+8) = htonl( seed_count );
*(ot_dword*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
*(ot_dword*)(r+4) = htonl( peer_count );
*(ot_dword*)(r+8) = htonl( seed_count );
r += 12;
}
@ -357,7 +357,7 @@ size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) { @@ -357,7 +357,7 @@ size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) {
if( !exactmatch ) {
memset( reply, 0, 12);
} else {
unsigned long *r = (unsigned long*) reply;
ot_dword *r = (ot_dword*) reply;
for( i=0; i<OT_POOLS_COUNT; ++i ) {
peers += torrent->peer_list->peers[i].size;
@ -394,7 +394,7 @@ size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ) { @@ -394,7 +394,7 @@ size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ) {
/* Throw away old changeset */
static void release_changeset( void ) {
ot_byte **changeset_ptrs = (ot_byte**)(changeset.data);
int i;
size_t i;
for( i = 0; i < changeset.size; ++i )
free( changeset_ptrs[i] );
@ -507,7 +507,8 @@ size_t return_changeset_for_tracker( char **reply ) { @@ -507,7 +507,8 @@ size_t return_changeset_for_tracker( char **reply ) {
/* Clean up all torrents, remove timedout pools and
torrents, also prepare new changeset */
void clean_all_torrents( void ) {
int i, j, k;
int i, k;
size_t j;
time_t time_now = NOW;
size_t peers_count;
@ -566,7 +567,7 @@ void clean_all_torrents( void ) { @@ -566,7 +567,7 @@ void clean_all_torrents( void ) {
}
}
typedef struct { int val; ot_torrent * torrent; } ot_record;
typedef struct { size_t val; ot_torrent * torrent; } ot_record;
/* Fetches stats from tracker */
size_t return_stats_for_tracker( char *reply, int mode ) {
@ -611,11 +612,11 @@ size_t return_stats_for_tracker( char *reply, int mode ) { @@ -611,11 +612,11 @@ size_t return_stats_for_tracker( char *reply, int mode ) {
r += sprintf( r, "Top5 torrents by peers:\n" );
for( idx=0; idx<5; ++idx )
if( top5c[idx].torrent )
r += sprintf( r, "\t%i\t%s\n", top5c[idx].val, to_hex(top5c[idx].torrent->hash) );
r += sprintf( r, "\t%zd\t%s\n", top5c[idx].val, to_hex(top5c[idx].torrent->hash) );
r += sprintf( r, "Top5 torrents by seeds:\n" );
for( idx=0; idx<5; ++idx )
if( top5s[idx].torrent )
r += sprintf( r, "\t%i\t%s\n", top5s[idx].val, to_hex(top5s[idx].torrent->hash) );
r += sprintf( r, "\t%zd\t%s\n", top5s[idx].val, to_hex(top5s[idx].torrent->hash) );
} else {
r += sprintf( r, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", peer_count, seed_count, torrent_count );
}

Loading…
Cancel
Save