diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-09-09 11:57:08 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-09-09 11:57:08 +0000 |
commit | 9280201a609b5b824ebec4e151bf65b563784a36 (patch) | |
tree | c269e1bdb4f78815ea5472a38f0740efc1b843a0 /src/transport/plugin_transport_http.c | |
parent | 6ad3e6f4977721c38ecaf0602f8cb67cbd6cf949 (diff) | |
download | gnunet-9280201a609b5b824ebec4e151bf65b563784a36.tar.gz gnunet-9280201a609b5b824ebec4e151bf65b563784a36.zip |
clean up
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 131 |
1 files changed, 51 insertions, 80 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index cdbc900f5..c5d92eada 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -52,7 +52,7 @@ | |||
52 | #define PROTOCOL_PREFIX "http" | 52 | #define PROTOCOL_PREFIX "http" |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | #define DEBUG_HTTP GNUNET_YES | 55 | #define DEBUG_HTTP GNUNET_NO |
56 | #define DEBUG_CURL GNUNET_NO | 56 | #define DEBUG_CURL GNUNET_NO |
57 | #define DEBUG_MHD GNUNET_NO | 57 | #define DEBUG_MHD GNUNET_NO |
58 | #define DEBUG_CONNECTIONS GNUNET_NO | 58 | #define DEBUG_CONNECTIONS GNUNET_NO |
@@ -406,6 +406,7 @@ struct Plugin | |||
406 | */ | 406 | */ |
407 | void * mhd_log; | 407 | void * mhd_log; |
408 | 408 | ||
409 | /* only needed for HTTPS plugin */ | ||
409 | #if BUILD_HTTPS | 410 | #if BUILD_HTTPS |
410 | /* The certificate MHD uses as an \0 terminated string */ | 411 | /* The certificate MHD uses as an \0 terminated string */ |
411 | char * cert; | 412 | char * cert; |
@@ -449,12 +450,12 @@ static void http_server_daemon_v6_run (void *cls, const struct GNUNET_SCHEDULER_ | |||
449 | 450 | ||
450 | /** | 451 | /** |
451 | * Function setting up curl handle and selecting message to send | 452 | * Function setting up curl handle and selecting message to send |
452 | * @param cls plugin | 453 | * @param plugin plugin |
453 | * @param ses session to send data to | 454 | * @param ses session to send data to |
454 | * @param con connection | 455 | * @param con connection |
455 | * @return bytes sent to peer | 456 | * @return bytes sent to peer |
456 | */ | 457 | */ |
457 | static ssize_t send_check_connections (void *cls, struct Session *ps); | 458 | static int send_check_connections (struct Plugin *plugin, struct Session *ps); |
458 | 459 | ||
459 | /** | 460 | /** |
460 | * Function setting up file descriptors and scheduling task to run | 461 | * Function setting up file descriptors and scheduling task to run |
@@ -462,20 +463,19 @@ static ssize_t send_check_connections (void *cls, struct Session *ps); | |||
462 | * @param ses session to send data to | 463 | * @param ses session to send data to |
463 | * @param | 464 | * @param |
464 | */ | 465 | */ |
465 | static int curl_schedule(void *cls ); | 466 | static int curl_schedule (struct Plugin *plugin); |
466 | 467 | ||
467 | 468 | ||
468 | /** | 469 | /** |
469 | * Creates a valid url from passed address and id | 470 | * Creates a valid url from passed address and id |
470 | * @param cls plugin as closure | 471 | * @param plugin plugin |
471 | * @param addr address to create url from | 472 | * @param addr address to create url from |
472 | * @param addrlen address lenth | 473 | * @param addrlen address lenth |
473 | * @param id session id | 474 | * @param id session id |
474 | * @return the created url | 475 | * @return the created url |
475 | */ | 476 | */ |
476 | static char * create_url(void * cls, const void * addr, size_t addrlen, size_t id) | 477 | static char * create_url(struct Plugin *plugin, const void * addr, size_t addrlen, size_t id) |
477 | { | 478 | { |
478 | struct Plugin *plugin = cls; | ||
479 | char *url = NULL; | 479 | char *url = NULL; |
480 | char *addr_str = (char *) http_plugin_address_to_string(NULL, addr, addrlen); | 480 | char *addr_str = (char *) http_plugin_address_to_string(NULL, addr, addrlen); |
481 | 481 | ||
@@ -806,8 +806,7 @@ static void mhd_write_mst_cb (void *cls, | |||
806 | * | 806 | * |
807 | */ | 807 | */ |
808 | static int | 808 | static int |
809 | mhd_accept_cb (void *cls, | 809 | mhd_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) |
810 | const struct sockaddr *addr, socklen_t addr_len) | ||
811 | { | 810 | { |
812 | #if 0 | 811 | #if 0 |
813 | struct Plugin *plugin = cls; | 812 | struct Plugin *plugin = cls; |
@@ -827,11 +826,13 @@ mhd_accept_cb (void *cls, | |||
827 | */ | 826 | */ |
828 | int mhd_send_callback (void *cls, uint64_t pos, char *buf, int max) | 827 | int mhd_send_callback (void *cls, uint64_t pos, char *buf, int max) |
829 | { | 828 | { |
830 | int bytes_read = 0; | ||
831 | struct Session * ps = cls; | 829 | struct Session * ps = cls; |
832 | struct HTTP_PeerContext * pc; | 830 | struct HTTP_PeerContext * pc; |
833 | struct HTTP_Message * msg; | 831 | struct HTTP_Message * msg; |
832 | int bytes_read = 0; | ||
833 | |||
834 | GNUNET_assert (ps!=NULL); | 834 | GNUNET_assert (ps!=NULL); |
835 | |||
835 | pc = ps->peercontext; | 836 | pc = ps->peercontext; |
836 | msg = ps->pending_msgs_tail; | 837 | msg = ps->pending_msgs_tail; |
837 | if (ps->send_force_disconnect==GNUNET_YES) | 838 | if (ps->send_force_disconnect==GNUNET_YES) |
@@ -876,12 +877,12 @@ int mhd_send_callback (void *cls, uint64_t pos, char *buf, int max) | |||
876 | */ | 877 | */ |
877 | static int | 878 | static int |
878 | mdh_access_cb (void *cls, | 879 | mdh_access_cb (void *cls, |
879 | struct MHD_Connection *mhd_connection, | 880 | struct MHD_Connection *mhd_connection, |
880 | const char *url, | 881 | const char *url, |
881 | const char *method, | 882 | const char *method, |
882 | const char *version, | 883 | const char *version, |
883 | const char *upload_data, | 884 | const char *upload_data, |
884 | size_t * upload_data_size, void **httpSessionCache) | 885 | size_t * upload_data_size, void **httpSessionCache) |
885 | { | 886 | { |
886 | struct Plugin *plugin = cls; | 887 | struct Plugin *plugin = cls; |
887 | struct MHD_Response *response; | 888 | struct MHD_Response *response; |
@@ -1114,14 +1115,13 @@ mdh_access_cb (void *cls, | |||
1114 | /** | 1115 | /** |
1115 | * Function that queries MHD's select sets and | 1116 | * Function that queries MHD's select sets and |
1116 | * starts the task waiting for them. | 1117 | * starts the task waiting for them. |
1117 | * @param cls plugin as closure | 1118 | * @param plugin plugin |
1118 | * @param daemon_handle the MHD daemon handle | 1119 | * @param daemon_handle the MHD daemon handle |
1119 | * @return gnunet task identifier | 1120 | * @return gnunet task identifier |
1120 | */ | 1121 | */ |
1121 | static GNUNET_SCHEDULER_TaskIdentifier | 1122 | static GNUNET_SCHEDULER_TaskIdentifier |
1122 | http_server_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | 1123 | http_server_daemon_prepare (struct Plugin *plugin , struct MHD_Daemon *daemon_handle) |
1123 | { | 1124 | { |
1124 | struct Plugin *plugin = cls; | ||
1125 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1125 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1126 | fd_set rs; | 1126 | fd_set rs; |
1127 | fd_set ws; | 1127 | fd_set ws; |
@@ -1134,7 +1134,6 @@ http_server_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | |||
1134 | int haveto; | 1134 | int haveto; |
1135 | struct GNUNET_TIME_Relative tv; | 1135 | struct GNUNET_TIME_Relative tv; |
1136 | 1136 | ||
1137 | GNUNET_assert(cls !=NULL); | ||
1138 | ret = GNUNET_SCHEDULER_NO_TASK; | 1137 | ret = GNUNET_SCHEDULER_NO_TASK; |
1139 | FD_ZERO(&rs); | 1138 | FD_ZERO(&rs); |
1140 | FD_ZERO(&ws); | 1139 | FD_ZERO(&ws); |
@@ -1611,12 +1610,9 @@ static void curl_perform (void *cls, | |||
1611 | 1610 | ||
1612 | GNUNET_assert(cls !=NULL); | 1611 | GNUNET_assert(cls !=NULL); |
1613 | 1612 | ||
1614 | |||
1615 | |||
1616 | plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; | 1613 | plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; |
1617 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1614 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1618 | return; | 1615 | return; |
1619 | |||
1620 | do | 1616 | do |
1621 | { | 1617 | { |
1622 | running = 0; | 1618 | running = 0; |
@@ -1626,7 +1622,6 @@ static void curl_perform (void *cls, | |||
1626 | handles_last_run = running; | 1622 | handles_last_run = running; |
1627 | } | 1623 | } |
1628 | while (mret == CURLM_CALL_MULTI_PERFORM); | 1624 | while (mret == CURLM_CALL_MULTI_PERFORM); |
1629 | |||
1630 | curl_schedule(plugin); | 1625 | curl_schedule(plugin); |
1631 | } | 1626 | } |
1632 | 1627 | ||
@@ -1637,9 +1632,8 @@ static void curl_perform (void *cls, | |||
1637 | * @param cls plugin as closure | 1632 | * @param cls plugin as closure |
1638 | * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok | 1633 | * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok |
1639 | */ | 1634 | */ |
1640 | static int curl_schedule(void *cls) | 1635 | static int curl_schedule(struct Plugin *plugin) |
1641 | { | 1636 | { |
1642 | struct Plugin *plugin = cls; | ||
1643 | fd_set rs; | 1637 | fd_set rs; |
1644 | fd_set ws; | 1638 | fd_set ws; |
1645 | fd_set es; | 1639 | fd_set es; |
@@ -1649,8 +1643,6 @@ static int curl_schedule(void *cls) | |||
1649 | long to; | 1643 | long to; |
1650 | CURLMcode mret; | 1644 | CURLMcode mret; |
1651 | 1645 | ||
1652 | GNUNET_assert(cls !=NULL); | ||
1653 | |||
1654 | /* Cancel previous scheduled task */ | 1646 | /* Cancel previous scheduled task */ |
1655 | if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) | 1647 | if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) |
1656 | { | 1648 | { |
@@ -1701,20 +1693,17 @@ static int curl_schedule(void *cls) | |||
1701 | /** | 1693 | /** |
1702 | * Function setting up curl handle and selecting message to send | 1694 | * Function setting up curl handle and selecting message to send |
1703 | * | 1695 | * |
1704 | * @param cls plugin | 1696 | * @param plugin plugin |
1705 | * @param ps session | 1697 | * @param ps session |
1706 | * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok | 1698 | * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok |
1707 | */ | 1699 | */ |
1708 | static ssize_t send_check_connections (void *cls, struct Session *ps) | 1700 | static int send_check_connections (struct Plugin *plugin, struct Session *ps) |
1709 | { | 1701 | { |
1710 | struct Plugin *plugin = cls; | ||
1711 | CURLMcode mret; | 1702 | CURLMcode mret; |
1712 | struct HTTP_Message * msg; | 1703 | struct HTTP_Message * msg; |
1713 | 1704 | ||
1714 | struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; | 1705 | struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; |
1715 | 1706 | ||
1716 | GNUNET_assert(cls !=NULL); | ||
1717 | |||
1718 | if (ps->direction == OUTBOUND) | 1707 | if (ps->direction == OUTBOUND) |
1719 | { | 1708 | { |
1720 | /* RECV DIRECTION */ | 1709 | /* RECV DIRECTION */ |
@@ -1891,7 +1880,7 @@ static ssize_t send_check_connections (void *cls, struct Session *ps) | |||
1891 | * @return selected session | 1880 | * @return selected session |
1892 | * | 1881 | * |
1893 | */ | 1882 | */ |
1894 | static struct Session * send_select_session (void * cls, struct HTTP_PeerContext *pc, const void * addr, size_t addrlen, int force_address, struct Session * session) | 1883 | static struct Session * send_select_session (struct HTTP_PeerContext *pc, const void * addr, size_t addrlen, int force_address, struct Session * session) |
1895 | { | 1884 | { |
1896 | struct Session * tmp = NULL; | 1885 | struct Session * tmp = NULL; |
1897 | int addr_given = GNUNET_NO; | 1886 | int addr_given = GNUNET_NO; |
@@ -2091,59 +2080,44 @@ http_plugin_send (void *cls, | |||
2091 | GNUNET_NO); | 2080 | GNUNET_NO); |
2092 | } | 2081 | } |
2093 | 2082 | ||
2094 | ps = send_select_session (plugin, pc, addr, addrlen, force_address, session); | 2083 | ps = send_select_session (pc, addr, addrlen, force_address, session); |
2095 | 2084 | ||
2096 | /* session not existing, but address forced -> creating new session */ | 2085 | /* session not existing, but address forced -> creating new session */ |
2097 | if (ps==NULL) | 2086 | if (ps==NULL) |
2098 | { | 2087 | { |
2099 | if ((addr!=NULL) && (addrlen!=0)) | 2088 | if ((addr==NULL) && (addrlen==0)) |
2100 | { | ||
2101 | ps = GNUNET_malloc(sizeof (struct Session)); | ||
2102 | #if DEBUG_SESSION_SELECTION | ||
2103 | if (force_address == GNUNET_YES) | ||
2104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection & forced address: creating new session %X to peer %s\n", ps, GNUNET_i2s(target)); | ||
2105 | if (force_address != GNUNET_YES) | ||
2106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection: creating new session %X to peer %s\n", ps, GNUNET_i2s(target)); | ||
2107 | #endif | ||
2108 | if ((addrlen!=0) && (addr!=NULL)) | ||
2109 | { | ||
2110 | ps->addr = GNUNET_malloc(addrlen); | ||
2111 | memcpy(ps->addr,addr,addrlen); | ||
2112 | ps->addrlen = addrlen; | ||
2113 | } | ||
2114 | else | ||
2115 | { | ||
2116 | ps->addr = NULL; | ||
2117 | ps->addrlen = 0; | ||
2118 | } | ||
2119 | ps->direction=OUTBOUND; | ||
2120 | ps->recv_connected = GNUNET_NO; | ||
2121 | ps->recv_force_disconnect = GNUNET_NO; | ||
2122 | ps->send_connected = GNUNET_NO; | ||
2123 | ps->send_force_disconnect = GNUNET_NO; | ||
2124 | ps->pending_msgs_head = NULL; | ||
2125 | ps->pending_msgs_tail = NULL; | ||
2126 | ps->peercontext=pc; | ||
2127 | ps->session_id = pc->session_id_counter; | ||
2128 | pc->session_id_counter++; | ||
2129 | ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id); | ||
2130 | if (ps->msgtok == NULL) | ||
2131 | ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps); | ||
2132 | GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps); | ||
2133 | /* FIXME */ | ||
2134 | |||
2135 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
2136 | gettext_noop ("# HTTP outbound sessions for peers active"), | ||
2137 | 1, | ||
2138 | GNUNET_NO); | ||
2139 | } | ||
2140 | else | ||
2141 | { | 2089 | { |
2142 | #if DEBUG_HTTP | 2090 | #if DEBUG_HTTP |
2143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing session found & and no address given: no way to send this message to peer `%s'!\n", GNUNET_i2s(target)); | 2091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing session found & and no address given: no way to send this message to peer `%s'!\n", GNUNET_i2s(target)); |
2144 | #endif | 2092 | #endif |
2145 | return GNUNET_SYSERR; | 2093 | return GNUNET_SYSERR; |
2146 | } | 2094 | } |
2095 | ps = GNUNET_malloc(sizeof (struct Session)); | ||
2096 | #if DEBUG_SESSION_SELECTION | ||
2097 | if (force_address == GNUNET_YES) | ||
2098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection & forced address: creating new session %X to peer %s\n", ps, GNUNET_i2s(target)); | ||
2099 | if (force_address != GNUNET_YES) | ||
2100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection: creating new session %X to peer %s\n", ps, GNUNET_i2s(target)); | ||
2101 | #endif | ||
2102 | ps->direction=OUTBOUND; | ||
2103 | ps->recv_connected = GNUNET_NO; | ||
2104 | ps->recv_force_disconnect = GNUNET_NO; | ||
2105 | ps->send_connected = GNUNET_NO; | ||
2106 | ps->send_force_disconnect = GNUNET_NO; | ||
2107 | ps->pending_msgs_head = NULL; | ||
2108 | ps->pending_msgs_tail = NULL; | ||
2109 | ps->peercontext=pc; | ||
2110 | ps->session_id = pc->session_id_counter; | ||
2111 | pc->session_id_counter++; | ||
2112 | ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id); | ||
2113 | if (ps->msgtok == NULL) | ||
2114 | ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps); | ||
2115 | GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps); | ||
2116 | |||
2117 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
2118 | gettext_noop ("# HTTP outbound sessions for peers active"), | ||
2119 | 1, | ||
2120 | GNUNET_NO); | ||
2147 | } | 2121 | } |
2148 | 2122 | ||
2149 | /* create msg */ | 2123 | /* create msg */ |
@@ -2444,7 +2418,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
2444 | plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 2418 | plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
2445 | } | 2419 | } |
2446 | 2420 | ||
2447 | |||
2448 | /* free all peer information */ | 2421 | /* free all peer information */ |
2449 | if (plugin->peers!=NULL) | 2422 | if (plugin->peers!=NULL) |
2450 | { | 2423 | { |
@@ -2730,11 +2703,9 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2730 | return NULL; | 2703 | return NULL; |
2731 | } | 2704 | } |
2732 | } | 2705 | } |
2733 | |||
2734 | GNUNET_free (key_file); | 2706 | GNUNET_free (key_file); |
2735 | GNUNET_free (cert_file); | 2707 | GNUNET_free (cert_file); |
2736 | 2708 | ||
2737 | |||
2738 | GNUNET_assert((plugin->key!=NULL) && (plugin->cert!=NULL)); | 2709 | GNUNET_assert((plugin->key!=NULL) && (plugin->cert!=NULL)); |
2739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n"); | 2710 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n"); |
2740 | #endif | 2711 | #endif |