(no commit message)
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 31 May 2010 12:02:01 +0000 (12:02 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 31 May 2010 12:02:01 +0000 (12:02 +0000)
src/transport/Makefile.am
src/transport/plugin_transport_http.c
src/transport/test_plugin_transport_http.c

index caee5b51dff6b9791a8b5c75096eff691ae02cf2..f42202c45500f01ee79deae9ef94f122c80a7cd5 100644 (file)
@@ -9,7 +9,7 @@ endif
 if HAVE_MHD 
  GN_LIBMHD = -lmicrohttpd
  HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la
- HTTP_PLGUIN_CHECK = test_plugin_transport_http
+ HTTP_PLUGIN_CHECK = test_plugin_transport_http
 endif
 
 if USE_COVERAGE
@@ -133,7 +133,7 @@ check_PROGRAMS = \
  test_transport_api_tcp \
  test_transport_api_tcp \
  test_transport_api_udp \
- $(HTTP_PLGUIN_CHECK) \
+ $(HTTP_PLUGIN_CHECK) \
  test_transport_api_udp_nat \
  test_transport_api_reliability_tcp 
 # test_transport_api_http \
index 726a9dbe27a0cb203e764c50bb8ef8cfa1789244..5e439e75e988f404e5262f42463f8cdfd2a5cbb7 100644 (file)
@@ -34,6 +34,7 @@
 #include "gnunet_transport_service.h"
 #include "gnunet_resolver_service.h"
 #include "plugin_transport.h"
+#include "gnunet_os_lib.h"
 #include "microhttpd.h"
 #include <curl/curl.h>
 
  */
 struct Plugin;
 
+/**
+ * Network format for IPv4 addresses.
+ */
+struct IPv4HttpAddress
+{
+  /**
+   * IPv4 address, in network byte order.
+   */
+  uint32_t ipv4_addr;
+
+  /**
+   * Port number, in network byte order.
+   */
+  uint16_t u_port;
+
+};
+
+
+/**
+ * Network format for IPv6 addresses.
+ */
+struct IPv6HttpAddress
+{
+  /**
+   * IPv6 address.
+   */
+  struct in6_addr ipv6_addr;
+
+  /**
+   * Port number, in network byte order.
+   */
+  uint16_t u6_port;
+
+};
+
+
+
 /**
  *  Message to send using http
  */
@@ -92,8 +130,6 @@ struct HTTP_Message
   /**
    * amount of data to sent
    */
-  size_t size;
-
   size_t len;
 };
 
@@ -204,6 +240,8 @@ struct Plugin
    */
   struct GNUNET_SERVICE_Context *service;
 
+  unsigned int port_inbound;
+
   /**
    * List of open sessions.
    */
@@ -1106,6 +1144,8 @@ http_plugin_address_pretty_printer (void *cls,
                                         asc, void *asc_cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_pretty_printer\n");
+
+
   asc (asc_cls, NULL);
 }
 
@@ -1157,6 +1197,61 @@ http_plugin_address_to_string (void *cls,
   return NULL;
 }
 
+/**
+ * Add the IP of our network interface to the list of
+ * our external IP addresses.
+ *
+ * @param cls the 'struct Plugin*'
+ * @param name name of the interface
+ * @param isDefault do we think this may be our default interface
+ * @param addr address of the interface
+ * @param addrlen number of bytes in addr
+ * @return GNUNET_OK to continue iterating
+ */
+static int
+process_interfaces (void *cls,
+                    const char *name,
+                    int isDefault,
+                    const struct sockaddr *addr, socklen_t addrlen)
+{
+  struct IPv4HttpAddress t4;
+  struct IPv6HttpAddress t6;
+  int af;
+  void *arg;
+  uint16_t args;
+
+  af = addr->sa_family;
+  if (af == AF_INET)
+    {
+      t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+      t4.u_port = htons (plugin->port_inbound);
+      arg = &t4;
+      args = sizeof (t4);
+    }
+  else if (af == AF_INET6)
+    {
+      if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+        {
+          /* skip link local addresses */
+          return GNUNET_OK;
+        }
+      memcpy (&t6.ipv6_addr,
+              &((struct sockaddr_in6 *) addr)->sin6_addr,
+              sizeof (struct in6_addr));
+      t6.u6_port = htons (plugin->port_inbound);
+      arg = &t6;
+      args = sizeof (t6);
+    }
+  else
+    {
+      GNUNET_break (0);
+      return GNUNET_OK;
+    }
+  plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
+
+  return GNUNET_OK;
+}
+
 /**
  * Exit point from the plugin.
  */
@@ -1302,7 +1397,7 @@ libgnunet_plugin_transport_http_init (void *cls)
       libgnunet_plugin_transport_http_done (api);
       return NULL;
     }
-
+  plugin->port_inbound = port;
   gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
   timeout = ( gn_timeout.value / 1000);
   if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
@@ -1340,6 +1435,7 @@ libgnunet_plugin_transport_http_init (void *cls)
   if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
 
+
   /* Initializing cURL */
   multi_handle = curl_multi_init();
   if ( NULL == multi_handle )
@@ -1351,6 +1447,9 @@ libgnunet_plugin_transport_http_init (void *cls)
     libgnunet_plugin_transport_http_done (api);
     return NULL;
   }
+
+  GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
+
   return api;
 }
 
index aa32e3eb1450b1b5e6fb57932c88c823fe3c7ef3..6e717470caf32acb208dcb8429969f0745f5580a 100644 (file)
@@ -121,6 +121,16 @@ static GNUNET_SCHEDULER_TaskIdentifier ti_send;
 
 const struct GNUNET_PeerIdentity * p;
 
+
+/**
+ * Did the test pass or fail?
+ */
+static int fail_notify_address;
+/**
+ * Did the test pass or fail?
+ */
+static int fail_notify_address_count;
+
 /**
  * Did the test pass or fail?
  */
@@ -220,6 +230,45 @@ receive (void *cls,
   return GNUNET_TIME_UNIT_ZERO;
 }
 
+
+/**
+ * Network format for IPv4 addresses.
+ */
+struct IPv4HttpAddress
+{
+  /**
+   * IPv4 address, in network byte order.
+   */
+  uint32_t ipv4_addr;
+
+  /**
+   * Port number, in network byte order.
+   */
+  uint16_t u_port;
+
+};
+
+
+/**
+ * Network format for IPv6 addresses.
+ */
+struct IPv6HttpAddress
+{
+  /**
+   * IPv6 address.
+   */
+  struct in6_addr ipv6_addr;
+
+  /**
+   * Port number, in network byte order.
+   */
+  uint16_t u6_port;
+
+};
+
+/**
+ * Plugin notifies transport (aka testcase) about its addresses
+ */
 void
 notify_address (void *cls,
                 const char *name,
@@ -227,7 +276,27 @@ notify_address (void *cls,
                 uint16_t addrlen,
                 struct GNUNET_TIME_Relative expires)
 {
+  char * address = NULL;
+  unsigned int port;
 
+
+  if (addrlen == (sizeof (struct IPv4HttpAddress)))
+  {
+    address = GNUNET_malloc (INET_ADDRSTRLEN);
+    inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
+    port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
+  }
+
+  if (addrlen == (sizeof (struct IPv6HttpAddress)))
+  {
+    address = GNUNET_malloc (INET6_ADDRSTRLEN);
+    inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
+    port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Transport plugin notification for address: `%s':%u\n"),address,port);
+  fail_notify_address_count++;
+
+  fail_notify_address = GNUNET_NO;
 }
 
 /**
@@ -308,8 +377,7 @@ run (void *cls,
   if (my_private_key == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _
-                  ("Transport service could not access hostkey.  Exiting.\n"));
+                  _("Transport service could not access hostkey.  Exiting.\n"));
       GNUNET_SCHEDULER_shutdown (s);
       fail = 1;
       return;
@@ -335,12 +403,18 @@ run (void *cls,
   ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT, &task_timeout, NULL);
 
   /* testing plugin functionality */
-
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"),  fail_notify_address_count);
 
   /* testing finished, shutting down */
+
+  if (fail_notify_address == GNUNET_NO)
+    fail = 0;
+
+
+
   shutdown_clean();
 
-  fail = 0;
+
   return;
 }