(no commit message)
[oweals/gnunet.git] / src / transport / plugin_transport_udp.c
index 0f53719fe11dfa07a9bb2dd2c9629bd017c5bf0d..94447bdbcffc933e7e7ed012b148d45d663511ff 100644 (file)
@@ -50,7 +50,7 @@
 #include "gnunet_signatures.h"
 #include "gnunet_statistics_service.h"
 #include "gnunet_transport_service.h"
-#include "plugin_transport.h"
+#include "gnunet_transport_plugin.h"
 #include "transport.h"
 
 #define DEBUG_UDP GNUNET_YES
@@ -471,7 +471,7 @@ struct Plugin
   /**
    * The process id of the server process (if behind NAT)
    */
-  GNUNET_OS_Process *server_proc;
+  struct GNUNET_OS_Process *server_proc;
 
 };
 
@@ -513,7 +513,7 @@ udp_transport_server_stop (void *cls)
 
   if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
     {
-      GNUNET_SCHEDULER_cancel (plugin->env->sched, plugin->select_task);
+      GNUNET_SCHEDULER_cancel (plugin->select_task);
       plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
     }
   if (plugin->udp_sockv4.desc != NULL)
@@ -702,7 +702,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
   char addr_buf[INET_ADDRSTRLEN];
   char *address_as_string;
   char *port_as_string;
-  GNUNET_OS_Process *proc;
+  struct GNUNET_OS_Process *proc;
   const struct IPv4UdpAddress *t4;
 
   GNUNET_assert(addrlen == sizeof(struct IPv4UdpAddress));
@@ -723,12 +723,15 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
 #endif
 
   /* Start the server process */
-  proc = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL);
+  proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL);
   GNUNET_free(address_as_string);
   GNUNET_free(port_as_string);
-  GNUNET_OS_process_wait (proc);
-  GNUNET_OS_process_close (proc);
-  proc = NULL;
+  if (proc != NULL)
+    {
+      GNUNET_OS_process_wait (proc);
+      GNUNET_OS_process_close (proc);
+      proc = NULL;
+    }
 }
 
 /**
@@ -1107,7 +1110,7 @@ void
 udp_probe_continuation (void *cls, const struct GNUNET_PeerIdentity *target, int result)
 {
   struct UDP_NAT_Probes *probe = cls;
-  struct Plugin *plugin = probe->plugin;
+  /*struct Plugin *plugin = probe->plugin;*/
 
   if ((result == GNUNET_OK) && (probe->count < MAX_PROBES))
     {
@@ -1115,7 +1118,7 @@ udp_probe_continuation (void *cls, const struct GNUNET_PeerIdentity *target, int
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                        _("Scheduling next probe for 10000 milliseconds\n"));
 #endif
-      probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10000), &send_udp_probe_message, probe);
+      probe->task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10000), &send_udp_probe_message, probe);
     }
   else /* Destroy the probe context. */
     {
@@ -1200,8 +1203,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
   else
     {
       plugin->server_read_task =
-           GNUNET_SCHEDULER_add_read_file (plugin->env->sched,
-                                           GNUNET_TIME_UNIT_FOREVER_REL,
+           GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                            plugin->server_stdout_handle, &udp_plugin_server_read, plugin);
       return;
     }
@@ -1222,8 +1224,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
                   _("nat-server-read malformed address\n"), &mybuf, port);
 
       plugin->server_read_task =
-          GNUNET_SCHEDULER_add_read_file (plugin->env->sched,
-                                          GNUNET_TIME_UNIT_FOREVER_REL,
+          GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                           plugin->server_stdout_handle, &udp_plugin_server_read, plugin);
       return;
     }
@@ -1238,13 +1239,12 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
       temp_probe->addr.u_port = htons(port);
       temp_probe->next = plugin->probes;
       temp_probe->plugin = plugin;
-      temp_probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_udp_probe_message, temp_probe);
+      temp_probe->task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_udp_probe_message, temp_probe);
       plugin->probes = temp_probe;
     }
 
   plugin->server_read_task =
-       GNUNET_SCHEDULER_add_read_file (plugin->env->sched,
-                                       GNUNET_TIME_UNIT_FOREVER_REL,
+       GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                        plugin->server_stdout_handle, &udp_plugin_server_read, plugin);
 
 }
@@ -1358,7 +1358,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
 
               if (outgoing_probe->task != GNUNET_SCHEDULER_NO_TASK)
                 {
-                  GNUNET_SCHEDULER_cancel(plugin->env->sched, outgoing_probe->task);
+                  GNUNET_SCHEDULER_cancel(outgoing_probe->task);
                   outgoing_probe->task = GNUNET_SCHEDULER_NO_TASK;
                   /* Schedule task to timeout and remove probe if confirmation not received */
                 }
@@ -1569,8 +1569,7 @@ udp_plugin_select (void *cls,
     {
       GNUNET_break_op (0);
       plugin->select_task =
-       GNUNET_SCHEDULER_add_select (plugin->env->sched,
-                                    GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                     GNUNET_SCHEDULER_NO_TASK,
                                     GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
                                     NULL, &udp_plugin_select, plugin);
@@ -1581,8 +1580,7 @@ udp_plugin_select (void *cls,
     {
       GNUNET_break_op (0);
       plugin->select_task =
-       GNUNET_SCHEDULER_add_select (plugin->env->sched,
-                                    GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                     GNUNET_SCHEDULER_NO_TASK,
                                     GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
                                     NULL, &udp_plugin_select, plugin);
@@ -1601,8 +1599,7 @@ udp_plugin_select (void *cls,
       count++;
     }
   plugin->select_task =
-    GNUNET_SCHEDULER_add_select (plugin->env->sched,
-                                 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+    GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                  GNUNET_SCHEDULER_NO_TASK,
                                  GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
                                  NULL, &udp_plugin_select, plugin);
@@ -1659,8 +1656,7 @@ udp_transport_server_start (void *cls)
 
       plugin->server_stdout_handle = GNUNET_DISK_pipe_handle(plugin->server_stdout, GNUNET_DISK_PIPE_END_READ);
       plugin->server_read_task =
-       GNUNET_SCHEDULER_add_read_file (plugin->env->sched,
-                                       GNUNET_TIME_UNIT_FOREVER_REL,
+       GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                        plugin->server_stdout_handle, &udp_plugin_server_read, plugin);
     }
 
@@ -1783,8 +1779,7 @@ udp_transport_server_start (void *cls)
                              plugin->udp_sockv6.desc);
 
   plugin->select_task =
-    GNUNET_SCHEDULER_add_select (plugin->env->sched,
-                                 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+    GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                  GNUNET_SCHEDULER_NO_TASK,
                                  GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
                                  NULL, &udp_plugin_select, plugin);
@@ -1992,8 +1987,7 @@ udp_plugin_address_pretty_printer (void *cls,
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;
-  GNUNET_RESOLVER_hostname_get (plugin->env->sched,
-                                plugin->env->cfg,
+  GNUNET_RESOLVER_hostname_get (plugin->env->cfg,
                                 sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
@@ -2167,7 +2161,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
   char *external_address;
   struct IPv4UdpAddress v4_address;
 
-  service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg);
+  service = GNUNET_SERVICE_start ("transport-udp", env->cfg);
   if (service == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _
@@ -2299,17 +2293,17 @@ libgnunet_plugin_transport_udp_init (void *cls)
 
   plugin->service = service;
 
-  GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-udp", "BINDTO", &plugin->bind_address);
-
-  GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-udp", "BINDTO6", &plugin->bind6_address);
+  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-udp", "BINDTO", &plugin->bind_address))
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Binding udp plugin to specific address: `%s'\n", plugin->bind_address);
+  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-udp", "BINDTO6", &plugin->bind6_address))
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Binding udp plugin to specific address: `%s'\n", plugin->bind6_address);
 
   if (plugin->behind_nat == GNUNET_NO)
     {
       GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
     }
 
-  plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched,
-                                                           env->cfg,
+  plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->cfg,
                                                            AF_UNSPEC,
                                                            HOSTNAME_RESOLVE_TIMEOUT,
                                                            &process_hostname_ips,