draft
authorChristian Grothoff <christian@grothoff.org>
Thu, 4 Aug 2011 12:58:58 +0000 (12:58 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 4 Aug 2011 12:58:58 +0000 (12:58 +0000)
src/transport/Makefile.am
src/transport/gnunet-service-transport-new.c [new file with mode: 0644]
src/transport/gnunet-service-transport.h
src/transport/gnunet-service-transport_blacklist.h
src/transport/gnunet-service-transport_clients.h
src/transport/gnunet-service-transport_neighbours.h
src/transport/gnunet-service-transport_plugins.h
src/transport/gnunet-service-transport_validation.h

index 6a870c6b096e81ba6a01d4e7996560d7084dd520..e004d9c00640bde2185ad90272450ea153569036 100644 (file)
@@ -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 (file)
index 0000000..c039d59
--- /dev/null
@@ -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 */
index 544b605074d4102cf98833309410f0f27a9c8dd8..8db60d707493a9a845202633a41840feb4c0fd39 100644 (file)
@@ -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"
 
index e1674ead311a1998f50c60966c64202ab01a1b82..1d10846ea11054d11e310122fa8c2d6bbcb69d48 100644 (file)
@@ -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"
 
 /**
index 299d75857b2c890788639a741cc92952ddab0113..1884ece5d62921c45af750edea2ea1a467950d00 100644 (file)
@@ -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"
 
 
index 18134fd334bad440e9ba16d8a88d1cde2ee06b55..c627e7e2faea586785a4a1ae3fd6588905911da5 100644 (file)
@@ -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,
index ad8746b4c0ac51d64769f8f45af7168d810a1528..0d62bbf791cb6331d601d255e366c8e964a3ca6f 100644 (file)
@@ -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"
 
 
index 374512e475a34a75b485299312a5660027f2e802..9768c425e26267e7a32fac6ec4d7b4d1542655da 100644 (file)
@@ -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);