stuff
[oweals/gnunet.git] / src / transport / plugin_transport_unix.c
index c72de6ca6d113f1f6de6f1f0b62d43d951e1abc0..2a7dc90650a1720654e3f50e87b837bf801ab5c8 100644 (file)
@@ -217,29 +217,6 @@ struct RetrySendContext
   struct RetryList *retry_list_entry;
 };
 
-/**
- * Local network addresses (actual unix path follows).
- */
-struct LocalAddrList
-{
-
-  /**
-   * This is a doubly linked list.
-   */
-  struct LocalAddrList *next;
-
-  /**
-   * This is a doubly linked list.
-   */
-  struct LocalAddrList *prev;
-
-  /**
-   * Number of bytes of the address that follow
-   */
-  size_t size;
-
-};
-
 
 /**
  * UNIX NAT "Session"
@@ -339,16 +316,6 @@ struct Plugin
    */
   uint16_t port;
 
-  /**
-   * List of our IP addresses.
-   */
-  struct LocalAddrList *lal_head;
-
-  /**
-   * Tail of our IP address list.
-   */
-  struct LocalAddrList *lal_tail;
-
   /**
    * FD Read set
    */
@@ -763,30 +730,6 @@ unix_plugin_send (void *cls,
 }
 
 
-static void
-add_to_address_list (struct Plugin *plugin,
-                    const void *arg,
-                    size_t arg_size)
-{
-  struct LocalAddrList *lal;
-
-  lal = plugin->lal_head;
-  while (NULL != lal)
-    {
-      if ( (lal->size == arg_size) &&
-          (0 == memcmp (&lal[1], arg, arg_size)) )
-       return;
-      lal = lal->next;
-    }
-  lal = GNUNET_malloc (sizeof (struct LocalAddrList) + arg_size);
-  lal->size = arg_size;
-  memcpy (&lal[1], arg, arg_size);
-  GNUNET_CONTAINER_DLL_insert (plugin->lal_head,
-                              plugin->lal_tail,
-                              lal);
-}
-
-
 /**
  * Demultiplexer for UNIX messages
  *
@@ -1062,7 +1005,6 @@ unix_plugin_address_pretty_printer (void *cls,
                                    GNUNET_TRANSPORT_AddressStringCallback asc,
                                    void *asc_cls)
 {
-  struct Plugin *plugin = cls;
   struct PrettyPrinterContext *ppc;
   const void *sb;
   size_t sbs;
@@ -1107,8 +1049,7 @@ unix_plugin_address_pretty_printer (void *cls,
   ppc->asc = asc;
   ppc->asc_cls = asc_cls;
   ppc->port = port;
-  GNUNET_RESOLVER_hostname_get (plugin->env->cfg,
-                                sb,
+  GNUNET_RESOLVER_hostname_get (sb,
                                 sbs,
                                 !numeric, timeout, &append_port, ppc);
 }
@@ -1129,41 +1070,27 @@ unix_address_to_string (void *cls,
                        const void *addr,
                        size_t addrlen)
 {
-  static char rbuf[INET6_ADDRSTRLEN + 10];
-  char buf[INET6_ADDRSTRLEN];
-  const void *sb;
-  struct in_addr a4;
-  struct in6_addr a6;
-  const struct IPv4UdpAddress *t4;
-  const struct IPv6UdpAddress *t6;
-  int af;
-  uint16_t port;
-
-  if (addrlen == sizeof (struct IPv6UdpAddress))
-    {
-      t6 = addr;
-      af = AF_INET6;
-      port = ntohs (t6->u6_port);
-      memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
-      sb = &a6;
-    }
-  else if (addrlen == sizeof (struct IPv4UdpAddress))
-    {
-      t4 = addr;
-      af = AF_INET;
-      port = ntohs (t4->u_port);
-      memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
-      sb = &a4;
-    }
+  if ((addr != NULL) && (addrlen > 0))
+    return (const char *) addr;
   else
     return NULL;
-  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
-  GNUNET_snprintf (rbuf,
-                   sizeof (rbuf),
-                   "%s:%u",
-                   buf,
-                   port);
-  return rbuf;
+}
+
+/**
+ * Notify transport service about address
+ *
+ * @param cls the plugin
+ * @param tc unused
+ */
+static void
+address_notification (void *cls,
+                    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct Plugin *plugin = cls;
+  plugin->env->notify_address(plugin->env->cls,
+                              GNUNET_YES,
+                              plugin->unix_socket_path,
+                              strlen(plugin->unix_socket_path) + 1);
 }
 
 /**
@@ -1185,22 +1112,13 @@ libgnunet_plugin_transport_unix_init (void *cls)
                                             "PORT",
                                             &port))
     port = UNIX_NAT_DEFAULT_PORT;
-  else if (port > 65535)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Given `%s' option is out of range: %llu > %u\n"),
-                  "PORT",
-                  port,
-                  65535);
-      return NULL;
-    }
-
-
   plugin = GNUNET_malloc (sizeof (struct Plugin));
   plugin->port = port;
   plugin->env = env;
-  GNUNET_asprintf(&plugin->unix_socket_path, "/tmp/unix-plugin-sock.%d", plugin->port);
-
+  GNUNET_asprintf (&plugin->unix_socket_path, 
+                  "/tmp/unix-plugin-sock.%d", 
+                  plugin->port);
+  
   api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
   api->cls = plugin;
 
@@ -1209,19 +1127,12 @@ libgnunet_plugin_transport_unix_init (void *cls)
   api->address_pretty_printer = &unix_plugin_address_pretty_printer;
   api->address_to_string = &unix_address_to_string;
   api->check_address = &unix_check_address;
-
-  add_to_address_list (plugin, plugin->unix_socket_path, strlen(plugin->unix_socket_path) + 1);
-
   sockets_created = unix_transport_server_start (plugin);
   if (sockets_created == 0)
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                _("Failed to open UNIX sockets\n"));
 
-  plugin->env->notify_address(plugin->env->cls,
-                              "unix",
-                              plugin->unix_socket_path,
-                              strlen(plugin->unix_socket_path) + 1,
-                              GNUNET_TIME_UNIT_FOREVER_REL);
+  GNUNET_SCHEDULER_add_now(address_notification, plugin);
   return api;
 }
 
@@ -1230,18 +1141,11 @@ libgnunet_plugin_transport_unix_done (void *cls)
 {
   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
-  struct LocalAddrList *lal;
 
   unix_transport_server_stop (plugin);
 
   GNUNET_NETWORK_fdset_destroy (plugin->rs);
-  while (NULL != (lal = plugin->lal_head))
-    {
-      GNUNET_CONTAINER_DLL_remove (plugin->lal_head,
-                                  plugin->lal_tail,
-                                  lal);
-      GNUNET_free (lal);
-    }
+  GNUNET_free (plugin->unix_socket_path);
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;