From: Matthias Wachs Date: Mon, 14 Jun 2010 11:21:52 +0000 (+0000) Subject: (no commit message) X-Git-Tag: initial-import-from-subversion-38251~21396 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dd512c67d981ba52f7eba429c36d126095bbdf93;hp=e5d0b4aadf77fb0a303320f9a6568a5d64cf8e00;p=oweals%2Fgnunet.git --- diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index c20e30c91..798452934 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -140,6 +140,18 @@ struct HTTP_Message size_t len; char * dest_url; + + /** + * Continuation function to call once the transmission buffer + * has again space available. NULL if there is no + * continuation to call. + */ + GNUNET_TRANSPORT_TransmitContinuation transmit_cont; + + /** + * Closure for transmit_cont. + */ + void *transmit_cont_cls; }; @@ -159,18 +171,6 @@ struct Session */ struct Plugin *plugin; - /** - * Continuation function to call once the transmission buffer - * has again space available. NULL if there is no - * continuation to call. - */ - GNUNET_TRANSPORT_TransmitContinuation transmit_cont; - - /** - * Closure for transmit_cont. - */ - void *transmit_cont_cls; - /** * To whom are we talking to (set to our identity * if we are still waiting for the welcome message) @@ -797,6 +797,7 @@ static int remove_http_message(struct Session * ses, struct HTTP_Message * msg) { ses->pending_outbound_msg = cur->next; GNUNET_free (cur->buf); + GNUNET_free (cur->dest_url); GNUNET_free (cur); cur = NULL; return GNUNET_OK; @@ -812,6 +813,7 @@ static int remove_http_message(struct Session * ses, struct HTTP_Message * msg) cur->next = cur->next->next; GNUNET_free (cur->next->buf); + GNUNET_free (cur->next->dest_url); GNUNET_free (cur->next); cur->next = NULL; return GNUNET_OK; @@ -921,7 +923,6 @@ static size_t send_prepare(struct Session* session ); */ static ssize_t send_select_init (struct Session* ses ) { - char * url; int bytes_sent = 0; CURLMcode mret; struct HTTP_Message * msg; @@ -935,15 +936,12 @@ static ssize_t send_select_init (struct Session* ses ) } msg = ses->pending_outbound_msg; - url = GNUNET_malloc( 7 + strlen(ses->ip) + 7 + strlen ((char *) &(ses->hash)) + 1); - /* FIXME: use correct port number */ - GNUNET_asprintf(&url,"http://%s:%u/%s",ses->ip,12389, (char *) &(ses->hash)); #if DEBUG_CURL curl_easy_setopt(ses->curl_handle, CURLOPT_VERBOSE, 1L); #endif - curl_easy_setopt(ses->curl_handle, CURLOPT_URL, url); + 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_READFUNCTION, send_read_callback); @@ -964,7 +962,6 @@ static ssize_t send_select_init (struct Session* ses ) return -1; } bytes_sent = send_prepare (ses ); - GNUNET_free ( url ); return bytes_sent; } @@ -1013,8 +1010,8 @@ static void send_execute (void *cls, __LINE__, curl_easy_strerror (msg->data.result)); /* sending msg failed*/ - if ( NULL != cs->transmit_cont) - cs->transmit_cont (cs->transmit_cont_cls,&cs->sender,GNUNET_SYSERR); + if ( NULL != cs->pending_outbound_msg->transmit_cont) + cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_SYSERR); } else { @@ -1027,8 +1024,8 @@ static void send_execute (void *cls, cs->curl_handle=NULL; /* Calling transmit continuation */ - if ( NULL != cs->transmit_cont) - cs->transmit_cont (NULL,&cs->sender,GNUNET_OK); + if ( NULL != cs->pending_outbound_msg->transmit_cont) + cs->pending_outbound_msg->transmit_cont (cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK); /* send pending messages */ @@ -1149,7 +1146,7 @@ http_plugin_send (void *cls, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { - char address[INET6_ADDRSTRLEN]; + char * address; struct Session* ses; struct Session* ses_temp; struct HTTP_Message * msg; @@ -1167,7 +1164,6 @@ http_plugin_send (void *cls, /*FIXME: what is const void * really? Assuming struct sockaddr_in * ! */ ses = create_session(NULL, (struct sockaddr_in *) addr, target); ses->is_active = GNUNET_YES; - ses->transmit_cont = cont; /* Insert session into linked list */ if ( plugin->sessions == NULL) @@ -1190,24 +1186,31 @@ http_plugin_send (void *cls, GNUNET_assert (addr!=NULL); unsigned int port; - if (addrlen == (sizeof (struct IPv4HttpAddress))) + + /* setting url to send to */ + if (force_address == GNUNET_YES) + { + if (addrlen == (sizeof (struct IPv4HttpAddress))) { + address = GNUNET_malloc(INET_ADDRSTRLEN + 14 + strlen ((const char *) (&ses->hash))); inet_ntop(AF_INET,&((struct IPv4HttpAddress *) addr)->ipv4_addr,address,INET_ADDRSTRLEN); port = ntohs(((struct IPv4HttpAddress *) addr)->u_port); + GNUNET_asprintf(&address,"http://%s:%u/%s",address,port, (char *) (&ses->hash)); } - else if (addrlen == (sizeof (struct IPv6HttpAddress))) + else if (addrlen == (sizeof (struct IPv6HttpAddress))) { + address = GNUNET_malloc(INET6_ADDRSTRLEN + 14 + strlen ((const char *) (&ses->hash))); inet_ntop(AF_INET6, &((struct IPv6HttpAddress *) addr)->ipv6_addr,address,INET6_ADDRSTRLEN); port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port); + GNUNET_asprintf(&address,"http://%s:%u/%s",address,port,(char *) (&ses->hash)); } - else - { - GNUNET_break (0); - return -1; + else + { + GNUNET_break (0); + return -1; } + } - ses->transmit_cont = cont; - ses->transmit_cont_cls = cont_cls; timeout = to; /* setting up message */ msg = GNUNET_malloc (sizeof (struct HTTP_Message)); @@ -1215,6 +1218,9 @@ http_plugin_send (void *cls, msg->len = msgbuf_size; msg->pos = 0; msg->buf = GNUNET_malloc (msgbuf_size); + msg->dest_url = address; + msg->transmit_cont = cont; + msg->transmit_cont_cls = cont_cls; memcpy (msg->buf,msgbuf, msgbuf_size); /* insert created message in list of pending messages */ diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index ed501be42..5f262bf5d 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c @@ -294,6 +294,11 @@ static int fail_pretty_printer_count; */ static int fail_addr_to_str; +/** + * Did the test pass or fail? + */ +static int fail_transmit_to_local_addrs; + /** * Test: connect to peer without peer identification */ @@ -343,7 +348,7 @@ shutdown_clean () /* Evaluate results */ if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) && (test_no_ident.test_failed == GNUNET_NO) && (test_too_short_ident.test_failed == GNUNET_NO) && (test_too_long_ident.test_failed == GNUNET_NO) && - (test_valid_ident.test_failed == GNUNET_NO)) + (test_valid_ident.test_failed == GNUNET_NO) && (fail_transmit_to_local_addrs == GNUNET_NO)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests successful\n"); fail = 0; @@ -408,6 +413,19 @@ static void task_send_cont (void *cls, const struct GNUNET_PeerIdentity * target, int result) { + struct Plugin_Address * tmp_addr; + tmp_addr = addr_head; + while (tmp_addr->next != NULL) + { + tmp_addr = tmp_addr->next; + } + + if (cls == tmp_addr) + { + fail_transmit_to_local_addrs = GNUNET_NO; + shutdown_clean(); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message was sent!\n"); fail = GNUNET_NO; //shutdown_clean(); @@ -915,8 +933,6 @@ static void run_connection_tests( void ) while (tmp_addr != NULL) { - - if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) { inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN); @@ -934,7 +950,7 @@ static void run_connection_tests( void ) 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, NULL); + 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); tmp_addr = tmp_addr->next; count ++; } @@ -970,6 +986,7 @@ run (void *cls, fail_pretty_printer = GNUNET_YES; fail_notify_address = GNUNET_YES; fail_addr_to_str = GNUNET_YES; + fail_transmit_to_local_addrs = GNUNET_YES; addr_head = NULL; count_str_addr = 0;