summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-11-06 18:02:03 +0000
committererdgeist <>2007-11-06 18:02:03 +0000
commit927ac023ce2c761063bbae81bb44b0aab624e36f (patch)
treecdae567406af42f8107daefdec8b762d30c63a13
parentad5fa66737dd77260b881ca673d03b1c171fa7bd (diff)
The expensive DMEM stats is gone. No need for it, too much potential to DOS.
-rw-r--r--Makefile2
-rw-r--r--opentracker.c14
-rw-r--r--ot_stats.c41
-rw-r--r--ot_stats.h4
-rw-r--r--ot_sync.h2
5 files changed, 6 insertions, 57 deletions
diff --git a/Makefile b/Makefile
index 37dd8d3..529eced 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
1CC?=gcc 1CC?=gcc
2FEATURES=#-DWANT_TRACKER_SYNC -DWANT_BLACKLISTING -DWANT_CLOSED_TRACKER -DWANT_UTORRENT1600_WORKAROUND #-DWANT_IP_FROM_QUERY_STRING -D_DEBUG_HTTPERROR 2FEATURES=-DWANT_TRACKER_SYNC #-DWANT_BLACKLISTING -DWANT_CLOSED_TRACKER -DWANT_UTORRENT1600_WORKAROUND #-DWANT_IP_FROM_QUERY_STRING -D_DEBUG_HTTPERROR
3OPTS_debug=-g -ggdb #-pg # -fprofile-arcs -ftest-coverage 3OPTS_debug=-g -ggdb #-pg # -fprofile-arcs -ftest-coverage
4OPTS_production=-Os 4OPTS_production=-Os
5CFLAGS+=-I../libowfat -Wall -pipe -Wextra #-pedantic -ansi 5CFLAGS+=-I../libowfat -Wall -pipe -Wextra #-pedantic -ansi
diff --git a/opentracker.c b/opentracker.c
index 6bde42e..8b440c5 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -325,8 +325,6 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] );
325 mode = STATS_TOP5; 325 mode = STATS_TOP5;
326 else if( !byte_diff(data,4,"fscr")) 326 else if( !byte_diff(data,4,"fscr"))
327 mode = STATS_FULLSCRAPE; 327 mode = STATS_FULLSCRAPE;
328 else if( !byte_diff(data,4,"dmem"))
329 mode = STATS_DMEM;
330 else if( !byte_diff(data,4,"tcp4")) 328 else if( !byte_diff(data,4,"tcp4"))
331 mode = STATS_TCP; 329 mode = STATS_TCP;
332 else if( !byte_diff(data,4,"udp4")) 330 else if( !byte_diff(data,4,"udp4"))
@@ -338,16 +336,8 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] );
338 } 336 }
339 } 337 }
340 338
341 switch( mode) 339 // default format for now
342 { 340 if( !( reply_size = return_stats_for_tracker( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, mode, 0 ) ) ) HTTPERROR_500;
343 case STATS_DMEM:
344 if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500;
345 return sendmmapdata( s, reply, reply_size );
346 default:
347 // default format for now
348 if( !( reply_size = return_stats_for_tracker( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, mode, 0 ) ) ) HTTPERROR_500;
349 break;
350 }
351 break; 341 break;
352 342
353/****************************** 343/******************************
diff --git a/ot_stats.c b/ot_stats.c
index 97e83dd..587155e 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -162,47 +162,6 @@ bailout_cleanup:
162 return 0; 162 return 0;
163} 163}
164 164
165size_t return_memstat_for_tracker( char **reply ) {
166 size_t torrent_count = 0, j;
167 size_t allocated, replysize;
168 ot_vector *torrents_list;
169 int bucket, k;
170 char *r;
171
172 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
173 torrents_list = mutex_bucket_lock(bucket);
174 torrent_count += torrents_list->size;
175 mutex_bucket_unlock(bucket);
176 }
177
178 allocated = OT_BUCKET_COUNT*32 + (43+OT_POOLS_COUNT*32)*torrent_count;
179 if( !( r = *reply = mmap( NULL, allocated, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0 ) ) ) return 0;
180
181 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
182 torrents_list = mutex_bucket_lock(bucket);
183 r += sprintf( r, "%02X: %08X %08X\n", bucket, (unsigned int)torrents_list->size, (unsigned int)torrents_list->space );
184 mutex_bucket_unlock(bucket);
185 }
186
187 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
188 ot_vector *torrents_list = mutex_bucket_lock(bucket);
189 char hex_out[42];
190 for( j=0; j<torrents_list->size; ++j ) {
191 ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
192 ot_hash *hash =&( ((ot_torrent*)(torrents_list->data))[j] ).hash;
193 r += sprintf( r, "\n%s:\n", to_hex( hex_out, (ot_byte*)hash) );
194 for( k=0; k<OT_POOLS_COUNT; ++k )
195 r += sprintf( r, "\t%05X %05X\n", ((unsigned int)peer_list->peers[k].size), (unsigned int)peer_list->peers[k].space );
196 }
197 mutex_bucket_unlock(bucket);
198 }
199
200 replysize = ( r - *reply );
201 fix_mmapallocation( *reply, allocated, replysize );
202
203 return replysize;
204}
205
206static unsigned long events_per_time( unsigned long long events, time_t t ) { 165static unsigned long events_per_time( unsigned long long events, time_t t ) {
207 return events / ( (unsigned int)t ? (unsigned int)t : 1 ); 166 return events / ( (unsigned int)t ? (unsigned int)t : 1 );
208} 167}
diff --git a/ot_stats.h b/ot_stats.h
index 58eec71..a0c2a6b 100644
--- a/ot_stats.h
+++ b/ot_stats.h
@@ -4,7 +4,7 @@
4#ifndef __OT_STATS_H__ 4#ifndef __OT_STATS_H__
5#define __OT_STATS_H__ 5#define __OT_STATS_H__
6 6
7enum { STATS_CONNS, STATS_PEERS, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE }; 7enum { STATS_CONNS, STATS_PEERS, STATS_TOP5, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_FULLSCRAPE };
8typedef enum { 8typedef enum {
9 EVENT_ACCEPT, 9 EVENT_ACCEPT,
10 EVENT_READ, 10 EVENT_READ,
@@ -18,8 +18,6 @@ typedef enum {
18} ot_status_event; 18} ot_status_event;
19 19
20size_t return_stats_for_tracker( char *reply, int mode, int format ); 20size_t return_stats_for_tracker( char *reply, int mode, int format );
21size_t return_memstat_for_tracker( char **reply );
22
23void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); 21void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data );
24 22
25#endif 23#endif
diff --git a/ot_sync.h b/ot_sync.h
index eb9c002..65bf307 100644
--- a/ot_sync.h
+++ b/ot_sync.h
@@ -7,6 +7,8 @@
7#include "trackerlogic.h" 7#include "trackerlogic.h"
8 8
9#ifdef WANT_TRACKER_SYNC 9#ifdef WANT_TRACKER_SYNC
10enum { SYNC_IN, SYNC_OUT };
11
10size_t return_changeset_for_tracker( char **reply ); 12size_t return_changeset_for_tracker( char **reply );
11int add_changeset_to_tracker( ot_byte *data, size_t len ); 13int add_changeset_to_tracker( ot_byte *data, size_t len );
12#endif 14#endif