2 This file is part of GNUnet.
3 (C) 2009 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_transport_api.c
22 * @brief testcase for transport_api.c
23 * @author Sailor Siraj
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_service_lib.h"
35 #include "gnunet_signatures.h"
36 #include "plugin_transport.h"
37 #include "transport.h"
42 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *my_public_key;
47 static struct GNUNET_PeerIdentity my_identity;
52 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
57 struct GNUNET_SCHEDULER_Handle *sched;
62 struct GNUNET_CONFIGURATION_Handle *cfg;
69 static struct TransportPlugin *plugins;
74 static struct GNUNET_SERVER_Handle *server;
79 * Number of neighbours we'd like to have.
81 static uint32_t max_connect_per_transport;
84 * Environment for this plugin.
86 struct GNUNET_TRANSPORT_PluginEnvironment env;
89 *handle for the api provided by this plugin
91 struct GNUNET_TRANSPORT_PluginFunctions *api;
94 * Initialize Environment for this plugin
97 receive(void *cls,void *plugin_context,
100 struct GNUNET_TIME_Relative
102 const struct GNUNET_PeerIdentity
104 const struct GNUNET_MessageHeader
110 void notify_address(void *cls,
120 void lookup (void *cls,
121 struct GNUNET_TIME_Relative
124 GNUNET_PeerIdentity * target,
125 GNUNET_TRANSPORT_AddressCallback
126 iter, void *iter_cls)
131 static void setup_plugin_environment()
135 env.my_public_key = my_public_key;
137 env.receive=&receive;
139 env.notify_address=¬ify_address;
140 env.max_connections = max_connect_per_transport;
145 * Initiate transport service.
148 * @param s scheduler to use
149 * @param serv the initialized server
150 * @param c configuration to use
154 struct GNUNET_SCHEDULER_Handle *s,
155 struct GNUNET_SERVER_Handle *serv, struct GNUNET_CONFIGURATION_Handle *c)
157 unsigned long long tneigh;
164 /* parse configuration */
166 GNUNET_CONFIGURATION_get_value_number (c,
171 GNUNET_CONFIGURATION_get_value_filename (c,
173 "HOSTKEY", &keyfile)))
175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
176 _("Transport service is lacking key configuration settings. Exiting.\n"));
177 GNUNET_SCHEDULER_shutdown (s);
180 max_connect_per_transport = (uint32_t) tneigh;
181 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
182 GNUNET_free (keyfile);
183 if (my_private_key == NULL)
185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
186 _("Transport service could not access hostkey. Exiting.\n"));
187 GNUNET_SCHEDULER_shutdown (s);
190 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
191 GNUNET_CRYPTO_hash (&my_public_key,
192 sizeof (my_public_key), &my_identity.hashPubKey);
196 /* load plugins... */
197 setup_plugin_environment();
198 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
199 _("Loading tcp transport plugin\n"));
200 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp");
202 api = GNUNET_PLUGIN_load(libname, &env);
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 _("Failed to load transport plugin for tcp\n"));
213 * Function called when the service shuts
214 * down. Unloads our plugins.
217 * @param cfg configuration to use
220 unload_plugins (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg)
222 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",api));
223 if (my_private_key != NULL)
224 GNUNET_CRYPTO_rsa_key_free (my_private_key);
230 * The main function for the transport service.
232 * @param argc number of arguments from the command line
233 * @param argv command line arguments
234 * @return 0 ok, 1 on error
237 main (int argc, char *const *argv)
239 GNUNET_log_setup ("test-puglin-transport",
247 GNUNET_SERVICE_run (argc,
250 &run, NULL, &unload_plugins, NULL)) ? 0 : 1;
253 /* end of test_plugin_transport.c */