diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-18 16:49:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-18 16:49:11 +0000 |
commit | df7458695c44a3abd745b239905715f760f16802 (patch) | |
tree | fdd40926542d7ea3fafbb65578d61d9568926762 /src/gns/gnunet-gns-proxy.c | |
parent | f262c1a6cbb0ca79e93617161c5e0f8684ef2d83 (diff) | |
download | gnunet-df7458695c44a3abd745b239905715f760f16802.tar.gz gnunet-df7458695c44a3abd745b239905715f760f16802.zip |
misc bugfixes
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 96 |
1 files changed, 77 insertions, 19 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 0e28ce6fe..95ae88bba 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -665,6 +665,15 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
665 | 665 | ||
666 | 666 | ||
667 | /** | 667 | /** |
668 | * Run MHD now, we have extra data ready for the callback. | ||
669 | * | ||
670 | * @param hd the daemon to run now. | ||
671 | */ | ||
672 | static void | ||
673 | run_mhd_now (struct MhdHttpList *hd); | ||
674 | |||
675 | |||
676 | /** | ||
668 | * Clean up s5r handles. | 677 | * Clean up s5r handles. |
669 | * | 678 | * |
670 | * @param s5r the handle to destroy | 679 | * @param s5r the handle to destroy |
@@ -672,8 +681,12 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
672 | static void | 681 | static void |
673 | cleanup_s5r (struct Socks5Request *s5r) | 682 | cleanup_s5r (struct Socks5Request *s5r) |
674 | { | 683 | { |
684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
685 | "Cleaning up socks request\n"); | ||
675 | if (NULL != s5r->curl) | 686 | if (NULL != s5r->curl) |
676 | { | 687 | { |
688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
689 | "Cleaning up cURL handle\n"); | ||
677 | curl_multi_remove_handle (curl_multi, s5r->curl); | 690 | curl_multi_remove_handle (curl_multi, s5r->curl); |
678 | curl_easy_cleanup (s5r->curl); | 691 | curl_easy_cleanup (s5r->curl); |
679 | s5r->curl = NULL; | 692 | s5r->curl = NULL; |
@@ -706,15 +719,6 @@ cleanup_s5r (struct Socks5Request *s5r) | |||
706 | } | 719 | } |
707 | 720 | ||
708 | 721 | ||
709 | /** | ||
710 | * Run MHD now, we have extra data ready for the callback. | ||
711 | * | ||
712 | * @param hd the daemon to run now. | ||
713 | */ | ||
714 | static void | ||
715 | run_mhd_now (struct MhdHttpList *hd); | ||
716 | |||
717 | |||
718 | /* ************************* HTTP handling with cURL *********************** */ | 722 | /* ************************* HTTP handling with cURL *********************** */ |
719 | 723 | ||
720 | 724 | ||
@@ -744,22 +748,33 @@ mhd_content_cb (void *cls, | |||
744 | /* we're still not done with the upload, do not yet | 748 | /* we're still not done with the upload, do not yet |
745 | start the download, the IO buffer is still full | 749 | start the download, the IO buffer is still full |
746 | with upload data. */ | 750 | with upload data. */ |
751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
752 | "Pausing MHD download, not yet ready for download\n"); | ||
747 | return 0; /* not yet ready for data download */ | 753 | return 0; /* not yet ready for data download */ |
748 | } | 754 | } |
749 | bytes_to_copy = GNUNET_MIN (max, | 755 | bytes_to_copy = GNUNET_MIN (max, |
750 | s5r->io_len); | 756 | s5r->io_len); |
751 | if ( (0 == bytes_to_copy) && | 757 | if ( (0 == bytes_to_copy) && |
752 | (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) ) | 758 | (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) ) |
759 | { | ||
760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
761 | "Pausing MHD download, no data available\n"); | ||
753 | return 0; /* more data later */ | 762 | return 0; /* more data later */ |
763 | } | ||
754 | if ( (0 == bytes_to_copy) && | 764 | if ( (0 == bytes_to_copy) && |
755 | (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) ) | 765 | (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) ) |
766 | { | ||
767 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
768 | "Completed MHD download\n"); | ||
756 | return MHD_CONTENT_READER_END_OF_STREAM; | 769 | return MHD_CONTENT_READER_END_OF_STREAM; |
770 | } | ||
757 | memcpy (buf, s5r->io_buf, bytes_to_copy); | 771 | memcpy (buf, s5r->io_buf, bytes_to_copy); |
758 | memmove (s5r->io_buf, | 772 | memmove (s5r->io_buf, |
759 | &s5r->io_buf[bytes_to_copy], | 773 | &s5r->io_buf[bytes_to_copy], |
760 | s5r->io_len - bytes_to_copy); | 774 | s5r->io_len - bytes_to_copy); |
761 | s5r->io_len -= bytes_to_copy; | 775 | s5r->io_len -= bytes_to_copy; |
762 | curl_easy_pause (s5r->curl, CURLPAUSE_CONT); | 776 | if (NULL != s5r->curl) |
777 | curl_easy_pause (s5r->curl, CURLPAUSE_CONT); | ||
763 | return bytes_to_copy; | 778 | return bytes_to_copy; |
764 | } | 779 | } |
765 | 780 | ||
@@ -807,7 +822,6 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
807 | return GNUNET_OK; | 822 | return GNUNET_OK; |
808 | } | 823 | } |
809 | 824 | ||
810 | |||
811 | 825 | ||
812 | /** | 826 | /** |
813 | * We're getting an HTTP response header from cURL. Convert it to the | 827 | * We're getting an HTTP response header from cURL. Convert it to the |
@@ -849,6 +863,9 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) | |||
849 | curl_easy_getinfo (s5r->curl, | 863 | curl_easy_getinfo (s5r->curl, |
850 | CURLINFO_RESPONSE_CODE, | 864 | CURLINFO_RESPONSE_CODE, |
851 | &resp_code)); | 865 | &resp_code)); |
866 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
867 | "Creating MHD response with code %d\n", | ||
868 | (int) resp_code); | ||
852 | s5r->response_code = resp_code; | 869 | s5r->response_code = resp_code; |
853 | s5r->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | 870 | s5r->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, |
854 | IO_BUFFERSIZE, | 871 | IO_BUFFERSIZE, |
@@ -973,10 +990,16 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) | |||
973 | if (NULL != (tok = strchr (hdr_val, '\t'))) | 990 | if (NULL != (tok = strchr (hdr_val, '\t'))) |
974 | *tok = '\0'; | 991 | *tok = '\0'; |
975 | if (0 != strlen (hdr_val)) | 992 | if (0 != strlen (hdr_val)) |
993 | { | ||
994 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
995 | "Adding header %s: %s to MHD response\n", | ||
996 | hdr_type, | ||
997 | hdr_val); | ||
976 | GNUNET_break (MHD_YES == | 998 | GNUNET_break (MHD_YES == |
977 | MHD_add_response_header (s5r->response, | 999 | MHD_add_response_header (s5r->response, |
978 | hdr_type, | 1000 | hdr_type, |
979 | hdr_val)); | 1001 | hdr_val)); |
1002 | } | ||
980 | GNUNET_free (ndup); | 1003 | GNUNET_free (ndup); |
981 | GNUNET_free_non_null (new_cookie_hdr); | 1004 | GNUNET_free_non_null (new_cookie_hdr); |
982 | GNUNET_free_non_null (new_location); | 1005 | GNUNET_free_non_null (new_location); |
@@ -1006,10 +1029,16 @@ curl_download_cb (void *ptr, size_t size, size_t nmemb, void* ctx) | |||
1006 | /* we're still not done with the upload, do not yet | 1029 | /* we're still not done with the upload, do not yet |
1007 | start the download, the IO buffer is still full | 1030 | start the download, the IO buffer is still full |
1008 | with upload data. */ | 1031 | with upload data. */ |
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1033 | "Pausing CURL download, waiting for UPLOAD to finish\n"); | ||
1009 | return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ | 1034 | return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ |
1010 | } | 1035 | } |
1011 | if (sizeof (s5r->io_buf) - s5r->io_len < total) | 1036 | if (sizeof (s5r->io_buf) - s5r->io_len < total) |
1037 | { | ||
1038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1039 | "Pausing CURL download, not enough space\n"); | ||
1012 | return CURL_WRITEFUNC_PAUSE; /* not enough space */ | 1040 | return CURL_WRITEFUNC_PAUSE; /* not enough space */ |
1041 | } | ||
1013 | memcpy (&s5r->io_buf[s5r->io_len], | 1042 | memcpy (&s5r->io_buf[s5r->io_len], |
1014 | ptr, | 1043 | ptr, |
1015 | total); | 1044 | total); |
@@ -1039,11 +1068,17 @@ curl_upload_cb (void *buf, size_t size, size_t nmemb, void *cls) | |||
1039 | 1068 | ||
1040 | if ( (0 == s5r->io_len) && | 1069 | if ( (0 == s5r->io_len) && |
1041 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) | 1070 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) |
1071 | { | ||
1072 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1073 | "Pausing CURL UPLOAD, need more data\n"); | ||
1042 | return CURL_READFUNC_PAUSE; | 1074 | return CURL_READFUNC_PAUSE; |
1075 | } | ||
1043 | if ( (0 == s5r->io_len) && | 1076 | if ( (0 == s5r->io_len) && |
1044 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | 1077 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) |
1045 | { | 1078 | { |
1046 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | 1079 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; |
1080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1081 | "Completed CURL UPLOAD\n"); | ||
1047 | return 0; /* upload finished, can now download */ | 1082 | return 0; /* upload finished, can now download */ |
1048 | } | 1083 | } |
1049 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) || | 1084 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) || |
@@ -1197,10 +1232,13 @@ curl_task_download (void *cls, | |||
1197 | run_mhd_now (s5r->hd); | 1232 | run_mhd_now (s5r->hd); |
1198 | break; | 1233 | break; |
1199 | } | 1234 | } |
1200 | GNUNET_break (NULL != s5r->response); | 1235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1236 | "Cleaning up cURL handle\n"); | ||
1201 | curl_multi_remove_handle (curl_multi, s5r->curl); | 1237 | curl_multi_remove_handle (curl_multi, s5r->curl); |
1202 | curl_easy_cleanup (s5r->curl); | 1238 | curl_easy_cleanup (s5r->curl); |
1203 | s5r->curl = NULL; | 1239 | s5r->curl = NULL; |
1240 | if (NULL == s5r->response) | ||
1241 | cleanup_s5r (s5r); /* curl failed to yield response, close Socks socket as well */ | ||
1204 | break; | 1242 | break; |
1205 | case CURLMSG_LAST: | 1243 | case CURLMSG_LAST: |
1206 | /* documentation says this is not used */ | 1244 | /* documentation says this is not used */ |
@@ -1262,6 +1300,9 @@ con_val_iter (void *cls, | |||
1262 | "%s: %s", | 1300 | "%s: %s", |
1263 | key, | 1301 | key, |
1264 | value); | 1302 | value); |
1303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1304 | "Adding HEADER `%s' to HTTP request\n", | ||
1305 | hdr); | ||
1265 | s5r->headers = curl_slist_append (s5r->headers, | 1306 | s5r->headers = curl_slist_append (s5r->headers, |
1266 | hdr); | 1307 | hdr); |
1267 | GNUNET_free (hdr); | 1308 | GNUNET_free (hdr); |
@@ -1318,7 +1359,8 @@ create_response (void *cls, | |||
1318 | GNUNET_break (0); | 1359 | GNUNET_break (0); |
1319 | return MHD_NO; | 1360 | return MHD_NO; |
1320 | } | 1361 | } |
1321 | if (NULL == s5r->curl) | 1362 | if ( (NULL == s5r->curl) && |
1363 | (SOCKS5_SOCKET_WITH_MHD == s5r->state) ) | ||
1322 | { | 1364 | { |
1323 | /* first time here, initialize curl handle */ | 1365 | /* first time here, initialize curl handle */ |
1324 | sa = (const struct sockaddr *) &s5r->destination_address; | 1366 | sa = (const struct sockaddr *) &s5r->destination_address; |
@@ -1377,7 +1419,7 @@ create_response (void *cls, | |||
1377 | curl_easy_setopt (s5r->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0); | 1419 | curl_easy_setopt (s5r->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0); |
1378 | curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); | 1420 | curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); |
1379 | curl_easy_setopt (s5r->curl, CURLOPT_PRIVATE, s5r); | 1421 | curl_easy_setopt (s5r->curl, CURLOPT_PRIVATE, s5r); |
1380 | curl_easy_setopt (s5r->curl, CURLOPT_VERBOSE, 1); // FIXME: remove later | 1422 | curl_easy_setopt (s5r->curl, CURLOPT_VERBOSE, 0); // FIXME: remove later |
1381 | GNUNET_asprintf (&curlurl, | 1423 | GNUNET_asprintf (&curlurl, |
1382 | (HTTPS_PORT != s5r->port) | 1424 | (HTTPS_PORT != s5r->port) |
1383 | ? "http://%s:%d%s" | 1425 | ? "http://%s:%d%s" |
@@ -1480,15 +1522,22 @@ create_response (void *cls, | |||
1480 | upload_data, | 1522 | upload_data, |
1481 | left); | 1523 | left); |
1482 | s5r->io_len += left; | 1524 | s5r->io_len += left; |
1483 | *upload_data_size -= left; | 1525 | *upload_data_size -= left; |
1484 | if (s5r->io_len == left) | 1526 | GNUNET_assert (NULL != s5r->curl); |
1485 | curl_easy_pause (s5r->curl, CURLPAUSE_CONT); | 1527 | curl_easy_pause (s5r->curl, CURLPAUSE_CONT); |
1486 | curl_download_prepare (); | 1528 | curl_download_prepare (); |
1487 | return MHD_YES; | 1529 | return MHD_YES; |
1488 | } | 1530 | } |
1489 | s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; | 1531 | if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) |
1532 | { | ||
1533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1534 | "Finished processing UPLOAD\n"); | ||
1535 | s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; | ||
1536 | } | ||
1490 | if (NULL == s5r->response) | 1537 | if (NULL == s5r->response) |
1491 | return MHD_YES; /* too early to queue response, did not yet get headers from cURL */ | 1538 | return MHD_YES; /* too early to queue response, did not yet get headers from cURL */ |
1539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1540 | "Queueing response with MHD\n"); | ||
1492 | return MHD_queue_response (con, | 1541 | return MHD_queue_response (con, |
1493 | s5r->response_code, | 1542 | s5r->response_code, |
1494 | s5r->response); | 1543 | s5r->response); |
@@ -1517,6 +1566,10 @@ mhd_completed_cb (void *cls, | |||
1517 | 1566 | ||
1518 | if (NULL == s5r) | 1567 | if (NULL == s5r) |
1519 | return; | 1568 | return; |
1569 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) | ||
1570 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1571 | "MHD encountered error handling request: %d\n", | ||
1572 | toe); | ||
1520 | cleanup_s5r (s5r); | 1573 | cleanup_s5r (s5r); |
1521 | *con_cls = NULL; | 1574 | *con_cls = NULL; |
1522 | } | 1575 | } |
@@ -2436,6 +2489,9 @@ do_accept (void *cls, | |||
2436 | struct GNUNET_NETWORK_Handle *s; | 2489 | struct GNUNET_NETWORK_Handle *s; |
2437 | struct Socks5Request *s5r; | 2490 | struct Socks5Request *s5r; |
2438 | 2491 | ||
2492 | ltask = GNUNET_SCHEDULER_NO_TASK; | ||
2493 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
2494 | return; | ||
2439 | ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2495 | ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
2440 | lsock, | 2496 | lsock, |
2441 | &do_accept, NULL); | 2497 | &do_accept, NULL); |
@@ -2476,6 +2532,8 @@ do_shutdown (void *cls, | |||
2476 | "Shutting down...\n"); | 2532 | "Shutting down...\n"); |
2477 | while (NULL != mhd_httpd_head) | 2533 | while (NULL != mhd_httpd_head) |
2478 | kill_httpd (mhd_httpd_head); | 2534 | kill_httpd (mhd_httpd_head); |
2535 | while (NULL != s5r_head) | ||
2536 | cleanup_s5r (s5r_head); | ||
2479 | if (NULL != lsock) | 2537 | if (NULL != lsock) |
2480 | { | 2538 | { |
2481 | GNUNET_NETWORK_socket_close (lsock); | 2539 | GNUNET_NETWORK_socket_close (lsock); |