more code
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index bb6a54b31784daa7f9b963d0c3a7b01e74ff72cc..677d0033c96a953d72f4862654367312a4cbd6a2 100644 (file)
@@ -61,12 +61,6 @@ struct GNUNET_PeerIdentity GST_my_identity;
  */
 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
 
-
-/**
- * Hostkey generation context
- */
-struct GNUNET_CRYPTO_RsaKeyGenerationContext * GST_keygen;
-
 /**
  * Our public key.
  */
@@ -277,7 +271,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
     GST_neighbours_handle_session_ack (message, peer, &address, session, ats,
-                                      ats_count);
+                                       ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
     GST_neighbours_handle_disconnect_message (peer, message);
@@ -315,16 +309,17 @@ end:
  * @param addr one of the addresses of the host
  *        the specific address format depends on the transport
  * @param addrlen length of the address
+ * @param dest_plugin destination plugin to use this address with
  */
 static void
 plugin_env_address_change_notification (void *cls, int add_remove,
-                                        const void *addr, size_t addrlen)
+                                        const void *addr, size_t addrlen,
+                                        const char *dest_plugin)
 {
-  const char *plugin_name = cls;
   struct GNUNET_HELLO_Address address;
 
   address.peer = GST_my_identity;
-  address.transport_name = plugin_name;
+  address.transport_name = dest_plugin;
   address.address = addr;
   address.address_length = addrlen;
   GST_hello_modify_addresses (add_remove, &address);
@@ -544,12 +539,6 @@ neighbours_address_notification (void *cls,
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  if (NULL != GST_keygen)
-  {
-    GNUNET_CRYPTO_rsa_key_create_stop (GST_keygen);
-    GST_keygen = NULL;
-  }
-
   GST_neighbours_stop ();
   GST_validation_stop ();
   GST_plugins_unload ();
@@ -577,34 +566,43 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
 }
 
-struct KeyGenerationContext
-{
-  struct GNUNET_SERVER_Handle *server;
-  const struct GNUNET_CONFIGURATION_Handle *c;
-
-};
 
-static void key_generation_cb (void *cls,
-                               struct GNUNET_CRYPTO_RsaPrivateKey *pk,
-                               const char *emsg)
+/**
+ * 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)
 {
-  struct KeyGenerationContext *scx = cls;
+  char *keyfile;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp;
-
-  GST_keygen = NULL;
-  if (NULL == pk)
+  /* 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 could not access hostkey: %s. Exiting.\n"),
-                emsg);
-    GNUNET_free (scx);
+                _
+                ("Transport service is lacking key configuration settings.  Exiting.\n"));
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  GST_my_private_key = pk;
-
-  GST_stats = GNUNET_STATISTICS_create ("transport", scx->c);
-  GST_peerinfo = GNUNET_PEERINFO_connect (scx->c);
+  GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  GNUNET_free (keyfile);
+  if (GST_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);
+  GST_peerinfo = GNUNET_PEERINFO_connect (c);
   memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key));
   memset (&tmp, '\0', sizeof (tmp));
   GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
@@ -627,7 +625,7 @@ static void key_generation_cb (void *cls,
   /* start subsystems */
   GST_hello_start (&process_hello_update, NULL);
   GNUNET_assert (NULL != GST_hello_get());
-  GST_blacklist_start (scx->server);
+  GST_blacklist_start (server);
   GST_ats =
       GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
   GST_plugins_load (&plugin_env_receive_callback,
@@ -638,49 +636,8 @@ static void key_generation_cb (void *cls,
                         &neighbours_connect_notification,
                         &neighbours_disconnect_notification,
                         &neighbours_address_notification);
-  GST_clients_start (scx->server);
+  GST_clients_start (server);
   GST_validation_start ();
-  GNUNET_free (scx);
-}
-
-
-/**
- * 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)
-{
-  struct KeyGenerationContext *scx;
-  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;
-  }
-  scx = GNUNET_malloc (sizeof (struct KeyGenerationContext));
-  scx->c = c;
-  scx->server = server;
-  GST_keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, key_generation_cb, scx);
-  GNUNET_free (keyfile);
-  if (NULL == GST_keygen)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Transport service is unable to access hostkey. Exiting.\n"));
-    GNUNET_SCHEDULER_shutdown ();
-  }
 }