aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-06-29 10:48:03 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-06-29 10:48:03 +0000
commitff12c387ccbf650427512dcb18cfbff0934c4edf (patch)
tree37fceadd0a1564b0a756367d30578d59e3e64baa /src
parentb51130e1f156917a1ddd892c645d871b84192ad6 (diff)
downloadgnunet-ff12c387ccbf650427512dcb18cfbff0934c4edf.tar.gz
gnunet-ff12c387ccbf650427512dcb18cfbff0934c4edf.zip
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http.c146
-rw-r--r--src/transport/test_plugin_transport_http.c15
2 files changed, 91 insertions, 70 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index b412b46ae..74d9fac94 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -391,11 +391,6 @@ static struct Session * session_get (void * cls, const struct GNUNET_PeerIdentit
391 unsigned int res; 391 unsigned int res;
392 392
393 cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &p->hashPubKey); 393 cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &p->hashPubKey);
394 if (cs != NULL)
395 {
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
397 "Session `%s' found\n", GNUNET_i2s(p));
398 }
399 if (cs == NULL) 394 if (cs == NULL)
400 { 395 {
401 cs = create_session(plugin, NULL, 0, NULL, 0, p); 396 cs = create_session(plugin, NULL, 0, NULL, 0, p);
@@ -471,7 +466,7 @@ static struct HTTP_Connection_out * session_check_outbound_address (void * cls,
471 } 466 }
472 cc=cc->next; 467 cc=cc->next;
473 } 468 }
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No connection info for this address was found\n",GNUNET_i2s(&cs->identity)); 469
475 if (con==NULL) 470 if (con==NULL)
476 { 471 {
477 con = GNUNET_malloc(sizeof(struct HTTP_Connection_out) + addr_len); 472 con = GNUNET_malloc(sizeof(struct HTTP_Connection_out) + addr_len);
@@ -482,6 +477,7 @@ static struct HTTP_Connection_out * session_check_outbound_address (void * cls,
482 con->session = cs; 477 con->session = cs;
483 memcpy(con->addr, addr, addr_len); 478 memcpy(con->addr, addr, addr_len);
484 GNUNET_CONTAINER_DLL_insert(cs->outbound_connections_head,cs->outbound_connections_tail,con); 479 GNUNET_CONTAINER_DLL_insert(cs->outbound_connections_head,cs->outbound_connections_tail,con);
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Created new connection %X to peer `%s'\n",con,GNUNET_i2s(&cs->identity));
485 } 481 }
486 return con; 482 return con;
487} 483}
@@ -563,8 +559,8 @@ static void messageTokenizerCallback (void *cls,
563 con->session->plugin->env->receive (con->session->plugin->env->cls, 559 con->session->plugin->env->receive (con->session->plugin->env->cls,
564 &con->session->identity, 560 &con->session->identity,
565 message, 1, con->session, 561 message, 1, con->session,
566 NULL, 562 con->addr,
567 0); 563 con->addrlen);
568} 564}
569 565
570/** 566/**
@@ -581,6 +577,13 @@ acceptPolicyCallback (void *cls,
581 return MHD_YES; 577 return MHD_YES;
582} 578}
583 579
580int server_read_callback (void *cls, uint64_t pos, char *buf, int max)
581{
582 int bytes_read = -1;
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server_read_callback\n");
584 return bytes_read;
585}
586
584/** 587/**
585 * Process GET or PUT request received via MHD. For 588 * Process GET or PUT request received via MHD. For
586 * GET, queue response that will send back our pending 589 * GET, queue response that will send back our pending
@@ -613,8 +616,8 @@ accessHandlerCallback (void *cls,
613 616
614 GNUNET_assert(cls !=NULL); 617 GNUNET_assert(cls !=NULL);
615 send_error_to_client = GNUNET_NO; 618 send_error_to_client = GNUNET_NO;
616 619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"accessHandlerCallback\n");
617 if ( NULL == *httpSessionCache) 620 if (NULL == *httpSessionCache)
618 { 621 {
619 /* check url for peer identity , if invalid send HTTP 404*/ 622 /* check url for peer identity , if invalid send HTTP 404*/
620 res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey)); 623 res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey));
@@ -629,36 +632,6 @@ accessHandlerCallback (void *cls,
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, could not send error\n"); 632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, could not send error\n");
630 return res; 633 return res;
631 } 634 }
632
633 /* get session for peer identity */
634 cs = session_get (plugin ,&pi_in);
635
636 conn_info = MHD_get_connection_info(mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS );
637 /* Incoming IPv4 connection */
638 if ( AF_INET == conn_info->client_addr->sin_family)
639 {
640 addrin = conn_info->client_addr;
641 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
642 memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr));
643 ipv4addr.u_port = addrin->sin_port;
644 con = session_check_inbound_address (plugin, cs, (const void *) &ipv4addr, sizeof (struct IPv4HttpAddress));
645 }
646 /* Incoming IPv6 connection */
647 if ( AF_INET6 == conn_info->client_addr->sin_family)
648 {
649 addrin6 = (struct sockaddr_in6 *) conn_info->client_addr;
650 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
651 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in_addr));
652 ipv6addr.u6_port = addrin6->sin6_port;
653 con = session_check_inbound_address (plugin, cs, &ipv6addr, sizeof (struct IPv6HttpAddress));
654 }
655 /* Set closure and update current session*/
656
657 *httpSessionCache = con;
658 if (con->msgtok==NULL)
659 con->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &messageTokenizerCallback, con);
660
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s'@`%s'\n",method, GNUNET_i2s(&cs->identity),address);
662 } 635 }
663 else 636 else
664 { 637 {
@@ -669,6 +642,39 @@ accessHandlerCallback (void *cls,
669 /* Is it a PUT or a GET request */ 642 /* Is it a PUT or a GET request */
670 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) 643 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
671 { 644 {
645 if (NULL == *httpSessionCache)
646 {
647 /* get session for peer identity */
648 cs = session_get (plugin ,&pi_in);
649
650 conn_info = MHD_get_connection_info(mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS );
651 /* Incoming IPv4 connection */
652 if ( AF_INET == conn_info->client_addr->sin_family)
653 {
654 addrin = conn_info->client_addr;
655 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
656 memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr));
657 ipv4addr.u_port = addrin->sin_port;
658 con = session_check_inbound_address (plugin, cs, (const void *) &ipv4addr, sizeof (struct IPv4HttpAddress));
659 }
660 /* Incoming IPv6 connection */
661 if ( AF_INET6 == conn_info->client_addr->sin_family)
662 {
663 addrin6 = (struct sockaddr_in6 *) conn_info->client_addr;
664 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
665 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in_addr));
666 ipv6addr.u6_port = addrin6->sin6_port;
667 con = session_check_inbound_address (plugin, cs, &ipv6addr, sizeof (struct IPv6HttpAddress));
668 }
669 /* Set closure and update current session*/
670
671 *httpSessionCache = con;
672 if (con->msgtok==NULL)
673 con->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &messageTokenizerCallback, con);
674
675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",method, GNUNET_i2s(&cs->identity),address);
676 }
677
672 if ((*upload_data_size == 0) && (con->is_put_in_progress==GNUNET_NO)) 678 if ((*upload_data_size == 0) && (con->is_put_in_progress==GNUNET_NO))
673 { 679 {
674 con->is_put_in_progress = GNUNET_YES; 680 con->is_put_in_progress = GNUNET_YES;
@@ -703,10 +709,28 @@ accessHandlerCallback (void *cls,
703 { 709 {
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n"); 710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n");
705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url); 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url);
706 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); 712
707 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 713 /* check url for peer identity , if invalid send HTTP 404*/
714 res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey));
715
716 if ( GNUNET_SYSERR == res )
717 {
718 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
719 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
720 MHD_destroy_response (response);
721 if (res == MHD_YES)
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, sent HTTP 1.1/404\n");
723 else
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, could not send error\n");
725 return res;
726 }
727
728 response = MHD_create_response_from_callback(-1,32 * 1024, &server_read_callback, cs, NULL);
729 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
708 MHD_destroy_response (response); 730 MHD_destroy_response (response);
731
709 return res; 732 return res;
733
710 } 734 }
711 return MHD_NO; 735 return MHD_NO;
712} 736}
@@ -1086,14 +1110,16 @@ static void send_execute (void *cls,
1086 (msg->data.result != CURLE_GOT_NOTHING) ) 1110 (msg->data.result != CURLE_GOT_NOTHING) )
1087 { 1111 {
1088 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1112 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1089 _("%s failed for `%s' at %s:%d: `%s'\n"), 1113 _("%s failed for `%s' connection %X at %s:%d: `%s'\n"),
1090 "curl_multi_perform", 1114 "curl_multi_perform",
1091 GNUNET_i2s(&cs->identity), 1115 GNUNET_i2s(&cs->identity),con,
1092 __FILE__, 1116 __FILE__,
1093 __LINE__, 1117 __LINE__,
1094 curl_easy_strerror (msg->data.result)); 1118 curl_easy_strerror (msg->data.result));
1095 /* sending msg failed*/ 1119 /* sending msg failed*/
1096 con->connected = GNUNET_NO; 1120 con->connected = GNUNET_NO;
1121 curl_easy_cleanup(con->curl_handle);
1122 con->curl_handle=NULL;
1097 if (( NULL != con->pending_msgs_tail) && ( NULL != con->pending_msgs_tail->transmit_cont)) 1123 if (( NULL != con->pending_msgs_tail) && ( NULL != con->pending_msgs_tail->transmit_cont))
1098 con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&con->session->identity,GNUNET_SYSERR); 1124 con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&con->session->identity,GNUNET_SYSERR);
1099 1125
@@ -1257,8 +1283,10 @@ http_plugin_send (void *cls,
1257 address = NULL; 1283 address = NULL;
1258 1284
1259 /* get session from hashmap */ 1285 /* get session from hashmap */
1286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to %s, %u\n", msgbuf_size, GNUNET_i2s(target),addrlen);
1260 cs = session_get(plugin, target); 1287 cs = session_get(plugin, target);
1261 con = session_check_outbound_address(plugin, cs, addr, addrlen); 1288 con = session_check_outbound_address(plugin, cs, addr, addrlen);
1289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to peer `%s'\n",msgbuf_size,GNUNET_i2s(&cs->identity));
1262 1290
1263 /* create msg */ 1291 /* create msg */
1264 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); 1292 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
@@ -1516,28 +1544,28 @@ process_interfaces (void *cls,
1516 const struct sockaddr *addr, socklen_t addrlen) 1544 const struct sockaddr *addr, socklen_t addrlen)
1517{ 1545{
1518 struct Plugin *plugin = cls; 1546 struct Plugin *plugin = cls;
1519 struct IPv4HttpAddress t4; 1547 struct IPv4HttpAddress * t4;
1520 struct IPv6HttpAddress t6; 1548 struct IPv6HttpAddress * t6;
1521 int af; 1549 int af;
1522 void *arg;
1523 uint16_t args;
1524 1550
1525 GNUNET_assert(cls !=NULL); 1551 GNUNET_assert(cls !=NULL);
1526 af = addr->sa_family; 1552 af = addr->sa_family;
1527 if (af == AF_INET) 1553 if (af == AF_INET)
1528 { 1554 {
1555 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
1529 if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr)) 1556 if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr))
1530 { 1557 {
1531 /* skip loopback addresses */ 1558 /* skip loopback addresses */
1532 return GNUNET_OK; 1559 return GNUNET_OK;
1533 } 1560 }
1534 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 1561 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1535 t4.u_port = htons (plugin->port_inbound); 1562 t4->u_port = htons (plugin->port_inbound);
1536 arg = &t4; 1563 plugin->env->notify_address(plugin->env->cls,"http",t4, sizeof (struct IPv4HttpAddress), GNUNET_TIME_UNIT_FOREVER_REL);
1537 args = sizeof (t4); 1564
1538 } 1565 }
1539 else if (af == AF_INET6) 1566 else if (af == AF_INET6)
1540 { 1567 {
1568 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
1541 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) 1569 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
1542 { 1570 {
1543 /* skip link local addresses */ 1571 /* skip link local addresses */
@@ -1548,22 +1576,14 @@ process_interfaces (void *cls,
1548 /* skip loopback addresses */ 1576 /* skip loopback addresses */
1549 return GNUNET_OK; 1577 return GNUNET_OK;
1550 } 1578 }
1551 memcpy (&t6.ipv6_addr, 1579 memcpy (&t6->ipv6_addr,
1552 &((struct sockaddr_in6 *) addr)->sin6_addr, 1580 &((struct sockaddr_in6 *) addr)->sin6_addr,
1553 sizeof (struct in6_addr)); 1581 sizeof (struct in6_addr));
1554 t6.u6_port = htons (plugin->port_inbound); 1582 t6->u6_port = htons (plugin->port_inbound);
1555 arg = &t6; 1583 plugin->env->notify_address(plugin->env->cls,"http",t6,sizeof (struct IPv6HttpAddress) , GNUNET_TIME_UNIT_FOREVER_REL);
1556 args = sizeof (t6);
1557 }
1558 else
1559 {
1560 GNUNET_break (0);
1561 return GNUNET_OK;
1562 } 1584 }
1563 plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
1564 return GNUNET_OK; 1585 return GNUNET_OK;
1565} 1586}
1566
1567int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value) 1587int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value)
1568{ 1588{
1569 struct Session * cs = value; 1589 struct Session * cs = value;
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 0e26c4639..7fdb2c6c4 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -44,7 +44,7 @@
44 44
45#define VERBOSE GNUNET_YES 45#define VERBOSE GNUNET_YES
46#define DEBUG GNUNET_NO 46#define DEBUG GNUNET_NO
47#define DEBUG_CURL GNUNET_YES 47#define DEBUG_CURL GNUNET_NO
48#define HTTP_BUFFER_SIZE 2048 48#define HTTP_BUFFER_SIZE 2048
49 49
50#define PLUGIN libgnunet_plugin_transport_template 50#define PLUGIN libgnunet_plugin_transport_template
@@ -164,12 +164,12 @@ struct IPv4HttpAddress
164 /** 164 /**
165 * IPv4 address, in network byte order. 165 * IPv4 address, in network byte order.
166 */ 166 */
167 uint32_t ipv4_addr; 167 uint32_t ipv4_addr GNUNET_PACKED;
168 168
169 /** 169 /**
170 * Port number, in network byte order. 170 * Port number, in network byte order.
171 */ 171 */
172 uint16_t u_port; 172 uint16_t u_port GNUNET_PACKED;
173 173
174}; 174};
175 175
@@ -182,16 +182,15 @@ struct IPv6HttpAddress
182 /** 182 /**
183 * IPv6 address. 183 * IPv6 address.
184 */ 184 */
185 struct in6_addr ipv6_addr; 185 struct in6_addr ipv6_addr GNUNET_PACKED;
186 186
187 /** 187 /**
188 * Port number, in network byte order. 188 * Port number, in network byte order.
189 */ 189 */
190 uint16_t u6_port; 190 uint16_t u6_port GNUNET_PACKED;
191 191
192}; 192};
193 193
194
195/** 194/**
196 * Our public key. 195 * Our public key.
197 */ 196 */
@@ -392,6 +391,8 @@ shutdown_clean ()
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n"); 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
393 } 392 }
394 393
394 api->disconnect(api->cls,&my_identity);
395
395 curl_multi_cleanup(multi_handle); 396 curl_multi_cleanup(multi_handle);
396 397
397 if (NULL != curl_handle) 398 if (NULL != curl_handle)
@@ -499,7 +500,7 @@ receive (void *cls,
499 if (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1) 500 if (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1)
500 { 501 {
501 fail_msg_transmited_max_size = GNUNET_NO; 502 fail_msg_transmited_max_size = GNUNET_NO;
502 shutdown_clean(); 503 //shutdown_clean();
503 } 504 }
504 505
505 return GNUNET_TIME_UNIT_ZERO; 506 return GNUNET_TIME_UNIT_ZERO;