gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23494 - in gnunet/src: include testing


From: gnunet
Subject: [GNUnet-SVN] r23494 - in gnunet/src: include testing
Date: Wed, 29 Aug 2012 14:35:14 +0200

Author: grothoff
Date: 2012-08-29 14:35:14 +0200 (Wed, 29 Aug 2012)
New Revision: 23494

Modified:
   gnunet/src/include/gnunet_testing_lib-new.h
   gnunet/src/testing/testing.c
Log:
extend API to enalbe exclusive port ranges to be specified for testing-system 
objects

Modified: gnunet/src/include/gnunet_testing_lib-new.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib-new.h 2012-08-29 12:20:06 UTC (rev 
23493)
+++ gnunet/src/include/gnunet_testing_lib-new.h 2012-08-29 12:35:14 UTC (rev 
23494)
@@ -60,7 +60,8 @@
 
 /**
  * Create a system handle.  There must only be one system
- * handle per operating system.
+ * handle per operating system.  Uses a default range for allowed ports.
+ * Ports are still tested for availability.
  *
  * @param testdir only the directory name without any path. This is used for
  *          all service homes; the directory will be created in a temporary
@@ -76,6 +77,30 @@
 
 
 /**
+ * Create a system handle.  There must only be one system
+ * handle per operating system.  Use this function directly
+ * if multiple system objects are created for the same host
+ * (only really useful when testing --- or to make the port
+ * range configureable).
+ *
+ * @param testdir only the directory name without any path. This is used for
+ *          all service homes; the directory will be created in a temporary
+ *          location depending on the underlying OS
+ * @param controller hostname of the controlling host, 
+ *        service configurations are modified to allow 
+ *        control connections from this host; can be NULL
+ * @param lowport lowest port number this system is allowed to allocate 
(inclusive)
+ * @param highport highest port number this system is allowed to allocate 
(exclusive)
+ * @return handle to this system, NULL on error
+ */
+struct GNUNET_TESTING_System *
+GNUNET_TESTING_system_create_with_portrange (const char *testdir,
+                                            const char *controller,
+                                            uint16_t lowport,
+                                            uint16_t highport);
+
+
+/**
  * Free system resources.
  *
  * @param system system to be freed

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2012-08-29 12:20:06 UTC (rev 23493)
+++ gnunet/src/testing/testing.c        2012-08-29 12:35:14 UTC (rev 23494)
@@ -124,6 +124,16 @@
    * The number of hostkeys
    */
   uint32_t total_hostkeys;
+
+  /**
+   * Lowest port we are allowed to use.
+   */
+  uint16_t lowport;
+
+  /**
+   * Highest port we are allowed to use.
+   */
+  uint16_t highport;
 };
 
 
@@ -249,21 +259,26 @@
  * @param testdir only the directory name without any path. This is used for
  *          all service homes; the directory will be created in a temporary
  *          location depending on the underlying OS
- *
  * @param controller hostname of the controlling host, 
  *        service configurations are modified to allow 
  *        control connections from this host; can be NULL
+ * @param lowport lowest port number this system is allowed to allocate 
(inclusive)
+ * @param highport highest port number this system is allowed to allocate 
(exclusive)
  * @return handle to this system, NULL on error
  */
 struct GNUNET_TESTING_System *
-GNUNET_TESTING_system_create (const char *testdir,
-                             const char *controller)
+GNUNET_TESTING_system_create_with_portrange (const char *testdir,
+                                            const char *controller,
+                                            uint16_t lowport,
+                                            uint16_t highport)
 {
   struct GNUNET_TESTING_System *system;
 
   GNUNET_assert (NULL != testdir);
   system = GNUNET_malloc (sizeof (struct GNUNET_TESTING_System));
   system->tmppath = GNUNET_DISK_mkdtemp (testdir);
+  system->lowport = lowport;
+  system->highport = highport;
   if (NULL == system->tmppath)
   {
     GNUNET_free (system);
@@ -281,6 +296,30 @@
 
 
 /**
+ * Create a system handle.  There must only be one system
+ * handle per operating system.
+ *
+ * @param testdir only the directory name without any path. This is used for
+ *          all service homes; the directory will be created in a temporary
+ *          location depending on the underlying OS
+ *
+ * @param controller hostname of the controlling host, 
+ *        service configurations are modified to allow 
+ *        control connections from this host; can be NULL
+ * @return handle to this system, NULL on error
+ */
+struct GNUNET_TESTING_System *
+GNUNET_TESTING_system_create (const char *testdir,
+                             const char *controller)
+{
+  return GNUNET_TESTING_system_create_with_portrange (testdir,
+                                                     controller,
+                                                     LOW_PORT,
+                                                     HIGH_PORT);
+}
+
+
+/**
  * Free system resources.
  *
  * @param system system to be freed
@@ -342,12 +381,12 @@
   hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
   port_buckets = (GNUNET_YES == is_tcp) ?
     system->reserved_tcp_ports : system->reserved_udp_ports;
-  for (index = (LOW_PORT / 32) + 1; index < (HIGH_PORT / 32); index++)
+  for (index = (system->lowport / 32) + 1; index < (system->highport / 32); 
index++)
   {
     xor_image = (UINT32_MAX ^ port_buckets[index]);
     if (0 == xor_image)        /* Ports in the bucket are full */
       continue;
-    pos = 0;
+    pos = system->lowport % 32;
     while (pos < 32)
     {
       if (0 == ((xor_image >> pos) & 1U))
@@ -356,6 +395,8 @@
         continue;
       }
       open_port = (index * 32) + pos;
+      if (open_port >= system->highport)
+       return 0;
       GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
       ret = NULL;
       GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));




reply via email to

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