summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2006-12-13 02:44:39 +0000
committererdgeist <>2006-12-13 02:44:39 +0000
commitd7c26dc71bd3cc04824ad979d31c1386dd5b1fa3 (patch)
tree53a381164f1d1ccfc1ae048db077799c595bd837
parent31c20c515d96c7311aa3483287202a48dd39cefb (diff)
Trackerlogic done... not tested yet
-rw-r--r--Makefile4
-rw-r--r--trackerlogic.c17
-rw-r--r--trackerlogic.h2
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 @@
1CC?=gcc 1CC?=gcc
2CFLAGS+=-I../libowfat -Wall -pipe -g -ggdb 2CFLAGS+=-I../libowfat -Wall -pipe -O2
3LDFLAGS+=-L../libowfat/ -lowfat 3LDFLAGS+=-L../libowfat/ -lowfat -s
4 4
5SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c 5SOURCES=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
112void clean_peerlist( ot_peerlist peer_list ) { 112void 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
116ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ) { 131ot_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
35typedef struct ot_vector { 35typedef struct ot_vector {
36 void *data; 36 void *data;