*/
struct GNUNET_TRANSPORT_PluginEnvironment *env;
- /**
- * Handle to the network service.
- */
- struct GNUNET_SERVICE_Context *service;
-
unsigned int port_inbound;
/**
*/
static CURLM *multi_handle;
-/**
- * Our hostname
- */
-static char * hostname;
-
/**
* Our ASCII encoded, hashed peer identity
* This string is used to distinguish between connections and is added to the urls
void *arg;
uint16_t args;
-
-
af = addr->sa_family;
if (af == AF_INET)
{
return GNUNET_OK;
}
plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
-
return GNUNET_OK;
}
cs = cs_next;
}
-
-
- /* GNUNET_SERVICE_stop (plugin->service); */
- GNUNET_free (hostname);
GNUNET_free (plugin);
GNUNET_free (api);
return NULL;
{
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
- struct GNUNET_SERVICE_Context *service;
unsigned int timeout;
struct GNUNET_TIME_Relative gn_timeout;
long long unsigned int port;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
- service = NULL;
- /*
- service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg);
- if (service == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "", _
- ("Failed to start service for `%s' transport plugin.\n"),
- "http");
- return NULL;
- }
- */
-
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
plugin->sessions = NULL;
- plugin->service = service;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
api->send = &http_plugin_send;
api->check_address = &http_plugin_address_suggested;
api->address_to_string = &http_plugin_address_to_string;
- hostname = GNUNET_RESOLVER_local_fqdn_get ();
-
/* Hashing our identity to use it in URLs */
GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident);
libgnunet_plugin_transport_http_done (api);
return NULL;
}
+
+ GNUNET_assert ((port > 0) && (port <= 65535));
+ GNUNET_assert (&my_ascii_hash_ident != NULL);
+
plugin->port_inbound = port;
gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
timeout = ( gn_timeout.value / 1000);
if (http_task_v4 != GNUNET_SCHEDULER_NO_TASK)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port);
- if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
+ else if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
-
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No MHD was started, transport plugin not functional!\n");
+ libgnunet_plugin_transport_http_done (api);
+ return NULL;
+ }
/* Initializing cURL */
multi_handle = curl_multi_init();
struct Plugin_Address * tmp;
/* 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) && (fail_msgs_transmited_to_local_addrs == count_str_addr))
+ fail = 0;
+ if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests successful\n");
- fail = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test plugin functions failed\n");
+ fail = 1;
}
- else
+ if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_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))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tests failed\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n");
fail = 1;
}
+ if (fail != 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
+ }
curl_multi_cleanup(multi_handle);
if (test_no_ident.test_executed == GNUNET_NO)
{
/* Connecting to peer without identification */
+
host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1);
GNUNET_asprintf (&host_str, "http://localhost:%u/",port);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"));
test_no_ident.test_executed = GNUNET_YES;
send_data ( &test_no_ident, host_str);
GNUNET_free (host_str);
-
return;
}
-
if (test_too_short_ident.test_executed == GNUNET_NO)
{
char * ident = "AAAAAAAAAA";
test_too_short_ident.test_executed = GNUNET_YES;
send_data ( &test_too_short_ident, host_str);
GNUNET_free (host_str);
-
return;
}
/* Connecting to peer with too long identification */
host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident));
GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"));
test_too_long_ident.test_executed = GNUNET_YES;
send_data ( &test_too_long_ident, host_str);
GNUNET_free (host_str);
-
return;
}
if (test_valid_ident.test_executed == GNUNET_NO)
{
struct GNUNET_CRYPTO_HashAsciiEncoded result;
-
GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result);
host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result));
GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result);
test_valid_ident.test_executed = GNUNET_YES;
send_data ( &test_valid_ident, host_str);
GNUNET_free (host_str);
-
return;
}
/* Using one of the addresses the plugin proposed */
"transport-http",
"PORT",
&port)) ||
- (port > 65535) )
+ (port > 65535) || (port == 0))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"http",
("Require valid port number for transport plugin `%s' in configuration!\n"),
"transport-http");
}
+
max_connect_per_transport = (uint32_t) tneigh;
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
fail = 1;
return;
}
+
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
- GNUNET_CRYPTO_hash (&my_public_key,
- sizeof (my_public_key), &my_identity.hashPubKey);
+ GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey);
+
+ /* assertions before start */
+ GNUNET_assert ((port > 0) && (port <= 65535));
+ GNUNET_assert(&my_public_key != NULL);
+ GNUNET_assert(&my_identity.hashPubKey != NULL);
/* load plugins... */
setup_plugin_environment ();