aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/plugin_transport_http.c46
-rw-r--r--src/transport/test_plugin_transport_http.c42
2 files changed, 36 insertions, 52 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index dcb778de9..58051e90e 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -246,11 +246,6 @@ struct Plugin
246 */ 246 */
247 struct GNUNET_TRANSPORT_PluginEnvironment *env; 247 struct GNUNET_TRANSPORT_PluginEnvironment *env;
248 248
249 /**
250 * Handle to the network service.
251 */
252 struct GNUNET_SERVICE_Context *service;
253
254 unsigned int port_inbound; 249 unsigned int port_inbound;
255 250
256 /** 251 /**
@@ -303,11 +298,6 @@ static struct Plugin *plugin;
303static CURLM *multi_handle; 298static CURLM *multi_handle;
304 299
305/** 300/**
306 * Our hostname
307 */
308static char * hostname;
309
310/**
311 * Our ASCII encoded, hashed peer identity 301 * Our ASCII encoded, hashed peer identity
312 * This string is used to distinguish between connections and is added to the urls 302 * This string is used to distinguish between connections and is added to the urls
313 */ 303 */
@@ -1454,8 +1444,6 @@ process_interfaces (void *cls,
1454 void *arg; 1444 void *arg;
1455 uint16_t args; 1445 uint16_t args;
1456 1446
1457
1458
1459 af = addr->sa_family; 1447 af = addr->sa_family;
1460 if (af == AF_INET) 1448 if (af == AF_INET)
1461 { 1449 {
@@ -1494,7 +1482,6 @@ process_interfaces (void *cls,
1494 return GNUNET_OK; 1482 return GNUNET_OK;
1495 } 1483 }
1496 plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL); 1484 plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
1497
1498 return GNUNET_OK; 1485 return GNUNET_OK;
1499} 1486}
1500 1487
@@ -1577,10 +1564,6 @@ libgnunet_plugin_transport_http_done (void *cls)
1577 cs = cs_next; 1564 cs = cs_next;
1578 } 1565 }
1579 1566
1580
1581
1582 /* GNUNET_SERVICE_stop (plugin->service); */
1583 GNUNET_free (hostname);
1584 GNUNET_free (plugin); 1567 GNUNET_free (plugin);
1585 GNUNET_free (api); 1568 GNUNET_free (api);
1586 return NULL; 1569 return NULL;
@@ -1595,29 +1578,15 @@ libgnunet_plugin_transport_http_init (void *cls)
1595{ 1578{
1596 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 1579 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1597 struct GNUNET_TRANSPORT_PluginFunctions *api; 1580 struct GNUNET_TRANSPORT_PluginFunctions *api;
1598 struct GNUNET_SERVICE_Context *service;
1599 unsigned int timeout; 1581 unsigned int timeout;
1600 struct GNUNET_TIME_Relative gn_timeout; 1582 struct GNUNET_TIME_Relative gn_timeout;
1601 long long unsigned int port; 1583 long long unsigned int port;
1602 1584
1603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); 1585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
1604 1586
1605 service = NULL;
1606 /*
1607 service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg);
1608 if (service == NULL)
1609 {
1610 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "", _
1611 ("Failed to start service for `%s' transport plugin.\n"),
1612 "http");
1613 return NULL;
1614 }
1615 */
1616
1617 plugin = GNUNET_malloc (sizeof (struct Plugin)); 1587 plugin = GNUNET_malloc (sizeof (struct Plugin));
1618 plugin->env = env; 1588 plugin->env = env;
1619 plugin->sessions = NULL; 1589 plugin->sessions = NULL;
1620 plugin->service = service;
1621 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 1590 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1622 api->cls = plugin; 1591 api->cls = plugin;
1623 api->send = &http_plugin_send; 1592 api->send = &http_plugin_send;
@@ -1626,8 +1595,6 @@ libgnunet_plugin_transport_http_init (void *cls)
1626 api->check_address = &http_plugin_address_suggested; 1595 api->check_address = &http_plugin_address_suggested;
1627 api->address_to_string = &http_plugin_address_to_string; 1596 api->address_to_string = &http_plugin_address_to_string;
1628 1597
1629 hostname = GNUNET_RESOLVER_local_fqdn_get ();
1630
1631 /* Hashing our identity to use it in URLs */ 1598 /* Hashing our identity to use it in URLs */
1632 GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident); 1599 GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident);
1633 1600
@@ -1647,6 +1614,10 @@ libgnunet_plugin_transport_http_init (void *cls)
1647 libgnunet_plugin_transport_http_done (api); 1614 libgnunet_plugin_transport_http_done (api);
1648 return NULL; 1615 return NULL;
1649 } 1616 }
1617
1618 GNUNET_assert ((port > 0) && (port <= 65535));
1619 GNUNET_assert (&my_ascii_hash_ident != NULL);
1620
1650 plugin->port_inbound = port; 1621 plugin->port_inbound = port;
1651 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; 1622 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
1652 timeout = ( gn_timeout.value / 1000); 1623 timeout = ( gn_timeout.value / 1000);
@@ -1682,9 +1653,14 @@ libgnunet_plugin_transport_http_init (void *cls)
1682 1653
1683 if (http_task_v4 != GNUNET_SCHEDULER_NO_TASK) 1654 if (http_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); 1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port);
1685 if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) 1656 else if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); 1657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
1687 1658 else
1659 {
1660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No MHD was started, transport plugin not functional!\n");
1661 libgnunet_plugin_transport_http_done (api);
1662 return NULL;
1663 }
1688 1664
1689 /* Initializing cURL */ 1665 /* Initializing cURL */
1690 multi_handle = curl_multi_init(); 1666 multi_handle = curl_multi_init();
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 882560745..468a2c883 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -351,18 +351,26 @@ shutdown_clean ()
351 struct Plugin_Address * tmp; 351 struct Plugin_Address * tmp;
352 352
353 /* Evaluate results */ 353 /* Evaluate results */
354 if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) && 354 fail = 0;
355 (test_no_ident.test_failed == GNUNET_NO) && (test_too_short_ident.test_failed == GNUNET_NO) && (test_too_long_ident.test_failed == GNUNET_NO) && 355 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
356 (test_valid_ident.test_failed == GNUNET_NO) && (fail_msgs_transmited_to_local_addrs == count_str_addr))
357 { 356 {
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests successful\n"); 357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test plugin functions failed\n");
359 fail = 0; 358 fail = 1;
360 } 359 }
361 else 360 if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_ident.test_failed == GNUNET_YES))
361 {
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data failed\n");
363 fail = 1;
364 }
365 if ((test_valid_ident.test_failed == GNUNET_YES) || (fail_msgs_transmited_to_local_addrs != count_str_addr))
362 { 366 {
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests failed\n"); 367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n");
364 fail = 1; 368 fail = 1;
365 } 369 }
370 if (fail != 1)
371 {
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
373 }
366 374
367 curl_multi_cleanup(multi_handle); 375 curl_multi_cleanup(multi_handle);
368 376
@@ -873,16 +881,15 @@ static void run_connection_tests( void )
873 if (test_no_ident.test_executed == GNUNET_NO) 881 if (test_no_ident.test_executed == GNUNET_NO)
874 { 882 {
875 /* Connecting to peer without identification */ 883 /* Connecting to peer without identification */
884
876 host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1); 885 host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1);
877 GNUNET_asprintf (&host_str, "http://localhost:%u/",port); 886 GNUNET_asprintf (&host_str, "http://localhost:%u/",port);
878 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n")); 887 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"));
879 test_no_ident.test_executed = GNUNET_YES; 888 test_no_ident.test_executed = GNUNET_YES;
880 send_data ( &test_no_ident, host_str); 889 send_data ( &test_no_ident, host_str);
881 GNUNET_free (host_str); 890 GNUNET_free (host_str);
882
883 return; 891 return;
884 } 892 }
885
886 if (test_too_short_ident.test_executed == GNUNET_NO) 893 if (test_too_short_ident.test_executed == GNUNET_NO)
887 { 894 {
888 char * ident = "AAAAAAAAAA"; 895 char * ident = "AAAAAAAAAA";
@@ -893,7 +900,6 @@ static void run_connection_tests( void )
893 test_too_short_ident.test_executed = GNUNET_YES; 900 test_too_short_ident.test_executed = GNUNET_YES;
894 send_data ( &test_too_short_ident, host_str); 901 send_data ( &test_too_short_ident, host_str);
895 GNUNET_free (host_str); 902 GNUNET_free (host_str);
896
897 return; 903 return;
898 } 904 }
899 905
@@ -904,18 +910,15 @@ static void run_connection_tests( void )
904 /* Connecting to peer with too long identification */ 910 /* Connecting to peer with too long identification */
905 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); 911 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident));
906 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); 912 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
907
908 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n")); 913 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"));
909 test_too_long_ident.test_executed = GNUNET_YES; 914 test_too_long_ident.test_executed = GNUNET_YES;
910 send_data ( &test_too_long_ident, host_str); 915 send_data ( &test_too_long_ident, host_str);
911 GNUNET_free (host_str); 916 GNUNET_free (host_str);
912
913 return; 917 return;
914 } 918 }
915 if (test_valid_ident.test_executed == GNUNET_NO) 919 if (test_valid_ident.test_executed == GNUNET_NO)
916 { 920 {
917 struct GNUNET_CRYPTO_HashAsciiEncoded result; 921 struct GNUNET_CRYPTO_HashAsciiEncoded result;
918
919 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result); 922 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result);
920 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result)); 923 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result));
921 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result); 924 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result);
@@ -924,7 +927,6 @@ static void run_connection_tests( void )
924 test_valid_ident.test_executed = GNUNET_YES; 927 test_valid_ident.test_executed = GNUNET_YES;
925 send_data ( &test_valid_ident, host_str); 928 send_data ( &test_valid_ident, host_str);
926 GNUNET_free (host_str); 929 GNUNET_free (host_str);
927
928 return; 930 return;
929 } 931 }
930 /* Using one of the addresses the plugin proposed */ 932 /* Using one of the addresses the plugin proposed */
@@ -1027,7 +1029,7 @@ run (void *cls,
1027 "transport-http", 1029 "transport-http",
1028 "PORT", 1030 "PORT",
1029 &port)) || 1031 &port)) ||
1030 (port > 65535) ) 1032 (port > 65535) || (port == 0))
1031 { 1033 {
1032 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1034 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1033 "http", 1035 "http",
@@ -1035,6 +1037,7 @@ run (void *cls,
1035 ("Require valid port number for transport plugin `%s' in configuration!\n"), 1037 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1036 "transport-http"); 1038 "transport-http");
1037 } 1039 }
1040
1038 max_connect_per_transport = (uint32_t) tneigh; 1041 max_connect_per_transport = (uint32_t) tneigh;
1039 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1042 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1040 GNUNET_free (keyfile); 1043 GNUNET_free (keyfile);
@@ -1046,9 +1049,14 @@ run (void *cls,
1046 fail = 1; 1049 fail = 1;
1047 return; 1050 return;
1048 } 1051 }
1052
1049 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 1053 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1050 GNUNET_CRYPTO_hash (&my_public_key, 1054 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey);
1051 sizeof (my_public_key), &my_identity.hashPubKey); 1055
1056 /* assertions before start */
1057 GNUNET_assert ((port > 0) && (port <= 65535));
1058 GNUNET_assert(&my_public_key != NULL);
1059 GNUNET_assert(&my_identity.hashPubKey != NULL);
1052 1060
1053 /* load plugins... */ 1061 /* load plugins... */
1054 setup_plugin_environment (); 1062 setup_plugin_environment ();