mod
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 21 Aug 2012 11:15:10 +0000 (11:15 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 21 Aug 2012 11:15:10 +0000 (11:15 +0000)
src/transport/plugin_transport_http.c
src/transport/plugin_transport_http.h
src/transport/test_transport_api_http_reverse_proxy.conf

index b3c463382615d304fd1891eb056c427e70803fae..af0d9fcf80b406a3d354afd9a7338c7e4f48d04d 100644 (file)
  */
 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
 
+
+/**
+ * Wrapper to manage addresses
+ */
+struct HttpAddressWrapper
+{
+  /**
+   * Linked list next
+   */
+  struct HttpAddressWrapper *next;
+
+  /**
+   * Linked list previous
+   */
+  struct HttpAddressWrapper *prev;
+
+  struct HttpAddress *addr;
+};
+
 /**
  * Wrapper to manage IPv4 addresses
  */
@@ -1372,6 +1391,37 @@ stop_report_addresses (struct Plugin *plugin)
   }
 }
 
+/**
+ * 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
+notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct Plugin *plugin = cls;
+  struct HttpAddress *eaddr;
+  size_t eaddr_len;
+  size_t uri_len;
+
+  plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
+
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
+
+  uri_len = strlen (plugin->external_hostname) + 1;
+  eaddr_len = sizeof (struct HttpAddress) + uri_len;
+  eaddr = GNUNET_malloc (eaddr_len);
+  eaddr->addr_len = htonl (strlen (plugin->external_hostname) + 1);
+  eaddr->addr = (void *) &eaddr[1];
+  memcpy (&eaddr->addr, plugin->external_hostname, uri_len);
+  plugin->env->notify_address (plugin->env->cls, GNUNET_YES, eaddr, eaddr_len);
+  plugin->ext_addr = eaddr;
+  plugin->ext_addr_len = eaddr_len;
+}
+
 
 static int
 configure_plugin (struct Plugin *plugin)
@@ -1461,7 +1511,6 @@ configure_plugin (struct Plugin *plugin)
     GNUNET_free (bind4_address);
   }
 
-
   char *bind6_address = NULL;
 
   if ((plugin->ipv6 == GNUNET_YES) &&
@@ -1491,6 +1540,17 @@ configure_plugin (struct Plugin *plugin)
     GNUNET_free (bind6_address);
   }
 
+  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
+                                              "EXTERNAL_HOSTNAME", &plugin->external_hostname))
+  {
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                       _("Using external hostname `%s'\n"), plugin->external_hostname);
+      plugin->notify_ext_task = GNUNET_SCHEDULER_add_now (&notify_external_hostname, plugin);
+  }
+  else
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                     _("No external hostname configured\n"));
+
 
   /* Optional parameters */
   unsigned long long maxneigh;
@@ -1703,6 +1763,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
     return NULL;
   }
 
+  if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task)
+  {
+      GNUNET_SCHEDULER_cancel (plugin->notify_ext_task);
+       plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+
+  if (NULL != plugin->ext_addr)
+  {
+      plugin->env->notify_address (plugin->env->cls, GNUNET_NO, plugin->ext_addr, plugin->ext_addr_len);
+      GNUNET_free (plugin->ext_addr);
+  }
+
   /* Stop reporting addresses to transport service */
   stop_report_addresses (plugin);
 
@@ -1732,6 +1804,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
                    "Plugin `%s' unloaded\n", plugin->name);
   GNUNET_free_non_null (plugin->server_addr_v4);
   GNUNET_free_non_null (plugin->server_addr_v6);
+  GNUNET_free_non_null (plugin->external_hostname);
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;
index dc0f8bb01a0af6bc0ccd389e07e5dd6305c689c3..1469fd8a939c21bb9d36cafff0ad4896ff1281ae 100644 (file)
@@ -118,6 +118,29 @@ struct Plugin
    * --------------------
    */
 
+  /**
+   * External hostname the plugin can be connected to, can be different to
+   * the host's FQDN, used e.g. for reverse proxying
+   */
+  char *external_hostname;
+
+  /**
+   * External hostname the plugin can be connected to, can be different to
+   * the host's FQDN, used e.g. for reverse proxying
+   */
+  struct HttpAddress *ext_addr;
+
+  /**
+   * External address length
+   */
+  size_t ext_addr_len;
+
+  /**
+   * Task calling transport service about external address
+   */
+  GNUNET_SCHEDULER_TaskIdentifier notify_ext_task;
+
+
   /**
    * Plugin name
    * Equals configuration section: transport-http, transport-https
@@ -283,6 +306,22 @@ struct Plugin
 
 GNUNET_NETWORK_STRUCT_BEGIN
 
+/**
+ * HTTP addresses including a full URI
+ */
+struct HttpAddress
+{
+  /**
+   * Length of the address following in NBO
+   */
+  uint32_t addr_len GNUNET_PACKED;
+
+  /**
+   * Address following
+   */
+  void *addr GNUNET_PACKED;
+};
+
 /**
  * IPv4 addresses
  */
index 8e57cb11d16b9029f4b9a0108ead09fa6fa5754f..49fd9612e13f7c786ead531e90d97bc448ef66de 100644 (file)
@@ -1,7 +1,7 @@
-@INLINE@ template_cfg_peer1.conf
+INLINE@ template_cfg_peer1.conf
 [PATHS]
 SERVICEHOME = /tmp/test-transport/api-http-p1/
-DEFAULTCONFIG = test_transport_api_http_peer1.conf
+DEFAULTCONFIG = test_transport_api_http_reverse_proxy.conf
 
 [transport-http]
 PORT = 12080
@@ -30,6 +30,6 @@ PORT = 12081
 PLUGINS = http
 #BINARY = .libs/gnunet-service-transport
 UNIXPATH = /tmp/gnunet-p1-service-transport.sock
-#PREFIX = valgrind --leak-check=full
+PREFIX = valgrind --leak-check=full
 #PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args