Fixed mem leak, inmplemented mrtg_scrape

dynamic-accesslists
erdgeist 18 years ago
parent 25e63d93d2
commit af147a1d14

@ -19,6 +19,8 @@
#include "trackerlogic.h" #include "trackerlogic.h"
#include "scan_urlencoded_query.h" #include "scan_urlencoded_query.h"
static unsigned int overall_connections = 0;
static void carp(const char* routine) { static void carp(const char* routine) {
buffer_puts(buffer_2,routine); buffer_puts(buffer_2,routine);
buffer_puts(buffer_2,": "); buffer_puts(buffer_2,": ");
@ -279,7 +281,13 @@ e500:
} }
} }
break; break;
default: /* neither scrape nor announce */ case 11:
if( byte_diff(data,11,",mrtg_scrape"))
goto e404;
reply = malloc( 128 );
reply_size = sprintf( reply, "%d\n%d\nUp: 23 years.\nPertuned by german engineers.", overall_connections, overall_connections );
break;
default: /* neither *scrape nor announce */
e404: e404:
httperror(h,"404 Not Found","No such file or directory."); httperror(h,"404 Not Found","No such file or directory.");
goto bailout; goto bailout;
@ -293,7 +301,7 @@ e404:
c+=fmt_httpdate(c,time(0)); c+=fmt_httpdate(c,time(0));
c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); c+=fmt_str(c,"\r\nConnection: close\r\n\r\n");
iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf);
if( reply && reply_size ) iob_addbuf(&h->iob,reply, reply_size ); if( reply && reply_size ) iob_addbuf_free(&h->iob,reply, reply_size );
bailout: bailout:
io_dontwantread(s); io_dontwantread(s);
@ -351,6 +359,7 @@ int main()
byte_zero(h,sizeof(struct http_data)); byte_zero(h,sizeof(struct http_data));
h->ip=ip; h->ip=ip;
io_setcookie(n,h); io_setcookie(n,h);
++overall_connections;
} else } else
io_close(n); io_close(n);
} else } else

@ -210,6 +210,10 @@ size_t return_peers_for_torrent( ot_torrent *torrent, unsigned long amount, char
off = 1 + ( off % ( peer_count - wert - 1 )); off = 1 + ( off % ( peer_count - wert - 1 ));
wert += off; pool_offset += off; wert += off; pool_offset += off;
// In some rare occasions random gets the last peer a round to early
// correct that and return last peer twice
if( wert >= peer_count ) { wert--; pool_offset--; }
while( pool_offset >= torrent->peer_list->peers[pool_index].size ) { while( pool_offset >= torrent->peer_list->peers[pool_index].size ) {
pool_offset -= torrent->peer_list->peers[pool_index].size; pool_offset -= torrent->peer_list->peers[pool_index].size;
pool_index++; pool_index++;

Loading…
Cancel
Save