2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file transport/test_plugin_transport_http.c
22 * @brief testcase for plugin_transport_http.c
23 * @author Matthias Wachs
27 #include "gnunet_constants.h"
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "gnunet_plugin_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_program_lib.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_service_lib.h"
37 #include "plugin_transport.h"
38 #include "gnunet_statistics_service.h"
39 #include "transport.h"
41 #define VERBOSE GNUNET_YES
42 #define DEBUG GNUNET_YES
45 * How long until we give up on transmitting the message?
47 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
52 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
57 static struct GNUNET_PeerIdentity my_identity;
62 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
67 struct GNUNET_SCHEDULER_Handle *sched;
70 * Our statistics handle.
72 struct GNUNET_STATISTICS_Handle *stats;
78 const struct GNUNET_CONFIGURATION_Handle *cfg;
81 * Number of neighbours we'd like to have.
83 static uint32_t max_connect_per_transport;
86 * Environment for this plugin.
88 static struct GNUNET_TRANSPORT_PluginEnvironment env;
91 *handle for the api provided by this plugin
93 static struct GNUNET_TRANSPORT_PluginFunctions *api;
95 static struct GNUNET_SERVICE_Context *service;
98 * Did the test pass or fail?
102 static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
107 * Initialize Environment for this plugin
109 static struct GNUNET_TIME_Relative
111 const struct GNUNET_PeerIdentity * peer,
112 const struct GNUNET_MessageHeader * message,
114 struct Session *session,
115 const char *sender_address,
116 uint16_t sender_address_len)
119 return GNUNET_TIME_UNIT_ZERO;
123 notify_address (void *cls,
127 struct GNUNET_TIME_Relative expires)
132 * Function called when the service shuts
133 * down. Unloads our plugins.
136 * @param cfg configuration to use
139 unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
141 GNUNET_assert (NULL ==
142 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
144 if (my_private_key != NULL)
145 GNUNET_CRYPTO_rsa_key_free (my_private_key);
149 * Simple example test that invokes
150 * the check_address function of the plugin.
152 /* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
153 * isn't enabled (eg. FreeBSD > 4)
158 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
159 GNUNET_SCHEDULER_cancel( sched, timeout_task );
160 if (NULL != service) GNUNET_SERVICE_stop (service);
161 if (0 != PLIBC_KILL (pid, SIGTERM))
163 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
166 unload_plugins(env.cls, env.cfg);
173 timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 timeout_task = GNUNET_SCHEDULER_NO_TASK;
176 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
179 "Timeout while executing testcase, test failed.\n");
180 /* FIXME : correct it to fail = GNUNET_YES;*/
186 setup_plugin_environment ()
191 env.my_identity = &my_identity;
193 env.receive = &receive;
194 env.notify_address = ¬ify_address;
195 env.max_connections = max_connect_per_transport;
199 process_stat (void *cls,
200 const char *subsystem,
205 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
206 _("Value: %llums\n"),
207 (unsigned long long) value);
216 * @param s scheduler to use
217 * @param c configuration to use
221 struct GNUNET_SCHEDULER_Handle *s,
223 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
225 unsigned long long tneigh;
232 timeout_task = GNUNET_SCHEDULER_add_delayed ( sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &timeout_error, NULL);
233 /* parse configuration */
235 GNUNET_CONFIGURATION_get_value_number (c,
240 GNUNET_CONFIGURATION_get_value_filename (c,
242 "HOSTKEY", &keyfile)))
244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
245 _("Transport service is lacking key configuration settings. Exiting.\n"));
246 GNUNET_SCHEDULER_shutdown (s);
250 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
251 "gnunet-service-statistics",
253 "-c", "test_plugin_transport_data_http.conf", NULL);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 _("Failed to start service for `%s' http transport plugin test.\n"),
266 stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
269 GNUNET_STATISTICS_get (stats,
271 gettext_noop("# PUT requests"),
272 GNUNET_TIME_UNIT_MINUTES,
277 max_connect_per_transport = (uint32_t) tneigh;
278 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
279 GNUNET_free (keyfile);
281 if (my_private_key == NULL)
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
285 ("Transport service could not access hostkey. Exiting.\n"));
286 GNUNET_SCHEDULER_shutdown (s);
289 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
290 GNUNET_CRYPTO_hash (&my_public_key,
291 sizeof (my_public_key), &my_identity.hashPubKey);*/
293 /* load plugins... */
294 setup_plugin_environment ();
296 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
298 api = GNUNET_PLUGIN_load (libname, &env);
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
301 "Loading http transport plugin `%s' was successful\n",libname);
303 GNUNET_free (libname);
306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
307 _("Failed to load http transport plugin\n"));
314 // shutdown_clean ();
319 * The main function for the transport service.
321 * @param argc number of arguments from the command line
322 * @param argv command line arguments
323 * @return 0 ok, 1 on error
326 main (int argc, char *const *argv)
328 static struct GNUNET_GETOPT_CommandLineOption options[] = {
329 GNUNET_GETOPT_OPTION_END
333 char *const argv_prog[] = {
334 "test_plugin_transport_http",
336 "test_plugin_transport_data_http.conf",
345 GNUNET_log_setup ("test_plugin_transport_http",
354 GNUNET_PROGRAM_run (5,
356 "test_plugin_transport_http",
357 "testcase", options, &run, NULL)) ? fail : 1;
358 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
363 /* end of test_plugin_transport_http.c */