From d7c26dc71bd3cc04824ad979d31c1386dd5b1fa3 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 13 Dec 2006 02:44:39 +0000 Subject: Trackerlogic done... not tested yet --- Makefile | 4 ++-- trackerlogic.c | 17 ++++++++++++++++- trackerlogic.h | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2aaf91d..21689e5 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC?=gcc -CFLAGS+=-I../libowfat -Wall -pipe -g -ggdb -LDFLAGS+=-L../libowfat/ -lowfat +CFLAGS+=-I../libowfat -Wall -pipe -O2 +LDFLAGS+=-L../libowfat/ -lowfat -s SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c diff --git a/trackerlogic.c b/trackerlogic.c index c57d1a9..5d83abb 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -110,7 +110,22 @@ int vector_remove_torrent( ot_vector vector, ot_hash *hash ) { } void clean_peerlist( ot_peerlist peer_list ) { - exit( 1 ); + long timedout = NOW-peer_list->base; + int i; + + if( !timedout ) return; + if( timedout > OT_POOLS_COUNT ) timedout = OT_POOLS_COUNT; + + for( i=OT_POOLS_COUNT-timedout; ipeers[i].data); + + MEMMOVE( peer_list->peers + timedout, peer_list->peers, sizeof( ot_vector ) * (OT_POOLS_COUNT-timedout) ); + byte_zero( peer_list->peers, sizeof( ot_vector ) * timedout ); + + MEMMOVE( peer_list->seed_count + timedout, peer_list->seed_count, sizeof( unsigned long ) * (OT_POOLS_COUNT-timedout) ); + byte_zero( peer_list->seed_count, sizeof( unsigned long ) * timedout ); + + peer_list->base = NOW; } ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ) { diff --git a/trackerlogic.h b/trackerlogic.h index 73f5d16..3243eb7 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -20,7 +20,6 @@ typedef time_t ot_time; #define FORMAT_FIXED_STRING sprintf #define FORMAT_FORMAT_STRING sprintf #define BINARY_FIND binary_search -#define NOW time(NULL) // We maintain a list of 256 pointers to sorted list of ot_torrent structs // Sort key is, of course, its hash @@ -31,6 +30,7 @@ typedef time_t ot_time; #define OT_POOLS_COUNT 9 #define OT_POOLS_TIMEOUT 300 +#define NOW (time(NULL)/OT_POOLS_TIMEOUT) typedef struct ot_vector { void *data; -- cgit v1.2.3