From 58cc7545c068d1deb7f7085822646313d5271b0f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 4 Aug 2011 12:58:58 +0000 Subject: [PATCH] draft --- src/transport/Makefile.am | 17 ++ src/transport/gnunet-service-transport-new.c | 157 ++++++++++++++++++ src/transport/gnunet-service-transport.h | 1 - .../gnunet-service-transport_blacklist.h | 1 - .../gnunet-service-transport_clients.h | 1 - .../gnunet-service-transport_neighbours.h | 6 +- .../gnunet-service-transport_plugins.h | 3 +- .../gnunet-service-transport_validation.h | 9 +- 8 files changed, 183 insertions(+), 12 deletions(-) create mode 100644 src/transport/gnunet-service-transport-new.c diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 6a870c6b0..e004d9c00 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -86,6 +86,7 @@ bin_PROGRAMS = \ gnunet-transport \ $(WLAN_BIN) \ gnunet-service-transport \ + gnunet-service-transport-new \ gnunet-transport-list-connections \ gnunet-transport-certificate-creation @@ -146,6 +147,22 @@ gnunet_service_transport_LDADD = \ $(GN_GLPK) \ $(GN_LIBINTL) +gnunet_service_transport_new_SOURCES = \ + gnunet-service-transport-new.c gnunet-service-transport.h \ + gnunet-service-transport_blacklist.h \ + gnunet-service-transport_clients.h \ + gnunet-service-transport_hello.h \ + gnunet-service-transport_neighbours.h \ + gnunet-service-transport_plugins.h \ + gnunet-service-transport_validation.h +gnunet_service_transport_new_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_GLPK) \ + $(GN_LIBINTL) + plugin_LTLIBRARIES = \ libgnunet_plugin_transport_tcp.la \ libgnunet_plugin_transport_udp.la \ diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c new file mode 100644 index 000000000..c039d5963 --- /dev/null +++ b/src/transport/gnunet-service-transport-new.c @@ -0,0 +1,157 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file transport/gnunet-service-transport-new.c + * @brief + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_statistics_service.h" +#include "gnunet_transport_service.h" +#include "gnunet-service-transport.h" +#include "gnunet-service-transport_blacklist.h" +#include "gnunet-service-transport_clients.h" +#include "gnunet-service-transport_hello.h" +#include "gnunet-service-transport_neighbours.h" +#include "gnunet-service-transport_plugins.h" +#include "gnunet-service-transport_validation.h" + +/* globals */ + +/** + * Statistics handle. + */ +struct GNUNET_STATISTICS_Handle *GST_stats; + +/** + * Configuration handle. + */ +const struct GNUNET_CONFIGURATION_Handle *GST_cfg; + +/** + * Configuration handle. + */ +struct GNUNET_PeerIdentity GST_my_identity; + +/** + * Our private key. + */ +static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; + +/** + * Our public key. + */ +static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; + +/** + * Function called when the service shuts down. Unloads our plugins + * and cancels pending validations. + * + * @param cls closure, unused + * @param tc task context (unused) + */ +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (GST_stats != NULL) + { + GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); + GST_stats = NULL; + } + if (my_private_key != NULL) + { + GNUNET_CRYPTO_rsa_key_free (my_private_key); + my_private_key = NULL; + } +} + + +/** + * Initiate transport service. + * + * @param cls closure + * @param server the initialized server + * @param c configuration to use + */ +static void +run (void *cls, + struct GNUNET_SERVER_Handle *server, + const struct GNUNET_CONFIGURATION_Handle *c) +{ +#if 0 + static const struct GNUNET_SERVER_MessageHandler handlers[] = { + {NULL, NULL, 0, 0} + }; +#endif + char *keyfile; + + /* setup globals */ + GST_cfg = c; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_filename (c, + "GNUNETD", + "HOSTKEY", &keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ + ("Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_free (keyfile); + if (my_private_key == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Transport service could not access hostkey. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + GST_stats = GNUNET_STATISTICS_create ("transport", c); + GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); + GNUNET_CRYPTO_hash (&my_public_key, + sizeof (my_public_key), &GST_my_identity.hashPubKey); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, NULL); +} + + +/** + * The main function for the transport service. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + return (GNUNET_OK == + GNUNET_SERVICE_run (argc, + argv, + "transport", + GNUNET_SERVICE_OPTION_NONE, + &run, NULL)) ? 0 : 1; +} + +/* end of file gnunet-service-transport-new.c */ diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index 544b60507..8db60d707 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h @@ -27,7 +27,6 @@ #define GNUNET_SERVICE_TRANSPORT_H #include "gnunet_statistics_service.h" -#include "gnunet_transport_plugins.h" #include "gnunet_transport_service.h" #include "gnunet_util_lib.h" diff --git a/src/transport/gnunet-service-transport_blacklist.h b/src/transport/gnunet-service-transport_blacklist.h index e1674ead3..1d10846ea 100644 --- a/src/transport/gnunet-service-transport_blacklist.h +++ b/src/transport/gnunet-service-transport_blacklist.h @@ -27,7 +27,6 @@ #define GNUNET_SERVICE_TRANSPORT_BLACKLIST_H #include "gnunet_statistics_service.h" -#include "gnunet_transport_blacklist.h" #include "gnunet_util_lib.h" /** diff --git a/src/transport/gnunet-service-transport_clients.h b/src/transport/gnunet-service-transport_clients.h index 299d75857..1884ece5d 100644 --- a/src/transport/gnunet-service-transport_clients.h +++ b/src/transport/gnunet-service-transport_clients.h @@ -27,7 +27,6 @@ #define GNUNET_SERVICE_TRANSPORT_CLIENTS_H #include "gnunet_statistics_service.h" -#include "gnunet_transport_clients.h" #include "gnunet_util_lib.h" diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 18134fd33..c627e7e2f 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -77,7 +77,7 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, * */ int -GST_neighbours_handle_pong (const GNUNET_PeerIdentity *sender, +GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, const char *plugin_name, const void *sender_address, @@ -87,7 +87,7 @@ GST_neighbours_handle_pong (const GNUNET_PeerIdentity *sender, * */ int -GST_neighbours_handle_connect (const GNUNET_PeerIdentity *sender, +GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, const char *plugin_name, const void *sender_address, @@ -97,7 +97,7 @@ GST_neighbours_handle_connect (const GNUNET_PeerIdentity *sender, * */ int -GST_neighbours_handle_disconnect (const GNUNET_PeerIdentity *sender, +GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, const char *plugin_name, const void *sender_address, diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h index ad8746b4c..0d62bbf79 100644 --- a/src/transport/gnunet-service-transport_plugins.h +++ b/src/transport/gnunet-service-transport_plugins.h @@ -27,7 +27,8 @@ #define GNUNET_SERVICE_TRANSPORT_PLUGINS_H #include "gnunet_statistics_service.h" -#include "gnunet_transport_plugins.h" +#include "gnunet_transport_service.h" +#include "gnunet_transport_plugin.h" #include "gnunet_util_lib.h" diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index 374512e47..9768c425e 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h @@ -27,7 +27,6 @@ #define GNUNET_SERVICE_TRANSPORT_VALIDATION_H #include "gnunet_statistics_service.h" -#include "gnunet_transport_validation.h" #include "gnunet_util_lib.h" @@ -49,7 +48,7 @@ GST_validation_stop (void); * */ int -GST_validation_handle_ping (const GNUNET_PeerIdentity *sender, +GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, const char *plugin_name, const void *sender_address, @@ -59,7 +58,7 @@ GST_validation_handle_ping (const GNUNET_PeerIdentity *sender, * */ int -GST_validation_handle_pong (const GNUNET_PeerIdentity *sender, +GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, const char *plugin_name, const void *sender_address, @@ -84,7 +83,7 @@ struct GST_ValidationIteratorContext; * is a time in the future if we're currently denying re-validation */ typedef void (*GST_ValidationAddressCallback)(void *cls, - const GNUNET_PeerIdentity *target, + const struct GNUNET_PeerIdentity *target, struct GNUNET_TIME_Absolute last_validated_at, struct GNUNET_TIME_Absolute validation_block, const char *plugin_name, @@ -92,7 +91,7 @@ typedef void (*GST_ValidationAddressCallback)(void *cls, size_t plugin_address_len); struct GST_ValidationIteratorContext * -GST_validation_get_addresses (const GNUNET_PeerIdentity *target, +GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, GST_ValidationAddressCallback cb, void *cb_cls); -- 2.25.1