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"
40 #include <curl/curl.h>
42 #define VERBOSE GNUNET_YES
43 #define DEBUG GNUNET_YES
45 #define PLUGIN libgnunet_plugin_transport_template
48 * How long until we give up on transmitting the message?
50 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
53 * How long until we give up on transmitting the message?
55 #define STAT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
60 /* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
65 static struct GNUNET_PeerIdentity my_identity;
71 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
77 struct GNUNET_SCHEDULER_Handle *sched;
80 * Our statistics handle.
82 struct GNUNET_STATISTICS_Handle *stats;
88 const struct GNUNET_CONFIGURATION_Handle *cfg;
91 * Number of neighbours we'd like to have.
93 static uint32_t max_connect_per_transport;
96 * Environment for this plugin.
98 static struct GNUNET_TRANSPORT_PluginEnvironment env;
101 *handle for the api provided by this plugin
103 static struct GNUNET_TRANSPORT_PluginFunctions *api;
106 * ID of the task controlling the locking between two hostlist tests
108 static GNUNET_SCHEDULER_TaskIdentifier ti_check_stat;
110 static struct GNUNET_STATISTICS_GetHandle * stat_get_handle;
112 static unsigned int timeout_count;
115 * Did the test pass or fail?
122 * Initialize Environment for this plugin
124 static struct GNUNET_TIME_Relative
126 const struct GNUNET_PeerIdentity * peer,
127 const struct GNUNET_MessageHeader * message,
129 struct Session *session,
130 const char *sender_address,
131 uint16_t sender_address_len)
134 return GNUNET_TIME_UNIT_ZERO;
138 notify_address (void *cls,
142 struct GNUNET_TIME_Relative expires)
148 * Simple example test that invokes
149 * the check_address function of the plugin.
151 /* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
152 * isn't enabled (eg. FreeBSD > 4)
157 /* if (stat_get_handle != NULL)
159 GNUNET_STATISTICS_get_cancel(stat_get_handle);
162 // if ( NULL!=stats )GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
163 if (ti_check_stat != GNUNET_SCHEDULER_NO_TASK)
164 GNUNET_SCHEDULER_cancel(sched,ti_check_stat);
165 ti_check_stat = GNUNET_SCHEDULER_NO_TASK;
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
168 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", api));
170 GNUNET_SCHEDULER_shutdown(sched);
171 /* FIXME: */ fail = GNUNET_NO;
176 setup_plugin_environment ()
181 env.my_identity = &my_identity;
183 env.receive = &receive;
184 env.notify_address = ¬ify_address;
185 env.max_connections = max_connect_per_transport;
189 process_stat (void *cls,
190 const char *subsystem,
195 stat_get_handle = NULL;
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin failed \n");
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin not failed \n");
213 cont_func (void *cls, int success)
215 stat_get_handle = NULL;
219 * Task that checks if we should try to download a hostlist.
220 * If so, we initiate the download, otherwise we schedule
221 * this task again for a later time.
224 task_check_stat (void *cls,
225 const struct GNUNET_SCHEDULER_TaskContext *tc)
227 ti_check_stat = GNUNET_SCHEDULER_NO_TASK;
228 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
231 if ( timeout_count > 2 )
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n", timeout_count);
240 /* stat_get_handle = GNUNET_STATISTICS_get (stats,
242 gettext_noop("shutdown"),
243 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
248 ti_check_stat = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, &task_check_stat, NULL);
256 * @param s scheduler to use
257 * @param c configuration to use
261 struct GNUNET_SCHEDULER_Handle *s,
263 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
269 /* settings up statistics */
270 /* stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
273 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
274 _("Failed to retrieve statistics handle\n"));
280 /* load plugins... */
281 setup_plugin_environment ();
282 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin `%s'\n"),"libgnunet_plugin_transport_http");
283 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
284 api = GNUNET_PLUGIN_load (libname, &env);
285 GNUNET_free (libname);
288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
289 _("Failed to load transport plugin for http\n"));
294 ti_check_stat = GNUNET_SCHEDULER_add_now (sched, &task_check_stat, NULL);
299 * The main function for the transport service.
301 * @param argc number of arguments from the command line
302 * @param argv command line arguments
303 * @return 0 ok, 1 on error
306 main (int argc, char *const *argv)
309 static struct GNUNET_GETOPT_CommandLineOption options[] = {
310 GNUNET_GETOPT_OPTION_END
313 char *const argv_prog[] = {
314 "test_plugin_transport_http",
316 "test_plugin_transport_data_http.conf",
325 GNUNET_log_setup ("test_plugin_transport_http",
332 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting statistics service\n");
333 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
334 "gnunet-service-statistics",
336 "-c", "test_plugin_transport_data_http.conf", NULL);
341 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to start statistics service\n");
347 GNUNET_PROGRAM_run (5,
349 "test_plugin_transport_http",
350 "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES;
351 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
353 if (0 != PLIBC_KILL (pid, SIGTERM))
355 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "Failed to kill statistics service");
358 if (GNUNET_OS_process_wait(pid) != GNUNET_OK)
359 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
360 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Killed statistics service\n");
364 /* end of test_plugin_transport_http.c */