From: Matthias Wachs Date: Wed, 16 Jun 2010 15:56:24 +0000 (+0000) Subject: (no commit message) X-Git-Tag: initial-import-from-subversion-38251~21366 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7e9b0bef0dc2a0915f411b167f0253d9a35f796a;p=oweals%2Fgnunet.git --- diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 1dee788d6..752b6675b 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -152,6 +152,8 @@ struct HTTP_Message * Closure for transmit_cont. */ void *transmit_cont_cls; + + unsigned int http_result_code; }; @@ -586,9 +588,10 @@ accessHandlerCallback (void *cls, res = MHD_queue_response (session, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, response); if (res == MHD_YES) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 ENTITY TOO LARGE as PUT Response\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 Request Entity Too Large as PUT Response\n"); cs->is_bad_request = GNUNET_NO; cs->is_put_in_progress =GNUNET_NO; + cs->pending_inbound_msg->pos = 0; } MHD_destroy_response (response); return MHD_YES; @@ -801,6 +804,7 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea { char * tmp; unsigned int len = size * nmemb; + struct Session * ses = stream; tmp = GNUNET_malloc ( len+1 ); memcpy(tmp,ptr,len); @@ -809,28 +813,26 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea #if DEBUG_CURL GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp); #endif - /* if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) { - res->http_result_code=100; + ses->pending_outbound_msg->http_result_code=100; } if (0==strcmp (tmp,"HTTP/1.1 200 OK")) { - res->http_result_code=200; + ses->pending_outbound_msg->http_result_code=200; } if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request")) { - res->http_result_code=400; + ses->pending_outbound_msg->http_result_code=400; } if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) { - res->http_result_code=404; + ses->pending_outbound_msg->http_result_code=404; } - if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large")) + if (0==strcmp (tmp,"HTTP/1.1 413 Request Entity Too Large")) { - res->http_result_code=413; + ses->pending_outbound_msg->http_result_code=413; } - */ GNUNET_free (tmp); return size * nmemb; } @@ -849,18 +851,33 @@ static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void * struct Session * ses = ptr; struct HTTP_Message * msg = ses->pending_outbound_msg; unsigned int bytes_sent; - + unsigned int len; bytes_sent = 0; - if (msg->len > (size * nmemb)) - return CURL_READFUNC_ABORT; - if (( msg->pos < msg->len) && (msg->len < (size * nmemb))) + /* data to send */ + if (( msg->pos < msg->len)) { - memcpy(stream, msg->buf, msg->len); - msg->pos = msg->len; - bytes_sent = msg->len; + /* data fit in buffer */ + if ((msg->len - msg->pos) <= (size * nmemb)) + { + len = (msg->len - msg->pos); + memcpy(stream, &msg->buf[msg->pos], len); + msg->pos += len; + bytes_sent = len; + } + else + { + len = size*nmemb; + memcpy(stream, &msg->buf[msg->pos], len); + msg->pos += len; + bytes_sent = len; + } + } + /* no data to send */ + else + { + bytes_sent = 0; } - return bytes_sent; } @@ -880,7 +897,7 @@ static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void memcpy( data, stream, size*nmemb); data[size*nmemb] = '\0'; /* Just a dummy print for the response recieved for the PUT message */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * nmemb, data); + /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * nmemb, data); */ free (data); return (size * nmemb); @@ -921,6 +938,7 @@ static ssize_t send_select_init (struct Session* ses ) curl_easy_setopt(ses->curl_handle, CURLOPT_URL, msg->dest_url); curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L); curl_easy_setopt(ses->curl_handle, CURLOPT_HEADERFUNCTION, &header_function); + curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEHEADER, ses); curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback); curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses); curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback); @@ -928,6 +946,7 @@ static ssize_t send_select_init (struct Session* ses ) curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len); curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, (long) (timeout.value / 1000 )); curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); + curl_easy_setopt(ses->curl_handle, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE); mret = curl_multi_add_handle(multi_handle, ses->curl_handle); if (mret != CURLM_OK) @@ -994,16 +1013,26 @@ static void send_execute (void *cls, } else { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Send to peer `%s' completed.\n", GNUNET_i2s(&cs->sender)); + "Send to peer `%s' completed with code %u\n", GNUNET_i2s(&cs->sender),cs->pending_outbound_msg->http_result_code); curl_easy_cleanup(cs->curl_handle); cs->curl_handle=NULL; /* Calling transmit continuation */ if (( NULL != cs->pending_outbound_msg) && (NULL != cs->pending_outbound_msg->transmit_cont)) - cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK); - + { + /* HTTP 1xx : Last message before here was informational */ + if ((cs->pending_outbound_msg->http_result_code >=100) && (cs->pending_outbound_msg->http_result_code < 200)) + cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK); + /* HTTP 2xx: successful operations */ + if ((cs->pending_outbound_msg->http_result_code >=200) && (cs->pending_outbound_msg->http_result_code < 300)) + cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK); + /* HTTP 3xx..5xx: error */ + if ((cs->pending_outbound_msg->http_result_code >=300) && (cs->pending_outbound_msg->http_result_code < 600)) + cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_SYSERR); + } if (GNUNET_OK != remove_http_message(cs, cs->pending_outbound_msg)) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->sender)); diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index d8e0b4f1f..3d1c8d5e5 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c @@ -42,7 +42,7 @@ #include "transport.h" #include -#define VERBOSE GNUNET_NO +#define VERBOSE GNUNET_YES #define DEBUG GNUNET_NO #define DEBUG_CURL GNUNET_NO #define HTTP_BUFFER_SIZE 2048 @@ -304,6 +304,16 @@ static int fail_addr_to_str; */ static int fail_msgs_transmited_to_local_addrs; +/** + * Test: transmit msg of max. size + */ +static int fail_msg_transmited_bigger_max_size; + +/** + * Test: transmit msg of max. size + */ +static int fail_msg_transmited_max_size; + /** * Test: connect to peer without peer identification */ @@ -362,12 +372,12 @@ shutdown_clean () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test plugin functions failed\n"); fail = 1; } - if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_ident.test_failed == GNUNET_YES)) + if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_ident.test_failed == GNUNET_YES) || (test_valid_ident.test_failed == GNUNET_YES)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data failed\n"); fail = 1; } - if ((test_valid_ident.test_failed == GNUNET_YES) || (fail_msgs_transmited_to_local_addrs != count_str_addr)) + if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_msg_transmited_max_size == GNUNET_YES) || (fail_msg_transmited_bigger_max_size == GNUNET_YES)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n"); fail = 1; @@ -437,23 +447,29 @@ static void task_send_cont (void *cls, struct Plugin_Address * tmp_addr; tmp_addr = addr_head; - while (tmp_addr != NULL) + if ((cls == &fail_msgs_transmited_to_local_addrs) && (result == GNUNET_OK)) { - if (cls == tmp_addr) - if (result == GNUNET_OK) fail_msgs_transmited_to_local_addrs++; - tmp_addr = tmp_addr->next; + fail_msgs_transmited_to_local_addrs++; + if (fail_msgs_transmited_to_local_addrs == count_str_addr) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message sent to %u addresses!\n",fail_msgs_transmited_to_local_addrs); + } + return; } - if (fail_msgs_transmited_to_local_addrs == count_str_addr) + if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not sent!\n"); + fail_msg_transmited_bigger_max_size = GNUNET_NO; + return; + } + if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message sent to %u addresses!\n",fail_msgs_transmited_to_local_addrs); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size succesfully sent!\n",fail_msgs_transmited_to_local_addrs); + fail_msg_transmited_max_size = GNUNET_NO; shutdown_clean(); } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message was sent!\n"); - fail = GNUNET_NO; - //shutdown_clean(); } #if 0 @@ -874,7 +890,6 @@ static void pretty_printer_cb (void *cls, static void run_connection_tests( ) { char * host_str = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO,"Addr: %s\n",test_addr); /* resetting buffers */ buffer_in.size = HTTP_BUFFER_SIZE; buffer_in.pos = 0; @@ -944,15 +959,13 @@ static void run_connection_tests( ) char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); char address[INET6_ADDRSTRLEN]; unsigned int port; + unsigned int type = 10; msg.size=htons(sizeof(struct GNUNET_MessageHeader)); - msg.type=htons(13); - memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); - tmp_addr = addr_head; /* send a message to all addresses advertised by plugin */ - int count = 0; + int count = 0; while (tmp_addr != NULL) { if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) @@ -972,11 +985,31 @@ static void run_connection_tests( ) GNUNET_break (0); return; } - api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont, tmp_addr); + msg.type=htons(type); + memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); + api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont, &fail_msgs_transmited_to_local_addrs); tmp_addr = tmp_addr->next; count ++; + type ++; } + /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE )*/ + GNUNET_free(tmp); + tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE); + uint16_t t2 = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE; + msg.size = htons(t2); + memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); + api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_msg_transmited_bigger_max_size); + + + /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ + GNUNET_free(tmp); + tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1); + uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1; + msg.size = htons(t); + memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); + api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE-1, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_msg_transmited_max_size); + GNUNET_free(tmp); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); } @@ -1009,6 +1042,7 @@ run (void *cls, fail_notify_address = GNUNET_YES; fail_addr_to_str = GNUNET_YES; fail_msgs_transmited_to_local_addrs = 0; + fail_msg_transmited_max_size = GNUNET_YES; addr_head = NULL; count_str_addr = 0;