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)
53 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
58 static struct GNUNET_PeerIdentity my_identity;
63 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
68 struct GNUNET_SCHEDULER_Handle *sched;
71 * Our statistics handle.
73 struct GNUNET_STATISTICS_Handle *stats;
79 const struct GNUNET_CONFIGURATION_Handle *cfg;
82 * Number of neighbours we'd like to have.
84 static uint32_t max_connect_per_transport;
87 * Environment for this plugin.
89 static struct GNUNET_TRANSPORT_PluginEnvironment env;
92 *handle for the api provided by this plugin
94 static struct GNUNET_TRANSPORT_PluginFunctions *api;
97 * Did the test pass or fail?
104 * Initialize Environment for this plugin
106 static struct GNUNET_TIME_Relative
108 const struct GNUNET_PeerIdentity * peer,
109 const struct GNUNET_MessageHeader * message,
111 struct Session *session,
112 const char *sender_address,
113 uint16_t sender_address_len)
116 return GNUNET_TIME_UNIT_ZERO;
120 notify_address (void *cls,
124 struct GNUNET_TIME_Relative expires)
129 * Simple example test that invokes
130 * the check_address function of the plugin.
132 /* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
133 * isn't enabled (eg. FreeBSD > 4)
138 GNUNET_assert (NULL ==
139 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
141 if (my_private_key != NULL)
142 GNUNET_CRYPTO_rsa_key_free (my_private_key);
143 GNUNET_SCHEDULER_shutdown(sched);
148 setup_plugin_environment ()
153 env.my_identity = &my_identity;
155 env.receive = &receive;
156 env.notify_address = ¬ify_address;
157 env.max_connections = max_connect_per_transport;
161 process_stat (void *cls,
162 const char *subsystem,
167 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
168 _("Value: %llums\n"),
169 (unsigned long long) value);
178 * @param s scheduler to use
179 * @param c configuration to use
183 struct GNUNET_SCHEDULER_Handle *s,
185 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
187 unsigned long long tneigh;
194 /* parse configuration */
196 GNUNET_CONFIGURATION_get_value_number (c,
201 GNUNET_CONFIGURATION_get_value_filename (c,
203 "HOSTKEY", &keyfile)))
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 _("Transport service is lacking key configuration settings. Exiting.\n"));
207 GNUNET_SCHEDULER_shutdown (s);
211 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
212 "gnunet-service-statistics",
214 "-c", "test_plugin_transport_data_http.conf", NULL);
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 _("Failed to start service for `%s' http transport plugin test.\n"),
222 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);
231 GNUNET_free (keyfile);
233 if (my_private_key == NULL)
235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
237 ("Transport service could not access hostkey. Exiting.\n"));
238 GNUNET_SCHEDULER_shutdown (s);
241 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
242 GNUNET_CRYPTO_hash (&my_public_key,
243 sizeof (my_public_key), &my_identity.hashPubKey);
245 /* load plugins... */
246 setup_plugin_environment ();
248 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
250 api = GNUNET_PLUGIN_load (libname, &env);
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Loading http transport plugin `%s' was successful\n",libname);
255 GNUNET_free (libname);
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 _("Failed to load http transport plugin\n"));
267 char * test_message = "Hello World!";
268 size_t size = strlen(test_message) +1;
270 /* Testing to send */
271 api->send(NULL, &my_identity,test_message,size,0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, NULL, NULL);
278 * The main function for the transport service.
280 * @param argc number of arguments from the command line
281 * @param argv command line arguments
282 * @return 0 ok, 1 on error
285 main (int argc, char *const *argv)
287 static struct GNUNET_GETOPT_CommandLineOption options[] = {
288 GNUNET_GETOPT_OPTION_END
291 char *const argv_prog[] = {
292 "test_plugin_transport_http",
294 "test_plugin_transport_data_http.conf",
303 GNUNET_log_setup ("test_plugin_transport_http",
312 GNUNET_PROGRAM_run (5,
314 "test_plugin_transport_http",
315 "testcase", options, &run, NULL)) ? fail : 1;
316 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
318 if (0 != PLIBC_KILL (pid, SIGTERM))
320 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
326 /* end of test_plugin_transport_http.c */