diff options
author | erdgeist <> | 2009-03-04 14:35:21 +0000 |
---|---|---|
committer | erdgeist <> | 2009-03-04 14:35:21 +0000 |
commit | 9297967f8523f1ac22bbac1823529b970a07cf56 (patch) | |
tree | 0a6bc2a2d3ac9d38e53079040c7057c779e30f15 /ot_http.c | |
parent | 72a1564ca14392cc2e1d044554c6e86a0eda9409 (diff) |
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).
Diffstat (limited to 'ot_http.c')
-rw-r--r-- | ot_http.c | 43 |
1 files changed, 35 insertions, 8 deletions
@@ -306,13 +306,14 @@ static ot_keywords keywords_announce[] = { { "port", 1 }, { "left", 2 }, { "even | |||
306 | { NULL, -3 } }; | 306 | { NULL, -3 } }; |
307 | static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } }; | 307 | static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } }; |
308 | static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) { | 308 | static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) { |
309 | int numwant, tmp, scanon; | 309 | int numwant, tmp, scanon; |
310 | ot_peer peer; | 310 | ot_peer peer; |
311 | ot_hash *hash = NULL; | 311 | ot_hash *hash = NULL; |
312 | unsigned short port = htons(6881); | 312 | unsigned short port = htons(6881); |
313 | char *write_ptr; | 313 | char *write_ptr; |
314 | ssize_t len; | 314 | ssize_t len; |
315 | 315 | struct http_data *cookie = io_getcookie( sock ); | |
316 | |||
316 | /* This is to hack around stupid clients that send "announce ?info_hash" */ | 317 | /* This is to hack around stupid clients that send "announce ?info_hash" */ |
317 | if( read_ptr[-1] != '?' ) { | 318 | if( read_ptr[-1] != '?' ) { |
318 | while( ( *read_ptr != '?' ) && ( *read_ptr != '\n' ) ) ++read_ptr; | 319 | 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, | |||
320 | ++read_ptr; | 321 | ++read_ptr; |
321 | } | 322 | } |
322 | 323 | ||
323 | OT_SETIP( &peer, ((struct http_data*)io_getcookie( sock ) )->ip ); | 324 | #ifdef WANT_IP_FROM_PROXY |
325 | if( accesslist_isblessed( cookie->ip, OT_PERMISSION_MAY_PROXY ) ) { | ||
326 | ot_ip6 proxied_ip; | ||
327 | char *fwd, *fwd_new = ws->request; | ||
328 | |||
329 | /* Zero terminate for string routines. Normally we'd only overwrite bollocks */ | ||
330 | ws->request[ws->request_size-1] = 0; | ||
331 | |||
332 | /* Find last occurence of the forwarded header */ | ||
333 | do { | ||
334 | fwd = fwd_new; | ||
335 | fwd_new = strcasestr( fwd_new, "\nX-Forwarded-For:" ); | ||
336 | } while( fwd_new ); | ||
337 | |||
338 | /* Skip spaces between : and the ip address */ | ||
339 | if( fwd ) { | ||
340 | fwd += 18; /* sizeof( "\nX-Forwarded-For:" ) */ | ||
341 | while( *fwd == ' ' ) ++fwd; | ||
342 | } | ||
343 | |||
344 | if( fwd && scan_ip6( fwd, proxied_ip ) ) | ||
345 | OT_SETIP( &peer, proxied_ip ); | ||
346 | else | ||
347 | OT_SETIP( &peer, cookie->ip ); | ||
348 | } | ||
349 | #endif | ||
350 | OT_SETIP( &peer, cookie->ip ); | ||
324 | OT_SETPORT( &peer, &port ); | 351 | OT_SETPORT( &peer, &port ); |
325 | OT_PEERFLAG( &peer ) = 0; | 352 | OT_PEERFLAG( &peer ) = 0; |
326 | numwant = 50; | 353 | numwant = 50; |