tighten formatting rules
[oweals/gnunet.git] / src / testbed / testbed_api_topology.c
index f23a771f9ebc2c58d8e9c12fe1fd7397f6993525..9ffe7f47d134f4c51babb0ed027d169b6415bc5a 100644 (file)
@@ -1,21 +1,21 @@
 /*
       This file is part of GNUnet
-      Copyright (C) 2008--2013 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2008--2013 GNUnet e.V.
 
-      GNUnet is free software; you can redistribute it and/or modify
-      it under the terms of the GNU General Public License as published
-      by the Free Software Foundation; either version 3, or (at your
-      option) any later version.
+      GNUnet is free software: you can redistribute it and/or modify it
+      under the terms of the GNU Affero General Public License as published
+      by the Free Software Foundation, either version 3 of the License,
+      or (at your option) any later version.
 
       GNUnet is distributed in the hope that it will be useful, but
       WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      General Public License for more details.
+      Affero General Public License for more details.
 
-      You should have received a copy of the GNU General Public License
-      along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      You should have received a copy of the GNU Affero General Public License
+      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
  */
 
 /**
@@ -33,7 +33,7 @@
 /**
  * Generic loggins shorthand
  */
-#define LOG(kind,...)                                           \
+#define LOG(kind, ...)                                           \
   GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__)
 
 
@@ -54,7 +54,6 @@ struct TopologyContext;
  */
 struct OverlayLink
 {
-
   /**
    * An operation corresponding to this link
    */
@@ -74,7 +73,6 @@ struct OverlayLink
    * position of peer B's handle in peers array
    */
   uint32_t B;
-
 };
 
 
@@ -216,22 +214,21 @@ struct TopologyContext
   /**
    * The type of this context
    */
-  enum {
-    
+  enum
+  {
     /**
      * Type for underlay topology
      */
     TOPOLOGYCONTEXT_TYPE_UNDERLAY = 0,
-    
+
     /**
      * Type for overlay topology
      */
     TOPOLOGYCONTEXT_TYPE_OVERLAY
-
   } type;
 
-  union {
-
+  union
+  {
     /**
      * Topology context information for overlay topology
      */
@@ -252,7 +249,6 @@ struct TopologyContext
    * The size of the link array
    */
   unsigned int link_array_size;
-
 };
 
 
@@ -260,74 +256,78 @@ struct TopologyContext
  * A array of names representing topologies. Should be in sync with enum
  * GNUNET_TESTBED_TopologyOption
  */
-const char *topology_strings[] = {
-
-    /**
-     * A clique (everyone connected to everyone else).  No options. If there are N
-     * peers this topology results in (N * (N -1)) connections.
-     */
+static const char *topology_strings[] = {
+  /**
+   * A clique (everyone connected to everyone else).  No options. If there are N
+   * peers this topology results in (N * (N -1)) connections.
+   */
   "CLIQUE",
 
-    /**
-     * Small-world network (2d torus plus random links).  Followed
-     * by the number of random links to add (unsigned int).
-     */
+  /*
+   * Small-world network (2d torus plus random links).  Followed
+   * by the number of random links to add (unsigned int).
+   */
   "SMALL_WORLD",
 
-    /**
-     * Small-world network (ring plus random links).  Followed
-     * by the number of random links to add (unsigned int).
-     */
+  /**
+   * Small-world network (ring plus random links).  Followed
+   * by the number of random links to add (unsigned int).
+   */
   "SMALL_WORLD_RING",
 
-    /**
-     * Ring topology.  No options.
-     */
+  /**
+   * Ring topology.  No options.
+   */
   "RING",
 
-    /**
-     * 2-d torus.  No options.
-     */
+  /**
+   * Star topology.  No options.
+   */
+  "STAR",
+
+  /**
+   * 2-d torus.  No options.
+   */
   "2D_TORUS",
 
-    /**
-     * Random graph.  Followed by the number of random links to be established
-     * (unsigned int)
-     */
+  /**
+   * Random graph.  Followed by the number of random links to be established
+   * (unsigned int)
+   */
   "RANDOM",                     // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI
 
-    /**
-     * Certain percentage of peers are unable to communicate directly
-     * replicating NAT conditions.  Followed by the fraction of
-     * NAT'ed peers (float).
-     */
+  /**
+   * Certain percentage of peers are unable to communicate directly
+   * replicating NAT conditions.  Followed by the fraction of
+   * NAT'ed peers (float).
+   */
   "INTERNAT",
 
-    /**
-     * Scale free topology. Followed by the maximum number of links a node can
-     * have (unsigned int); and the number of links a new node should have when
-     * it is added to the network (unsigned int)
-     */
+  /**
+   * Scale free topology. Followed by the maximum number of links a node can
+   * have (unsigned int); and the number of links a new node should have when
+   * it is added to the network (unsigned int)
+   */
   "SCALE_FREE",
 
-    /**
-     * Straight line topology.  No options.
-     */
+  /**
+   * Straight line topology.  No options.
+   */
   "LINE",
 
-    /**
-     * Read a topology from a given file.  Followed by the name of the file (const char *).
-     */
+  /**
+   * Read a topology from a given file.  Followed by the name of the file (const char *).
+   */
   "FROM_FILE",
 
-    /**
-     * All peers are disconnected.  No options.
-     */
+  /**
+   * All peers are disconnected.  No options.
+   */
   "NONE",
 
-    /**
-     * End of strings
-     */
+  /**
+   * End of strings
+   */
   NULL
 };
 
@@ -341,7 +341,8 @@ const char *topology_strings[] = {
  *          operation has executed successfully.
  */
 static void
-overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op,
+overlay_link_completed (void *cls,
+                        struct GNUNET_TESTBED_Operation *op,
                         const char *emsg)
 {
   struct OverlayLink *link = cls;
@@ -361,10 +362,13 @@ overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op,
     if (0 != overlay->retry_cnt)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING,
-           "Error while establishing a link: %s -- Retrying\n", emsg);
+           "Error while establishing a link: %s -- Retrying\n",
+           emsg);
       retry_entry = GNUNET_new (struct RetryListEntry);
       retry_entry->link = link;
-      GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head, overlay->rl_tail, retry_entry);
+      GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head,
+                                        overlay->rl_tail,
+                                        retry_entry);
     }
   }
   else
@@ -381,23 +385,28 @@ overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op,
     {
       link = retry_entry->link;
       link->op =
-          GNUNET_TESTBED_overlay_connect (overlay->op_cls, &overlay_link_completed,
-                                          link, overlay->peers[link->A],
-                                          overlay->peers[link->B]);
+        GNUNET_TESTBED_overlay_connect (overlay->op_cls,
+                                        &overlay_link_completed,
+                                        link,
+                                        overlay->peers[link->A],
+                                        overlay->peers[link->B]);
       overlay->nlinks++;
-      GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry);
+      GNUNET_CONTAINER_DLL_remove (overlay->rl_head,
+                                   overlay->rl_tail,
+                                   retry_entry);
       GNUNET_free (retry_entry);
     }
     return;
   }
   if (NULL != overlay->comp_cb)
   {
-    overlay->comp_cb (overlay->comp_cb_cls, overlay->nsuccess, overlay->nfailures);
+    overlay->comp_cb (overlay->comp_cb_cls,
+                      overlay->nsuccess,
+                      overlay->nfailures);
   }
 }
 
 
-
 /**
  * Function called when a overlay connect operation is ready
  *
@@ -416,10 +425,11 @@ opstart_overlay_configure_topology (void *cls)
   for (p = 0; p < tc->link_array_size; p++)
   {
     overlay->link_array[p].op =
-        GNUNET_TESTBED_overlay_connect (overlay->op_cls, &overlay_link_completed,
-                                        &overlay->link_array[p],
-                                        overlay->peers[overlay->link_array[p].A],
-                                        overlay->peers[overlay->link_array[p].B]);
+      GNUNET_TESTBED_overlay_connect (overlay->op_cls,
+                                      &overlay_link_completed,
+                                      &overlay->link_array[p],
+                                      overlay->peers[overlay->link_array[p].A],
+                                      overlay->peers[overlay->link_array[p].B]);
   }
 }
 
@@ -441,7 +451,8 @@ oprelease_overlay_configure_topology (void *cls)
   overlay = &tc->u.overlay;
   while (NULL != (retry_entry = overlay->rl_head))
   {
-    GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry);
+    GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail,
+                                 retry_entry);
     GNUNET_free (retry_entry);
   }
   if (NULL != overlay->link_array)
@@ -465,7 +476,9 @@ oprelease_overlay_configure_topology (void *cls)
  * @return
  */
 static void
-make_link (unsigned int offset, uint32_t A, uint32_t B,
+make_link (unsigned int offset,
+           uint32_t A,
+           uint32_t B,
            struct TopologyContext *tc)
 {
   GNUNET_assert (A != B);
@@ -475,7 +488,7 @@ make_link (unsigned int offset, uint32_t A, uint32_t B,
     {
       struct TopologyContextOverlay *overlay;
       struct OverlayLink *olink;
-      
+
       overlay = &tc->u.overlay;
       GNUNET_assert (offset < tc->link_array_size);
       olink = &overlay->link_array[offset];
@@ -486,11 +499,12 @@ make_link (unsigned int offset, uint32_t A, uint32_t B,
       olink->tc = tc;
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
       struct UnderlayLink *ulink;
-      
+
       underlay = &tc->u.underlay;
       GNUNET_assert (offset < tc->link_array_size);
       ulink = &underlay->link_array[offset];
@@ -518,19 +532,22 @@ gen_topo_line (struct TopologyContext *tc)
   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
     {
       struct TopologyContextOverlay *overlay;
-      
+
       overlay = &tc->u.overlay;
       overlay->link_array =
-          GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
+        GNUNET_new_array (tc->link_array_size,
+                          struct OverlayLink);
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
-      
+
       underlay = &tc->u.underlay;
       underlay->link_array =
-          GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
+        GNUNET_new_array (tc->link_array_size,
+                          struct UnderlayLink);
     }
     break;
   }
@@ -539,6 +556,49 @@ gen_topo_line (struct TopologyContext *tc)
 }
 
 
+/**
+ * Generates star topology
+ *
+ * @param tc the topology context
+ */
+static void
+gen_topo_star (struct TopologyContext *tc)
+{
+  unsigned int cnt;
+
+  tc->link_array_size = tc->num_peers - 1;
+  switch (tc->type)
+  {
+  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
+    {
+      struct TopologyContextOverlay *overlay;
+
+      overlay = &tc->u.overlay;
+      overlay->link_array =
+        GNUNET_new_array (tc->link_array_size,
+                          struct OverlayLink);
+    }
+    break;
+
+  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
+    {
+      struct TopologyContextUnderlay *underlay;
+
+      underlay = &tc->u.underlay;
+      underlay->link_array =
+        GNUNET_new_array (tc->link_array_size,
+                          struct UnderlayLink);
+    }
+    break;
+  }
+  for (cnt = tc->link_array_size; cnt; cnt--)
+    make_link (cnt - 1,
+               0,
+               cnt,
+               tc);
+}
+
+
 /**
  * Generates ring topology
  *
@@ -557,18 +617,19 @@ gen_topo_ring (struct TopologyContext *tc)
 
       overlay = &tc->u.overlay;
       overlay->link_array =
-          GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) *
-                          tc->link_array_size);
+        GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
+                        * tc->link_array_size);
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
-      
+
       underlay = &tc->u.underlay;
       underlay->link_array =
-          GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) *
-      tc->link_array_size);
+        GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
+                        * tc->link_array_size);
     }
     break;
   }
@@ -605,7 +666,7 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows,
   sq = floor (sq);
   sq_floor = (unsigned int) sq;
   _rows = (sq_floor + 1);
-  _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows);
+  _rows_len = GNUNET_malloc (sizeof(unsigned int) * _rows);
   for (y = 0; y < _rows - 1; y++)
     _rows_len[y] = sq_floor;
   _num_peers = sq_floor * sq_floor;
@@ -650,25 +711,26 @@ gen_topo_2dtorus (struct TopologyContext *tc)
   unsigned int offset;
 
   tc->link_array_size =
-      GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
+    GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
   switch (tc->type)
   {
   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
     {
       struct TopologyContextOverlay *overlay;
-      
+
       overlay = &tc->u.overlay;
       overlay->link_array =
-          GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
+        GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
 
       underlay = &tc->u.underlay;
       underlay->link_array =
-          GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
+        GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
       break;
     }
   }
@@ -714,11 +776,13 @@ gen_topo_2dtorus (struct TopologyContext *tc)
  *
  * @param tc the topology context
  * @param links the number of random links to establish
- * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
+ * @param append #GNUNET_YES to add links to existing link array; #GNUNET_NO to
  *          create a new link array
  */
 static void
-gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
+gen_topo_random (struct TopologyContext *tc,
+                 unsigned int links,
+                 int append)
 {
   unsigned int cnt;
   unsigned int index;
@@ -748,15 +812,17 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
       {
         GNUNET_assert (NULL == overlay->link_array);
         overlay->link_array =
-            GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
+          GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
         break;
       }
-      GNUNET_assert ((0 < tc->link_array_size) && (NULL != overlay->link_array));
+      GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
+                                                   overlay->link_array));
       overlay->link_array =
-          GNUNET_realloc (overlay->link_array,
-                          sizeof (struct OverlayLink) * tc->link_array_size);
+        GNUNET_realloc (overlay->link_array,
+                        sizeof(struct OverlayLink) * tc->link_array_size);
       break;
     }
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
@@ -766,13 +832,14 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
       {
         GNUNET_assert (NULL == underlay->link_array);
         underlay->link_array =
-            GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
+          GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
         break;
       }
-      GNUNET_assert ((0 < tc->link_array_size) && (NULL != underlay->link_array));
+      GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
+                                                   underlay->link_array));
       underlay->link_array =
-          GNUNET_realloc (underlay->link_array,
-                          sizeof (struct UnderlayLink) * tc->link_array_size);
+        GNUNET_realloc (underlay->link_array,
+                        sizeof(struct UnderlayLink) * tc->link_array_size);
       break;
     }
   }
@@ -781,12 +848,12 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
     do
     {
       A_rand =
-          GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
+        GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
       B_rand =
-          GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
+        GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
     }
     while (A_rand == B_rand);
-    make_link (index+cnt, A_rand, B_rand, tc);
+    make_link (index + cnt, A_rand, B_rand, tc);
   }
 }
 
@@ -802,7 +869,9 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
  *   network
  */
 static void
-gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
+gen_topo_scale_free (struct TopologyContext *tc,
+                     uint16_t cap,
+                     uint8_t m)
 {
   unsigned int *deg;
   unsigned int *etab;
@@ -825,23 +894,24 @@ gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
       struct TopologyContextOverlay *overlay;
 
       overlay = &tc->u.overlay;
-      overlay->link_array = GNUNET_malloc_large (sizeof (struct OverlayLink) *
-                                                 tc->link_array_size);
+      overlay->link_array = GNUNET_malloc_large (sizeof(struct OverlayLink)
+                                                 tc->link_array_size);
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
 
       underlay = &tc->u.underlay;
-      underlay->link_array = GNUNET_malloc_large (sizeof (struct UnderlayLink) *
-                                                  tc->link_array_size);
+      underlay->link_array = GNUNET_malloc_large (sizeof(struct UnderlayLink)
+                                                  tc->link_array_size);
     }
     break;
   }
-  etab = GNUNET_malloc_large (sizeof (unsigned int) * 2 * tc->link_array_size);
-  deg = GNUNET_malloc (sizeof (unsigned int) * tc->num_peers);
-  used = GNUNET_malloc (sizeof (unsigned int) * m);
+  etab = GNUNET_malloc_large (sizeof(unsigned int) * 2 * tc->link_array_size);
+  deg = GNUNET_malloc (sizeof(unsigned int) * tc->num_peers);
+  used = GNUNET_malloc (sizeof(unsigned int) * m);
   /* start by connecting peer 1 to peer 0 */
   make_link (0, 0, 1, tc);
   deg[0]++;
@@ -856,7 +926,7 @@ gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
     for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
     {
       redo_threshold = 0;
-    redo:
+redo:
       off = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, etaboff);
       random_peer = etab[off];
       if (cap < deg[random_peer])
@@ -903,19 +973,22 @@ gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
     {
       struct TopologyContextOverlay *overlay;
-      
+
       overlay = &tc->u.overlay;
-      overlay->link_array = 
-          GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size);
+      overlay->link_array =
+        GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
+                        * tc->link_array_size);
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
 
       underlay = &tc->u.underlay;
       underlay->link_array =
-          GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * tc->link_array_size);
+        GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
+                        * tc->link_array_size);
     }
     break;
   }
@@ -929,7 +1002,8 @@ gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
  * @param filename the filename of the file containing topology data
  */
 static void
-gen_topo_from_file (struct TopologyContext *tc, const char *filename)
+gen_topo_from_file (struct TopologyContext *tc,
+                    const char *filename)
 {
   char *data;
   char *end;
@@ -940,7 +1014,6 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
   unsigned long int other_peer_id;
   enum ParseState
   {
-
     /**
      * We read the peer index
      */
@@ -950,27 +1023,30 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
      * We read the other peer indices
      */
     OTHER_PEER_INDEX,
-
   } state;
   int status;
 
   status = GNUNET_SYSERR;
   if (GNUNET_YES != GNUNET_DISK_file_test (filename))
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename);
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _ ("Topology file %s not found\n"),
+         filename);
     return;
   }
   if (GNUNET_OK !=
       GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"),
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _ ("Topology file %s has no data\n"),
          filename);
     return;
   }
   data = GNUNET_malloc (fs);
   if (fs != GNUNET_DISK_fn_read (filename, data, fs))
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"),
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _ ("Topology file %s cannot be read\n"),
          filename);
     goto _exit;
   }
@@ -980,7 +1056,7 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
   state = PEER_INDEX;
   while (offset < fs)
   {
-    if (0 != isspace (data[offset]))
+    if (0 != isspace ((unsigned char) data[offset]))
     {
       offset++;
       continue;
@@ -992,7 +1068,7 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
       if (NULL == buf)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Failed to read peer index from toology file: %s"), filename);
+             _ ("Failed to read peer index from toology file: %s"), filename);
         goto _exit;
       }
       *buf = '\0';
@@ -1001,43 +1077,44 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
       if (0 != errno)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Value in given topology file: %s out of range\n"), filename);
+             _ ("Value in given topology file: %s out of range\n"), filename);
         goto _exit;
       }
       if (&data[offset] == end)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Failed to read peer index from topology file: %s"), filename);
+             _ ("Failed to read peer index from topology file: %s"), filename);
         goto _exit;
       }
       if (tc->num_peers <= peer_id)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Topology file needs more peers than given ones\n"), filename);
+             _ ("Topology file needs more peers than given ones\n"), filename);
         goto _exit;
       }
       state = OTHER_PEER_INDEX;
       offset += ((unsigned int) (buf - &data[offset])) + 1;
       break;
+
     case OTHER_PEER_INDEX:
       errno = 0;
       other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
       if (0 != errno)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Value in given topology file: %s out of range\n"), filename);
+             _ ("Value in given topology file: %s out of range\n"), filename);
         goto _exit;
       }
       if (&data[offset] == end)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Failed to read peer index from topology file: %s"), filename);
+             _ ("Failed to read peer index from topology file: %s"), filename);
         goto _exit;
       }
       if (tc->num_peers <= other_peer_id)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             _("Topology file needs more peers than given ones\n"), filename);
+             _ ("Topology file needs more peers than given ones\n"), filename);
         goto _exit;
       }
       if (peer_id != other_peer_id)
@@ -1048,21 +1125,23 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
         case TOPOLOGYCONTEXT_TYPE_OVERLAY:
           {
             struct TopologyContextOverlay *overlay;
-            
+
             overlay = &tc->u.overlay;
-            overlay->link_array = 
-                GNUNET_realloc (overlay->link_array,
-                                sizeof (struct OverlayLink) * tc->link_array_size);
+            overlay->link_array =
+              GNUNET_realloc (overlay->link_array,
+                              sizeof(struct OverlayLink) * tc->link_array_size);
           }
           break;
+
         case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
           {
             struct TopologyContextUnderlay *underlay;
-            
+
             underlay = &tc->u.underlay;
             underlay->link_array =
-                GNUNET_realloc (underlay->link_array,
-                                sizeof (struct UnderlayLink) * tc->link_array_size);
+              GNUNET_realloc (underlay->link_array,
+                              sizeof(struct UnderlayLink)
+                              * tc->link_array_size);
           }
           break;
         }
@@ -1071,13 +1150,16 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
       }
       else
         LOG (GNUNET_ERROR_TYPE_WARNING,
-             _("Ignoring to connect peer %u to peer %u\n"), peer_id,
+             _ ("Ignoring to connect peer %u to peer %u\n"),
+             peer_id,
              other_peer_id);
       while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
         offset++;
-      if ('\n' == data[offset])
+      if ((offset < fs) &&
+          ('\n' == data[offset]))
         state = PEER_INDEX;
-      else if ('|' == data[offset])
+      else if ((offset < fs) &&
+               ('|' == data[offset]))
       {
         state = OTHER_PEER_INDEX;
         offset++;
@@ -1091,23 +1173,25 @@ _exit:
   GNUNET_free (data);
   if (GNUNET_OK != status)
   {
-    LOG (GNUNET_ERROR_TYPE_WARNING, "Removing link data read from the file\n");
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Removing link data read from the file\n");
     tc->link_array_size = 0;
     switch (tc->type)
     {
     case TOPOLOGYCONTEXT_TYPE_OVERLAY:
       {
         struct TopologyContextOverlay *overlay;
-        
+
         overlay = &tc->u.overlay;
         GNUNET_free_non_null (overlay->link_array);
         overlay->link_array = NULL;
       }
       break;
+
     case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
       {
         struct TopologyContextUnderlay *underlay;
-        
+
         underlay = &tc->u.underlay;
         GNUNET_free_non_null (underlay->link_array);
         underlay->link_array = NULL;
@@ -1129,7 +1213,7 @@ gen_topo_clique (struct TopologyContext *tc)
   unsigned int cnt;
   unsigned int offset;
   unsigned int neighbour;
-  
+
   tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
   switch (tc->type)
   {
@@ -1138,17 +1222,18 @@ gen_topo_clique (struct TopologyContext *tc)
       struct TopologyContextOverlay *overlay;
 
       overlay = &tc->u.overlay;
-      overlay->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
-                                           tc->link_array_size);
+      overlay->link_array = GNUNET_new_array (tc->link_array_size,
+                                              struct OverlayLink);
     }
     break;
+
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
 
       underlay = &tc->u.underlay;
-      underlay->link_array = GNUNET_malloc (sizeof (struct UnderlayLink) *
-                                            tc->link_array_size);
+      underlay->link_array = GNUNET_new_array (tc->link_array_size,
+                                               struct UnderlayLink);
     }
   }
   offset = 0;
@@ -1169,8 +1254,8 @@ gen_topo_clique (struct TopologyContext *tc)
  * Configure overall network topology to have a particular shape.
  *
  * @param op_cls closure argument to give with the operation event
- * @param num_peers number of peers in 'peers'
- * @param peers array of 'num_peers' with the peers to configure
+ * @param num_peers number of peers in @a peers
+ * @param peers array of @a num_peers with the peers to configure
  * @param topo desired underlay topology to use
  * @param ap topology-specific options
  * @return handle to the operation, NULL if configuring the topology
@@ -1194,8 +1279,8 @@ GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
  * Configure overall network topology to have a particular shape.
  *
  * @param op_cls closure argument to give with the operation event
- * @param num_peers number of peers in 'peers'
- * @param peers array of 'num_peers' with the peers to configure
+ * @param num_peers number of peers in @a peers
+ * @param peers array of @a num_peers with the peers to configure
  * @param topo desired underlay topology to use
  * @param ... topology-specific options
  * @return handle to the operation, NULL if configuring the topology
@@ -1220,8 +1305,8 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
  *
  * @param op_cls closure argument to give with the peer connect operation events
  *          generated through this function
- * @param num_peers number of peers in 'peers'
- * @param peers array of 'num_peers' with the peers to configure
+ * @param num_peers number of peers in @a peers
+ * @param peers array of @a num_peers with the peers to configure
  * @param max_connections the maximums number of overlay connections that will
  *          be made to achieve the given topology
  * @param comp_cb the completion callback to call when the topology generation
@@ -1241,7 +1326,8 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
                                               GNUNET_TESTBED_TopologyCompletionCallback
                                               comp_cb,
                                               void *comp_cb_cls,
-                                              enum GNUNET_TESTBED_TopologyOption topo,
+                                              enum GNUNET_TESTBED_TopologyOption
+                                              topo,
                                               va_list va)
 {
   struct TopologyContext *tc;
@@ -1267,27 +1353,38 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
   case GNUNET_TESTBED_TOPOLOGY_LINE:
     gen_topo_line (tc);
     break;
+
+  case GNUNET_TESTBED_TOPOLOGY_STAR:
+    gen_topo_star (tc);
+    break;
+
   case GNUNET_TESTBED_TOPOLOGY_RING:
     gen_topo_ring (tc);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
     gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
     gen_topo_ring (tc);
     gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
     gen_topo_clique (tc);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
     gen_topo_2dtorus (tc);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
     gen_topo_2dtorus (tc);
     gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
 
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
     {
       uint16_t cap;
@@ -1298,16 +1395,18 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
       gen_topo_scale_free (tc, cap, m);
     }
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
-  {
-    const char *filename;
+    {
+      const char *filename;
 
-    filename = va_arg (va, const char *);
+      filename = va_arg (va, const char *);
 
-    GNUNET_assert (NULL != filename);
-    gen_topo_from_file (tc, filename);
-  }
+      GNUNET_assert (NULL != filename);
+      gen_topo_from_file (tc, filename);
+    }
     break;
+
   default:
     GNUNET_break (0);
     GNUNET_free (tc);
@@ -1315,15 +1414,17 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
   }
   do
   {
-    secondary_option = va_arg (va, enum GNUNET_TESTBED_TopologyOption);
+    secondary_option = GNUNET_VA_ARG_ENUM (va, GNUNET_TESTBED_TopologyOption);
 
     switch (secondary_option)
     {
     case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT:
-      overlay->retry_cnt =  va_arg (va, unsigned int);
+      overlay->retry_cnt = va_arg (va, unsigned int);
       break;
+
     case GNUNET_TESTBED_TOPOLOGY_OPTION_END:
       break;
+
     default:
       GNUNET_break (0);         /* Should not use any other option apart from
                                  * the ones handled here */
@@ -1337,9 +1438,10 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
                                          &opstart_overlay_configure_topology,
                                          &oprelease_overlay_configure_topology);
   GNUNET_TESTBED_operation_queue_insert_
-      (c->opq_parallel_topology_config_operations, op);
+    (c->opq_parallel_topology_config_operations, op);
   GNUNET_TESTBED_operation_begin_wait_ (op);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Generated %u connections\n",
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Generated %u connections\n",
        tc->link_array_size);
   if (NULL != max_connections)
     *max_connections = tc->link_array_size;
@@ -1375,7 +1477,8 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
                                            GNUNET_TESTBED_TopologyCompletionCallback
                                            comp_cb,
                                            void *comp_cb_cls,
-                                           enum GNUNET_TESTBED_TopologyOption topo,
+                                           enum GNUNET_TESTBED_TopologyOption
+                                           topo,
                                            ...)
 {
   struct GNUNET_TESTBED_Operation *op;
@@ -1399,8 +1502,8 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
  * @param topology where to write the retrieved topology
  * @param topology_string The string to attempt to
  *        get a configuration value from
- * @return GNUNET_YES if topology string matched a
- *         known topology, GNUNET_NO if not
+ * @return #GNUNET_YES if topology string matched a
+ *         known topology, #GNUNET_NO if not
  */
 int
 GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
@@ -1414,6 +1517,8 @@ GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
     {
       if (NULL != topology)
         *topology = (enum GNUNET_TESTBED_TopologyOption) cnt;
+      GNUNET_assert (GNUNET_TESTBED_TOPOLOGY_OPTION_END !=
+                     (enum GNUNET_TESTBED_TopologyOption) cnt);
       return GNUNET_YES;
     }
   }
@@ -1444,14 +1549,14 @@ GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
  *          generated
  * @param proc the underlay link processor callback.  Will be called for each
  *          underlay link generated unless a previous call to this callback
- *          returned GNUNET_SYSERR.  Cannot be NULL.
- * @param cls closure for proc
+ *          returned #GNUNET_SYSERR.  Cannot be NULL.
+ * @param cls closure for @a proc
  * @param ... variable arguments denoting the topology and its parameters.  They
  *          should start with the type of topology to generate followed by their
  *          options.
- * @return GNUNET_OK if underlay link generation is successful; GNUNET_SYSERR
+ * @return #GNUNET_OK if underlay link generation is successful; #GNUNET_SYSERR
  *          upon error in generating the underlay or if any calls to the
- *          underlay link processor returned GNUNET_SYSERR
+ *          underlay link processor returned #GNUNET_SYSERR
  */
 int
 GNUNET_TESTBED_underlay_construct_ (int num_peers,
@@ -1466,40 +1571,51 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers,
   enum GNUNET_TESTBED_TopologyOption topology;
   unsigned int cnt;
   int ret;
-  
+
   GNUNET_assert (NULL != proc);
   ret = GNUNET_OK;
-  memset (&tc, 0, sizeof (tc));
+  memset (&tc, 0, sizeof(tc));
   tc.num_peers = num_peers;
   tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
   underlay = &tc.u.underlay;
   va_start (vargs, cls);
-  topology = va_arg (vargs, enum GNUNET_TESTBED_TopologyOption);
+  topology = GNUNET_VA_ARG_ENUM (vargs, GNUNET_TESTBED_TopologyOption);
   switch (topology)
   {
   case GNUNET_TESTBED_TOPOLOGY_LINE:
     gen_topo_line (&tc);
     break;
+
+  case GNUNET_TESTBED_TOPOLOGY_STAR:
+    gen_topo_star (&tc);
+    break;
+
   case GNUNET_TESTBED_TOPOLOGY_RING:
     gen_topo_ring (&tc);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
     gen_topo_clique (&tc);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
     gen_topo_2dtorus (&tc);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
     gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
     gen_topo_ring (&tc);
     gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
     gen_topo_2dtorus (&tc);
     gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
     {
       const char *filename;
@@ -1508,6 +1624,7 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers,
       gen_topo_from_file (&tc, filename);
     }
     break;
+
   case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
     {
       uint16_t cap;
@@ -1517,6 +1634,7 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers,
       gen_topo_scale_free (&tc, cap, m);
     }
     break;
+
   default:
     GNUNET_assert (0);
   }
@@ -1539,4 +1657,5 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers,
   return ret;
 }
 
+
 /* end of testbed_api_topology.c */