-ensure stats queues do not grow too big
[oweals/gnunet.git] / src / testbed / testbed_api_topology.c
index f23a771f9ebc2c58d8e9c12fe1fd7397f6993525..1f7d11b27312e58d378f33c911a90d7f4962f5af 100644 (file)
@@ -1,6 +1,6 @@
 /*
       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
@@ -14,8 +14,8 @@
 
       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.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -217,12 +217,12 @@ struct TopologyContext
    * The type of this context
    */
   enum {
-    
+
     /**
      * Type for underlay topology
      */
     TOPOLOGYCONTEXT_TYPE_UNDERLAY = 0,
-    
+
     /**
      * Type for overlay topology
      */
@@ -475,7 +475,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];
@@ -490,7 +490,7 @@ make_link (unsigned int offset, uint32_t A, uint32_t B,
     {
       struct TopologyContextUnderlay *underlay;
       struct UnderlayLink *ulink;
-      
+
       underlay = &tc->u.underlay;
       GNUNET_assert (offset < tc->link_array_size);
       ulink = &underlay->link_array[offset];
@@ -518,7 +518,7 @@ 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);
@@ -527,7 +527,7 @@ gen_topo_line (struct TopologyContext *tc)
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
-      
+
       underlay = &tc->u.underlay;
       underlay->link_array =
           GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
@@ -564,7 +564,7 @@ gen_topo_ring (struct TopologyContext *tc)
   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
     {
       struct TopologyContextUnderlay *underlay;
-      
+
       underlay = &tc->u.underlay;
       underlay->link_array =
           GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) *
@@ -656,7 +656,7 @@ gen_topo_2dtorus (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);
@@ -714,11 +714,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;
@@ -802,7 +804,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;
@@ -903,9 +907,9 @@ 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 = 
+      overlay->link_array =
           GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size);
     }
     break;
@@ -929,7 +933,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;
@@ -957,20 +962,24 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
   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;
   }
@@ -1048,9 +1057,9 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
         case TOPOLOGYCONTEXT_TYPE_OVERLAY:
           {
             struct TopologyContextOverlay *overlay;
-            
+
             overlay = &tc->u.overlay;
-            overlay->link_array = 
+            overlay->link_array =
                 GNUNET_realloc (overlay->link_array,
                                 sizeof (struct OverlayLink) * tc->link_array_size);
           }
@@ -1058,7 +1067,7 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
         case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
           {
             struct TopologyContextUnderlay *underlay;
-            
+
             underlay = &tc->u.underlay;
             underlay->link_array =
                 GNUNET_realloc (underlay->link_array,
@@ -1071,7 +1080,8 @@ 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++;
@@ -1091,14 +1101,15 @@ _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;
@@ -1107,7 +1118,7 @@ _exit:
     case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
       {
         struct TopologyContextUnderlay *underlay;
-        
+
         underlay = &tc->u.underlay;
         GNUNET_free_non_null (underlay->link_array);
         underlay->link_array = NULL;
@@ -1129,7 +1140,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,8 +1149,8 @@ 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:
@@ -1147,8 +1158,8 @@ gen_topo_clique (struct TopologyContext *tc)
       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 +1180,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 +1205,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 +1231,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
@@ -1339,7 +1350,8 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
   GNUNET_TESTBED_operation_queue_insert_
       (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;
@@ -1399,8 +1411,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,
@@ -1444,14 +1456,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,7 +1478,7 @@ 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));