diff options
Diffstat (limited to 'ot_http.c')
| -rw-r--r-- | ot_http.c | 24 |
1 files changed, 12 insertions, 12 deletions
| @@ -25,8 +25,8 @@ | |||
| 25 | #include "ot_ip.h" | 25 | #include "ot_ip.h" |
| 26 | #include "ot_mutex.h" | 26 | #include "ot_mutex.h" |
| 27 | #include "ot_scan.h" | 27 | #include "ot_scan.h" |
| 28 | #include "ot_fdstate.h" | ||
| 28 | #include "ot_stats.h" | 29 | #include "ot_stats.h" |
| 29 | #include "ot_timeout.h" | ||
| 30 | #include "scan_urlencoded_query.h" | 30 | #include "scan_urlencoded_query.h" |
| 31 | #include "trackerlogic.h" | 31 | #include "trackerlogic.h" |
| 32 | 32 | ||
| @@ -39,7 +39,7 @@ ssize_t g_stats_path_len; | |||
| 39 | enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; | 39 | enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; |
| 40 | 40 | ||
| 41 | static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { | 41 | static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { |
| 42 | struct http_data *cookie = io_getcookie(sock); | 42 | struct http_data *cookie = fdstate_cookie(sock); |
| 43 | ssize_t written_size; | 43 | ssize_t written_size; |
| 44 | 44 | ||
| 45 | if (!cookie) { | 45 | if (!cookie) { |
| @@ -97,7 +97,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { | |||
| 97 | 97 | ||
| 98 | /* writeable short data sockets just have a tcp timeout */ | 98 | /* writeable short data sockets just have a tcp timeout */ |
| 99 | if (!ws->keep_alive) { | 99 | if (!ws->keep_alive) { |
| 100 | timeout_never(sock); | 100 | fdstate_set_expiry(sock, 0); |
| 101 | io_dontwantread(sock); | 101 | io_dontwantread(sock); |
| 102 | } | 102 | } |
| 103 | io_wantwrite(sock); | 103 | io_wantwrite(sock); |
| @@ -134,7 +134,7 @@ ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) | |||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial) { | 136 | ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial) { |
| 137 | struct http_data *cookie = io_getcookie(sock); | 137 | struct http_data *cookie = fdstate_cookie(sock); |
| 138 | char *header; | 138 | char *header; |
| 139 | const char *encoding = ""; | 139 | const char *encoding = ""; |
| 140 | size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); | 140 | size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); |
| @@ -207,7 +207,7 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t | |||
| 207 | cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; | 207 | cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | timeout_in(sock, OT_CLIENT_TIMEOUT_SEND); | 210 | fdstate_set_expiry(sock, g_now_seconds + OT_CLIENT_TIMEOUT_SEND); |
| 211 | io_wantwrite(sock); | 211 | io_wantwrite(sock); |
| 212 | return 0; | 212 | return 0; |
| 213 | } | 213 | } |
| @@ -243,7 +243,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c | |||
| 243 | {"url", TASK_FULLSCRAPE_TPB_URLENCODED}, {"txt", TASK_FULLSCRAPE_TPB_ASCII}, | 243 | {"url", TASK_FULLSCRAPE_TPB_URLENCODED}, {"txt", TASK_FULLSCRAPE_TPB_ASCII}, |
| 244 | {"txtp", TASK_FULLSCRAPE_TPB_ASCII_PLUS}, {NULL, -3}}; | 244 | {"txtp", TASK_FULLSCRAPE_TPB_ASCII_PLUS}, {NULL, -3}}; |
| 245 | 245 | ||
| 246 | struct http_data *cookie = io_getcookie(sock); | 246 | struct http_data *cookie = fdstate_cookie(sock); |
| 247 | int mode = TASK_STATS_PEERS, scanon = 1, format = 0; | 247 | int mode = TASK_STATS_PEERS, scanon = 1, format = 0; |
| 248 | 248 | ||
| 249 | /* A socket without one is a dead socket, which is what http_sendiovecdata | 249 | /* A socket without one is a dead socket, which is what http_sendiovecdata |
| @@ -301,7 +301,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c | |||
| 301 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; | 301 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; |
| 302 | 302 | ||
| 303 | /* Clients waiting for us should not easily timeout */ | 303 | /* Clients waiting for us should not easily timeout */ |
| 304 | timeout_never(sock); | 304 | fdstate_set_expiry(sock, 0); |
| 305 | fullscrape_deliver(sock, format); | 305 | fullscrape_deliver(sock, format); |
| 306 | io_dontwantread(sock); | 306 | io_dontwantread(sock); |
| 307 | return ws->reply_size = -2; | 307 | return ws->reply_size = -2; |
| @@ -314,7 +314,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c | |||
| 314 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | 314 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; |
| 315 | 315 | ||
| 316 | /* Complex stats also include expensive memory debugging tools */ | 316 | /* Complex stats also include expensive memory debugging tools */ |
| 317 | timeout_never(sock); | 317 | fdstate_set_expiry(sock, 0); |
| 318 | stats_deliver(sock, mode); | 318 | stats_deliver(sock, mode); |
| 319 | return ws->reply_size = -2; | 319 | return ws->reply_size = -2; |
| 320 | } | 320 | } |
| @@ -334,7 +334,7 @@ typedef struct { | |||
| 334 | 334 | ||
| 335 | #ifdef WANT_FULLSCRAPE | 335 | #ifdef WANT_FULLSCRAPE |
| 336 | static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct *ws) { | 336 | static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct *ws) { |
| 337 | struct http_data *cookie = io_getcookie(sock); | 337 | struct http_data *cookie = fdstate_cookie(sock); |
| 338 | int format = 0; | 338 | int format = 0; |
| 339 | 339 | ||
| 340 | #ifdef WANT_MODEST_FULLSCRAPES | 340 | #ifdef WANT_MODEST_FULLSCRAPES |
| @@ -394,7 +394,7 @@ static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct * | |||
| 394 | /* Pass this task to the worker thread */ | 394 | /* Pass this task to the worker thread */ |
| 395 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; | 395 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; |
| 396 | /* Clients waiting for us should not easily timeout */ | 396 | /* Clients waiting for us should not easily timeout */ |
| 397 | timeout_never(sock); | 397 | fdstate_set_expiry(sock, 0); |
| 398 | fullscrape_deliver(sock, format); | 398 | fullscrape_deliver(sock, format); |
| 399 | io_dontwantread(sock); | 399 | io_dontwantread(sock); |
| 400 | return ws->reply_size = -2; | 400 | return ws->reply_size = -2; |
| @@ -486,7 +486,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct | |||
| 486 | unsigned short port = 0; | 486 | unsigned short port = 0; |
| 487 | char *write_ptr; | 487 | char *write_ptr; |
| 488 | ssize_t len; | 488 | ssize_t len; |
| 489 | struct http_data *cookie = io_getcookie(sock); | 489 | struct http_data *cookie = fdstate_cookie(sock); |
| 490 | 490 | ||
| 491 | /* This is to hack around stupid clients that send "announce ?info_hash" */ | 491 | /* This is to hack around stupid clients that send "announce ?info_hash" */ |
| 492 | if (read_ptr[-1] != '?') { | 492 | if (read_ptr[-1] != '?') { |
| @@ -663,7 +663,7 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) { | |||
| 663 | char *read_ptr = ws->request, *write_ptr; | 663 | char *read_ptr = ws->request, *write_ptr; |
| 664 | 664 | ||
| 665 | #ifdef WANT_FULLLOG_NETWORKS | 665 | #ifdef WANT_FULLLOG_NETWORKS |
| 666 | struct http_data *cookie = io_getcookie(sock); | 666 | struct http_data *cookie = fdstate_cookie(sock); |
| 667 | if (loglist_check_address(cookie->ip)) { | 667 | if (loglist_check_address(cookie->ip)) { |
| 668 | ot_log *log = malloc(sizeof(ot_log)); | 668 | ot_log *log = malloc(sizeof(ot_log)); |
| 669 | if (log) { | 669 | if (log) { |
