gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r11572 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r11572 - gnunet/src/transport
Date: Mon, 31 May 2010 14:02:01 +0200

Author: wachs
Date: 2010-05-31 14:02:01 +0200 (Mon, 31 May 2010)
New Revision: 11572

Modified:
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/plugin_transport_http.c
   gnunet/src/transport/test_plugin_transport_http.c
Log:


Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2010-05-31 11:32:39 UTC (rev 11571)
+++ gnunet/src/transport/Makefile.am    2010-05-31 12:02:01 UTC (rev 11572)
@@ -9,7 +9,7 @@
 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 @@
  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 \

Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-05-31 11:32:39 UTC 
(rev 11571)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-31 12:02:01 UTC 
(rev 11572)
@@ -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>
 
@@ -70,6 +71,43 @@
 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
  */
 struct HTTP_Message
@@ -92,8 +130,6 @@
   /**
    * amount of data to sent
    */
-  size_t size;
-
   size_t len;
 };
 
@@ -204,6 +240,8 @@
    */
   struct GNUNET_SERVICE_Context *service;
 
+  unsigned int port_inbound;
+
   /**
    * List of open sessions.
    */
@@ -1106,6 +1144,8 @@
                                         asc, void *asc_cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: 
http_plugin_address_pretty_printer\n");
+
+
   asc (asc_cls, NULL);
 }
 
@@ -1158,6 +1198,61 @@
 }
 
 /**
+ * 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.
  */
 void *
@@ -1302,7 +1397,7 @@
       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 @@
   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_done (api);
     return NULL;
   }
+
+  GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
+
   return api;
 }
 

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-05-31 11:32:39 UTC 
(rev 11571)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-05-31 12:02:01 UTC 
(rev 11572)
@@ -121,9 +121,19 @@
 
 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?
+ */
 static int fail;
 
 /**
@@ -220,6 +230,45 @@
   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 @@
                 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 @@
   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 @@
   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 */
 
-  /* testing finished, shutting down */
+  if (fail_notify_address == GNUNET_NO)
+    fail = 0;
+
+
+
   shutdown_clean();
 
-  fail = 0;
+
   return;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]