From 9297967f8523f1ac22bbac1823529b970a07cf56 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 4 Mar 2009 14:35:21 +0000 Subject: Add a stat option the count bucket stalls Add an iterator for all torrents. It's slower but for stats it's okay. Move some stats collection stuff to the new iterator. More to come. Start a "report all stats" page. Start fixing the code to identify "busy" networks. Add the concept of hosts allowed to proxy. Add a parser for the X-Forwarded-For: HTTP header. Clean up HTTP Header handling code. (Remove some left overs of now vanished sync code). --- ot_http.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index 971d81d..de57dad 100644 --- a/ot_http.c +++ b/ot_http.c @@ -306,13 +306,14 @@ static ot_keywords keywords_announce[] = { { "port", 1 }, { "left", 2 }, { "even { NULL, -3 } }; static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } }; static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) { - int numwant, tmp, scanon; - ot_peer peer; - ot_hash *hash = NULL; - unsigned short port = htons(6881); - char *write_ptr; - ssize_t len; - + int numwant, tmp, scanon; + ot_peer peer; + ot_hash *hash = NULL; + unsigned short port = htons(6881); + char *write_ptr; + ssize_t len; + struct http_data *cookie = io_getcookie( sock ); + /* This is to hack around stupid clients that send "announce ?info_hash" */ if( read_ptr[-1] != '?' ) { while( ( *read_ptr != '?' ) && ( *read_ptr != '\n' ) ) ++read_ptr; @@ -320,7 +321,33 @@ static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, ++read_ptr; } - OT_SETIP( &peer, ((struct http_data*)io_getcookie( sock ) )->ip ); +#ifdef WANT_IP_FROM_PROXY + if( accesslist_isblessed( cookie->ip, OT_PERMISSION_MAY_PROXY ) ) { + ot_ip6 proxied_ip; + char *fwd, *fwd_new = ws->request; + + /* Zero terminate for string routines. Normally we'd only overwrite bollocks */ + ws->request[ws->request_size-1] = 0; + + /* Find last occurence of the forwarded header */ + do { + fwd = fwd_new; + fwd_new = strcasestr( fwd_new, "\nX-Forwarded-For:" ); + } while( fwd_new ); + + /* Skip spaces between : and the ip address */ + if( fwd ) { + fwd += 18; /* sizeof( "\nX-Forwarded-For:" ) */ + while( *fwd == ' ' ) ++fwd; + } + + if( fwd && scan_ip6( fwd, proxied_ip ) ) + OT_SETIP( &peer, proxied_ip ); + else + OT_SETIP( &peer, cookie->ip ); + } +#endif + OT_SETIP( &peer, cookie->ip ); OT_SETPORT( &peer, &port ); OT_PEERFLAG( &peer ) = 0; numwant = 50; -- cgit v1.2.3