diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | trackerlogic.c | 17 | ||||
-rw-r--r-- | trackerlogic.h | 2 |
3 files changed, 19 insertions, 4 deletions
@@ -1,6 +1,6 @@ | |||
1 | CC?=gcc | 1 | CC?=gcc |
2 | CFLAGS+=-I../libowfat -Wall -pipe -g -ggdb | 2 | CFLAGS+=-I../libowfat -Wall -pipe -O2 |
3 | LDFLAGS+=-L../libowfat/ -lowfat | 3 | LDFLAGS+=-L../libowfat/ -lowfat -s |
4 | 4 | ||
5 | SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c | 5 | SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c |
6 | 6 | ||
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 ) { | |||
110 | } | 110 | } |
111 | 111 | ||
112 | void clean_peerlist( ot_peerlist peer_list ) { | 112 | void clean_peerlist( ot_peerlist peer_list ) { |
113 | exit( 1 ); | 113 | long timedout = NOW-peer_list->base; |
114 | int i; | ||
115 | |||
116 | if( !timedout ) return; | ||
117 | if( timedout > OT_POOLS_COUNT ) timedout = OT_POOLS_COUNT; | ||
118 | |||
119 | for( i=OT_POOLS_COUNT-timedout; i<OT_POOLS_COUNT; ++i ) | ||
120 | free( peer_list->peers[i].data); | ||
121 | |||
122 | MEMMOVE( peer_list->peers + timedout, peer_list->peers, sizeof( ot_vector ) * (OT_POOLS_COUNT-timedout) ); | ||
123 | byte_zero( peer_list->peers, sizeof( ot_vector ) * timedout ); | ||
124 | |||
125 | MEMMOVE( peer_list->seed_count + timedout, peer_list->seed_count, sizeof( unsigned long ) * (OT_POOLS_COUNT-timedout) ); | ||
126 | byte_zero( peer_list->seed_count, sizeof( unsigned long ) * timedout ); | ||
127 | |||
128 | peer_list->base = NOW; | ||
114 | } | 129 | } |
115 | 130 | ||
116 | ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ) { | 131 | 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; | |||
20 | #define FORMAT_FIXED_STRING sprintf | 20 | #define FORMAT_FIXED_STRING sprintf |
21 | #define FORMAT_FORMAT_STRING sprintf | 21 | #define FORMAT_FORMAT_STRING sprintf |
22 | #define BINARY_FIND binary_search | 22 | #define BINARY_FIND binary_search |
23 | #define NOW time(NULL) | ||
24 | 23 | ||
25 | // We maintain a list of 256 pointers to sorted list of ot_torrent structs | 24 | // We maintain a list of 256 pointers to sorted list of ot_torrent structs |
26 | // Sort key is, of course, its hash | 25 | // Sort key is, of course, its hash |
@@ -31,6 +30,7 @@ typedef time_t ot_time; | |||
31 | 30 | ||
32 | #define OT_POOLS_COUNT 9 | 31 | #define OT_POOLS_COUNT 9 |
33 | #define OT_POOLS_TIMEOUT 300 | 32 | #define OT_POOLS_TIMEOUT 300 |
33 | #define NOW (time(NULL)/OT_POOLS_TIMEOUT) | ||
34 | 34 | ||
35 | typedef struct ot_vector { | 35 | typedef struct ot_vector { |
36 | void *data; | 36 | void *data; |