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 "plugin_transport.h"
37 #include "gnunet_statistics_service.h"
38 #include "transport.h"
40 #define VERBOSE GNUNET_YES
41 #define DEBUG GNUNET_YES
44 * How long until we give up on transmitting the message?
46 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
51 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
56 static struct GNUNET_PeerIdentity my_identity;
61 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
66 struct GNUNET_SCHEDULER_Handle *sched;
69 * Our statistics handle.
71 struct GNUNET_STATISTICS_Handle *stats;
77 const struct GNUNET_CONFIGURATION_Handle *cfg;
80 * Number of neighbours we'd like to have.
82 static uint32_t max_connect_per_transport;
85 * Environment for this plugin.
87 struct GNUNET_TRANSPORT_PluginEnvironment env;
90 *handle for the api provided by this plugin
92 struct GNUNET_TRANSPORT_PluginFunctions *api;
95 * Did the test pass or fail?
99 static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
102 * Initialize Environment for this plugin
104 static struct GNUNET_TIME_Relative
106 const struct GNUNET_PeerIdentity * peer,
107 const struct GNUNET_MessageHeader * message,
109 struct Session *session,
110 const char *sender_address,
111 uint16_t sender_address_len)
114 return GNUNET_TIME_UNIT_ZERO;
118 notify_address (void *cls,
122 struct GNUNET_TIME_Relative expires)
127 * Function called when the service shuts
128 * down. Unloads our plugins.
131 * @param cfg configuration to use
134 unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
136 GNUNET_assert (NULL ==
137 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
139 if (my_private_key != NULL)
140 GNUNET_CRYPTO_rsa_key_free (my_private_key);
144 * Simple example test that invokes
145 * the check_address function of the plugin.
147 /* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
148 * isn't enabled (eg. FreeBSD > 4)
153 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
154 GNUNET_SCHEDULER_cancel( sched, timeout_task );
155 unload_plugins(env.cls, env.cfg);
162 timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164 timeout_task = GNUNET_SCHEDULER_NO_TASK;
165 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
167 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 "Timeout while executing testcase, test failed.\n");
169 /* FIXME : correct it to fail = GNUNET_YES;*/
175 setup_plugin_environment ()
180 env.my_identity = &my_identity;
182 env.receive = &receive;
183 env.notify_address = ¬ify_address;
184 env.max_connections = max_connect_per_transport;
191 * @param s scheduler to use
192 * @param c configuration to use
196 struct GNUNET_SCHEDULER_Handle *s,
198 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
200 unsigned long long tneigh;
207 timeout_task = GNUNET_SCHEDULER_add_delayed ( sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &timeout_error, NULL);
208 /* parse configuration */
210 GNUNET_CONFIGURATION_get_value_number (c,
215 GNUNET_CONFIGURATION_get_value_filename (c,
217 "HOSTKEY", &keyfile)))
219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
220 _("Transport service is lacking key configuration settings. Exiting.\n"));
221 GNUNET_SCHEDULER_shutdown (s);
226 stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
229 max_connect_per_transport = (uint32_t) tneigh;
230 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
232 GNUNET_free (keyfile);
234 if (my_private_key == NULL)
236 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
238 ("Transport service could not access hostkey. Exiting.\n"));
239 GNUNET_SCHEDULER_shutdown (s);
242 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
243 GNUNET_CRYPTO_hash (&my_public_key,
244 sizeof (my_public_key), &my_identity.hashPubKey);*/
246 /* load plugins... */
247 setup_plugin_environment ();
249 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
251 api = GNUNET_PLUGIN_load (libname, &env);
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Loading http transport plugin `%s' was successful\n",libname);
256 GNUNET_free (libname);
259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
260 _("Failed to load http transport plugin\n"));
266 // shutdown_clean ();
271 * The main function for the transport service.
273 * @param argc number of arguments from the command line
274 * @param argv command line arguments
275 * @return 0 ok, 1 on error
278 main (int argc, char *const *argv)
280 static struct GNUNET_GETOPT_CommandLineOption options[] = {
281 GNUNET_GETOPT_OPTION_END
284 char *const argv_prog[] = {
285 "test-gnunetd-plugin-transport_http",
287 "test_plugin_transport_data_http.conf",
296 GNUNET_log_setup ("test-gnunetd-plugin-transport_http",
305 GNUNET_PROGRAM_run (5,
307 "test-plugin-transport_http",
308 "testcase", options, &run, NULL)) ? fail : 1;
309 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport_http");
314 /* end of test_plugin_transport_http.c */