From 175c37c3e89f179a3da82a66b06b931b24a52b98 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Mon, 5 Mar 2007 21:14:50 +0000 Subject: [PATCH] Can now handle multiple ips/ports, can BIND to udp ports but not yet handle them, now checks if event=completed comes with left=0 and drops it, if it doesnt --- opentracker.c | 107 ++++++++++++++++++++++++++++++++++++++++--------- trackerlogic.c | 4 ++ 2 files changed, 91 insertions(+), 20 deletions(-) diff --git a/opentracker.c b/opentracker.c index 090b382..51a5b33 100644 --- a/opentracker.c +++ b/opentracker.c @@ -12,6 +12,8 @@ #include "case.h" #include "fmt.h" #include "str.h" +#include "scan.h" +#include "ip4.h" #include #include #include @@ -38,6 +40,13 @@ static const size_t SUCCESS_HTTP_SIZE_OFF = 17; static char static_inbuf[8192]; static char static_outbuf[8192]; +#define OT_MAXSOCKETS_TCP4 64 +#define OT_MAXSOCKETS_UDP4 64 +static int64 ot_sockets_tcp4[ OT_MAXSOCKETS_TCP4 ]; +static int64 ot_sockets_udp4[ OT_MAXSOCKETS_UDP4 ]; +static int ot_sockets_tcp4_count = 0; +static int ot_sockets_udp4_count = 0; + #ifdef _DEBUG_HTTPERROR static char debug_request[8192]; #endif @@ -60,7 +69,7 @@ static void httpresponse( const int64 s, char *data ); static void sendmallocdata( const int64 s, char *buffer, const size_t size ); static void senddata( const int64 s, char *buffer, const size_t size ); -static void server_mainloop( const int64 serversocket ); +static void server_mainloop( ); static void handle_timeouted( void ); static void handle_accept( const int64 serversocket ); static void handle_read( const int64 clientsocket ); @@ -436,8 +445,9 @@ static void usage( char *name ) { static void help( char *name ) { usage( name ); - fprintf( stderr, "\t-i serverip\tspecify ip to bind to (default: *)\n" - "\t-p serverport\tspecify port to bind to (default: 6969)\n" + fprintf( stderr, "\t-i serverip\tspecify ip to bind to (default: *, you may specify more than one)\n" + "\t-p serverport\tspecify port to bind to (default: 6969, you may specify more than one)\n" + "\t-P serverport\tspecify port to bind to (you may specify more than one)\n" "\t-d serverdir\tspecify directory containing white- or black listed torrent info_hashes (default: \".\")\n" #ifdef WANT_CLOSED_TRACKER "\t-o\t\tmake tracker an open tracker, e.g. do not check for white list (default: off)\n" @@ -456,6 +466,7 @@ static void help( char *name ) { #endif "* To white list a torrent, touch a file inside serverdir with info_hash hex string, preprended by '-'.\n" #endif + "\nExample: ./opentracker -i 127.0.0.1 -p 6968 -P 6968 -i 10.1.1.23 -p 6969 -p 6970\n" ); } @@ -544,10 +555,35 @@ static void handle_timeouted( void ) { } } -static void server_mainloop( const int64 serversocket ) { +void handle_udp4( int64 serversocket ) { + size_t r; + char remoteip[4]; + uint16 port; + + r = socket_recv4(serversocket, static_inbuf, 8192, remoteip, &port); + + // too lazy :) +} + +int ot_in_tcp4_sockets( int64 fd ) { + int i; + for( i=0; ipeer_list ); + /* Sanitize flags: Whoever claims to have completed download, must be a seeder */ + if( ( OT_FLAG( peer ) & ( PEER_FLAG_COMPLETED | PEER_FLAG_SEEDING ) ) == PEER_FLAG_COMPLETED ) + OT_FLAG( peer ) ^= PEER_FLAG_COMPLETED; + peer_pool = &torrent->peer_list->peers[0]; peer_dest = vector_find_or_insert( peer_pool, (void*)peer, sizeof( ot_peer ), OT_PEER_COMPARE_SIZE, &exactmatch );