diff options
| author | erdgeist <> | 2006-12-15 22:07:33 +0000 |
|---|---|---|
| committer | erdgeist <> | 2006-12-15 22:07:33 +0000 |
| commit | af147a1d147ce79636656b1b835230be29b6c3b9 (patch) | |
| tree | 0b6ab9a874e50abaa3fdfc649a1b1ba0eb04e68d | |
| parent | 25e63d93d2d48d49799ec66f571b0457a3bd4345 (diff) | |
Fixed mem leak, inmplemented mrtg_scrape
| -rw-r--r-- | opentracker.c | 13 | ||||
| -rw-r--r-- | trackerlogic.c | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/opentracker.c b/opentracker.c index 35482e4..1bd8514 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -19,6 +19,8 @@ | |||
| 19 | #include "trackerlogic.h" | 19 | #include "trackerlogic.h" |
| 20 | #include "scan_urlencoded_query.h" | 20 | #include "scan_urlencoded_query.h" |
| 21 | 21 | ||
| 22 | static unsigned int overall_connections = 0; | ||
| 23 | |||
| 22 | static void carp(const char* routine) { | 24 | static void carp(const char* routine) { |
| 23 | buffer_puts(buffer_2,routine); | 25 | buffer_puts(buffer_2,routine); |
| 24 | buffer_puts(buffer_2,": "); | 26 | buffer_puts(buffer_2,": "); |
| @@ -279,7 +281,13 @@ e500: | |||
| 279 | } | 281 | } |
| 280 | } | 282 | } |
| 281 | break; | 283 | break; |
| 282 | default: /* neither scrape nor announce */ | 284 | case 11: |
| 285 | if( byte_diff(data,11,",mrtg_scrape")) | ||
| 286 | goto e404; | ||
| 287 | reply = malloc( 128 ); | ||
| 288 | reply_size = sprintf( reply, "%d\n%d\nUp: 23 years.\nPertuned by german engineers.", overall_connections, overall_connections ); | ||
| 289 | break; | ||
| 290 | default: /* neither *scrape nor announce */ | ||
| 283 | e404: | 291 | e404: |
| 284 | httperror(h,"404 Not Found","No such file or directory."); | 292 | httperror(h,"404 Not Found","No such file or directory."); |
| 285 | goto bailout; | 293 | goto bailout; |
| @@ -293,7 +301,7 @@ e404: | |||
| 293 | c+=fmt_httpdate(c,time(0)); | 301 | c+=fmt_httpdate(c,time(0)); |
| 294 | c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); | 302 | c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); |
| 295 | iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); | 303 | iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); |
| 296 | if( reply && reply_size ) iob_addbuf(&h->iob,reply, reply_size ); | 304 | if( reply && reply_size ) iob_addbuf_free(&h->iob,reply, reply_size ); |
| 297 | 305 | ||
| 298 | bailout: | 306 | bailout: |
| 299 | io_dontwantread(s); | 307 | io_dontwantread(s); |
| @@ -351,6 +359,7 @@ int main() | |||
| 351 | byte_zero(h,sizeof(struct http_data)); | 359 | byte_zero(h,sizeof(struct http_data)); |
| 352 | h->ip=ip; | 360 | h->ip=ip; |
| 353 | io_setcookie(n,h); | 361 | io_setcookie(n,h); |
| 362 | ++overall_connections; | ||
| 354 | } else | 363 | } else |
| 355 | io_close(n); | 364 | io_close(n); |
| 356 | } else | 365 | } else |
diff --git a/trackerlogic.c b/trackerlogic.c index 7b5b94a..b9f14f0 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
| @@ -210,6 +210,10 @@ size_t return_peers_for_torrent( ot_torrent *torrent, unsigned long amount, char | |||
| 210 | off = 1 + ( off % ( peer_count - wert - 1 )); | 210 | off = 1 + ( off % ( peer_count - wert - 1 )); |
| 211 | wert += off; pool_offset += off; | 211 | wert += off; pool_offset += off; |
| 212 | 212 | ||
| 213 | // In some rare occasions random gets the last peer a round to early | ||
| 214 | // correct that and return last peer twice | ||
| 215 | if( wert >= peer_count ) { wert--; pool_offset--; } | ||
| 216 | |||
| 213 | while( pool_offset >= torrent->peer_list->peers[pool_index].size ) { | 217 | while( pool_offset >= torrent->peer_list->peers[pool_index].size ) { |
| 214 | pool_offset -= torrent->peer_list->peers[pool_index].size; | 218 | pool_offset -= torrent->peer_list->peers[pool_index].size; |
| 215 | pool_index++; | 219 | pool_index++; |
