2 This file is part of GNUnet.
3 (C) 2010,2011 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 3, 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.
22 * @file transport/gnunet-service-transport-new.c
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_peerinfo_service.h"
31 #include "gnunet-service-transport.h"
32 #include "gnunet-service-transport_ats-new.h"
33 #include "gnunet-service-transport_blacklist.h"
34 #include "gnunet-service-transport_clients.h"
35 #include "gnunet-service-transport_hello.h"
36 #include "gnunet-service-transport_neighbours.h"
37 #include "gnunet-service-transport_plugins.h"
38 #include "gnunet-service-transport_validation.h"
45 struct GNUNET_STATISTICS_Handle *GST_stats;
48 * Configuration handle.
50 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
53 * Configuration handle.
55 struct GNUNET_PeerIdentity GST_my_identity;
58 * Handle to peerinfo service.
60 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
65 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded GST_my_public_key;
70 struct GNUNET_CRYPTO_RsaPrivateKey *GST_my_private_key;
75 struct GST_AtsHandle *GST_ats;
79 * My HELLO has changed. Tell everyone who should know.
82 * @param hello new HELLO
85 process_hello_update (void *cls,
86 const struct GNUNET_MessageHeader *hello)
88 GST_clients_broadcast (hello, GNUNET_NO);
90 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
91 &transmit_our_hello_if_pong,
98 * Function that will be called for each address the transport
99 * is aware that it might be reachable under. Update our HELLO.
101 * @param cls name of the plugin (const char*)
102 * @param add_remove should the address added (YES) or removed (NO) from the
103 * set of valid addresses?
104 * @param addr one of the addresses of the host
105 * the specific address format depends on the transport
106 * @param addrlen length of the address
109 plugin_env_address_change_notification (void *cls,
114 const char *plugin_name = cls;
116 GST_hello_modify_addresses (add_remove,
124 * Function called when the service shuts down. Unloads our plugins
125 * and cancels pending validations.
127 * @param cls closure, unused
128 * @param tc task context (unused)
131 shutdown_task (void *cls,
132 const struct GNUNET_SCHEDULER_TaskContext *tc)
134 GST_validation_stop ();
135 GST_neighbours_stop ();
136 GST_ats_shutdown (GST_ats); GST_ats = NULL;
138 GST_blacklist_stop ();
139 GST_plugins_unload ();
142 if (GST_peerinfo != NULL)
144 GNUNET_PEERINFO_disconnect (GST_peerinfo);
147 if (GST_stats != NULL)
149 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
152 if (GST_my_private_key != NULL)
154 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key);
155 GST_my_private_key = NULL;
161 * Initiate transport service.
164 * @param server the initialized server
165 * @param c configuration to use
169 struct GNUNET_SERVER_Handle *server,
170 const struct GNUNET_CONFIGURATION_Handle *c)
173 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
182 GNUNET_CONFIGURATION_get_value_filename (c,
184 "HOSTKEY", &keyfile))
186 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
188 ("Transport service is lacking key configuration settings. Exiting.\n"));
189 GNUNET_SCHEDULER_shutdown ();
192 GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
193 GNUNET_free (keyfile);
194 if (GST_my_private_key == NULL)
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 _("Transport service could not access hostkey. Exiting.\n"));
198 GNUNET_SCHEDULER_shutdown ();
201 GST_stats = GNUNET_STATISTICS_create ("transport", c);
202 GST_peerinfo = GNUNET_PEERINFO_connect (c);
203 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
204 GNUNET_CRYPTO_hash (&GST_my_public_key,
205 sizeof (GST_my_public_key), &GST_my_identity.hashPubKey);
206 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
207 &shutdown_task, NULL);
208 if (GST_peerinfo == NULL)
210 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
211 _("Could not access PEERINFO service. Exiting.\n"));
212 GNUNET_SCHEDULER_shutdown ();
216 /* start subsystems */
217 GST_hello_start (&process_hello_update, NULL);
218 GST_blacklist_start (server);
219 GST_plugins_load (NULL, // FIXME...
220 &plugin_env_address_change_notification,
224 GST_ats = GST_ats_init (GST_cfg,
227 GST_neighbours_start (NULL, // FIXME...
230 GST_clients_start (server);
231 GST_validation_start ();
236 * The main function for the transport service.
238 * @param argc number of arguments from the command line
239 * @param argv command line arguments
240 * @return 0 ok, 1 on error
243 main (int argc, char *const *argv)
246 GNUNET_SERVICE_run (argc,
249 GNUNET_SERVICE_OPTION_NONE,
250 &run, NULL)) ? 0 : 1;
253 /* end of file gnunet-service-transport-new.c */