diff --git a/opentracker.c b/opentracker.c index 35482e4..1bd8514 100644 --- a/opentracker.c +++ b/opentracker.c @@ -19,6 +19,8 @@ #include "trackerlogic.h" #include "scan_urlencoded_query.h" +static unsigned int overall_connections = 0; + static void carp(const char* routine) { buffer_puts(buffer_2,routine); buffer_puts(buffer_2,": "); @@ -279,7 +281,13 @@ e500: } } 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: httperror(h,"404 Not Found","No such file or directory."); goto bailout; @@ -293,7 +301,7 @@ e404: c+=fmt_httpdate(c,time(0)); c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); 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: io_dontwantread(s); @@ -351,6 +359,7 @@ int main() byte_zero(h,sizeof(struct http_data)); h->ip=ip; io_setcookie(n,h); + ++overall_connections; } else io_close(n); } 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 off = 1 + ( off % ( peer_count - wert - 1 )); 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 ) { pool_offset -= torrent->peer_list->peers[pool_index].size; pool_index++;