leak
[oweals/gnunet.git] / src / testing / testing_group.c
index 66bcae842b99bfd9cfd6dc5baeec9bde8b089a08..033ab7d5edc00315a63d50a43ba8eaeddc1d032c 100644 (file)
@@ -1410,6 +1410,10 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
       GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH",
                                              "");
 
+      GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR",
+                                             "YES");
+      GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR",
+                                             "YES");
       GNUNET_free_non_null (control_host);
       GNUNET_free (allowed_hosts);
     }
@@ -1423,6 +1427,10 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
                                              hostname);
       GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "BINDTO",
                                              hostname);
+      GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR",
+                                             "YES");
+      GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR",
+                                             "YES");
       GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM",
                                              allowed_hosts);
       GNUNET_free (allowed_hosts);
@@ -1433,6 +1441,10 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
                                              "127.0.0.1");
       GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "BINDTO",
                                              "127.0.0.1");
+      GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR",
+                                             "YES");
+      GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR",
+                                             "YES");
     }
 
   *port = (uint16_t) uc.nport;
@@ -2513,7 +2525,7 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
   struct stat frstat;
   int count;
   char *data;
-  char *buf;
+  const char *buf;
   unsigned int total_peers;
   enum States curr_state;
 
@@ -2556,79 +2568,80 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
 
       switch (curr_state)
         {
-      case NUM_PEERS:
-        errno = 0;
-        total_peers = strtoul(&buf[count], NULL, 10);
-        if (errno != 0)
-          {
-            GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                        "Failed to read number of peers from topology file!\n");
-            GNUNET_free_non_null(data);
-            return connect_attempts;
-          }
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                    "Read %u total peers in topology\n", total_peers);
-        GNUNET_assert(total_peers == pg->total);
-        curr_state = PEER_INDEX;
-        while ((buf[count] != '\n') && (count < frstat.st_size - 1))
-          count++;
-        count++;
-        break;
-      case PEER_INDEX:
-        errno = 0;
-        first_peer_index = strtoul(&buf[count], NULL, 10);
-        if (errno != 0)
-          {
-            GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                        "Failed to read peer index from topology file!\n");
-            GNUNET_free_non_null(data);
-            return connect_attempts;
-          }
-        while ((buf[count] != ':') && (count < frstat.st_size - 1))
-          count++;
-        count++;
-        curr_state = OTHER_PEER_INDEX;
-        break;
-      case COLON:
-        if (1 == sscanf (&buf[count], ":"))
-          curr_state = OTHER_PEER_INDEX;
-        count++;
-        break;
-      case OTHER_PEER_INDEX:
-        errno = 0;
-        second_peer_index = strtoul(&buf[count], NULL, 10);
-        if (errno != 0)
-          {
-            GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                        "Failed to peer index from topology file!\n");
-            GNUNET_free_non_null(data);
-            return connect_attempts;
-          }
-        /* Assume file is written with first peer 1, but array index is 0 */
-        connect_attempts += proc (pg, first_peer_index - 1, second_peer_index
-                                  - 1, list, GNUNET_YES);
-        while ((buf[count] != '\n') && (buf[count] != ',') && (count
-            < frstat.st_size - 1))
-          count++;
-        if (buf[count] == '\n')
-          {
-            curr_state = PEER_INDEX;
-          }
-        else if (buf[count] != ',')
-          {
-            curr_state = OTHER_PEER_INDEX;
-          }
-        count++;
-        break;
-      default:
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Found bad data in topology file while in state %d!\n",
-                    curr_state);
-        GNUNET_break(0);
-        return connect_attempts;
+       case NUM_PEERS:
+         errno = 0;
+         total_peers = strtoul(&buf[count], NULL, 10);
+         if (errno != 0)
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                         "Failed to read number of peers from topology file!\n");
+             GNUNET_free (data);
+             return connect_attempts;
+           }
+         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                     "Read %u total peers in topology\n", total_peers);
+         GNUNET_assert(total_peers == pg->total);
+         curr_state = PEER_INDEX;
+         while ((buf[count] != '\n') && (count < frstat.st_size - 1))
+           count++;
+         count++;
+         break;
+       case PEER_INDEX:
+         errno = 0;
+         first_peer_index = strtoul(&buf[count], NULL, 10);
+         if (errno != 0)
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                         "Failed to read peer index from topology file!\n");
+             GNUNET_free (data);
+             return connect_attempts;
+           }
+         while ((buf[count] != ':') && (count < frstat.st_size - 1))
+           count++;
+         count++;
+         curr_state = OTHER_PEER_INDEX;
+         break;
+       case COLON:
+         if (1 == sscanf (&buf[count], ":"))
+           curr_state = OTHER_PEER_INDEX;
+         count++;
+         break;
+       case OTHER_PEER_INDEX:
+         errno = 0;
+         second_peer_index = strtoul(&buf[count], NULL, 10);
+         if (errno != 0)
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                         "Failed to peer index from topology file!\n");
+             GNUNET_free (data);
+             return connect_attempts;
+           }
+         /* Assume file is written with first peer 1, but array index is 0 */
+         connect_attempts += proc (pg, first_peer_index - 1, second_peer_index
+                                   - 1, list, GNUNET_YES);
+         while ((buf[count] != '\n') && (buf[count] != ',') && (count
+                                                                < frstat.st_size - 1))
+           count++;
+         if (buf[count] == '\n')
+           {
+             curr_state = PEER_INDEX;
+           }
+         else if (buf[count] != ',')
+           {
+             curr_state = OTHER_PEER_INDEX;
+           }
+         count++;
+         break;
+       default:
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     "Found bad data in topology file while in state %d!\n",
+                     curr_state);
+         GNUNET_break(0);
+         GNUNET_free (data);
+         return connect_attempts;
         }
-
     }
+  GNUNET_free (data);
   return connect_attempts;
 }
 
@@ -3237,7 +3250,6 @@ send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext
         while (conn != NULL)
           {
             GNUNET_CORE_peer_request_connect(send_hello_context->peer->daemon->server,
-                GNUNET_TIME_relative_get_forever(),
                 &send_hello_context->pg->peers[conn->index].daemon->id,
                 NULL,
                 NULL);
@@ -5901,15 +5913,28 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                            &hostkeys_file))
     {
       if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!\n");
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 
+                   _("Could not read hostkeys file!\n"));
       else
         {
           /* Check hostkey file size, read entire thing into memory */
-          fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ,
+          fd = GNUNET_DISK_file_open (hostkeys_file,
+                                     GNUNET_DISK_OPEN_READ,
                                       GNUNET_DISK_PERM_NONE);
           if (NULL == fd)
             {
-              GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_file);
+              GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 
+                                       "open", 
+                                       hostkeys_file);
+             GNUNET_free (hostkeys_file);
+             for (i=0;i<pg->num_hosts;i++)
+               {
+                 GNUNET_free (pg->hosts[i].hostname);
+                 GNUNET_free_non_null (pg->hosts[i].username);
+               }
+             GNUNET_free (pg->peers);
+             GNUNET_free (pg->hosts);
+             GNUNET_free (pg);
               return NULL;
             }
 
@@ -5917,12 +5942,11 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                    GNUNET_YES))
             fs = 0;
 
-          GNUNET_log (
-                      GNUNET_ERROR_TYPE_DEBUG,
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Found file size %llu for hostkeys, expect hostkeys to be size %d\n",
                       fs, HOSTKEYFILESIZE);
 
-          if (fs % HOSTKEYFILESIZE != 0)
+          if (0 != (fs % HOSTKEYFILESIZE))
             {
               GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                           "File size %llu seems incorrect for hostkeys...\n",
@@ -5932,11 +5956,12 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
             {
               total_hostkeys = fs / HOSTKEYFILESIZE;
               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                          "Will read %llu hostkeys from file\n", total_hostkeys);
+                          "Will read %llu hostkeys from file\n",
+                         total_hostkeys);
               pg->hostkey_data = GNUNET_malloc_large (fs);
               GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs));
-              GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd));
             }
+         GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd));
         }
       GNUNET_free(hostkeys_file);
     }
@@ -6092,8 +6117,7 @@ GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg,
 {
   if (position < pg->total)
     return pg->peers[position].daemon;
-  else
-    return NULL;
+  return NULL;
 }
 
 /*
@@ -6117,7 +6141,6 @@ GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg,
                        sizeof(struct GNUNET_PeerIdentity)))
         return pg->peers[i].daemon;
     }
-
   return NULL;
 }
 
@@ -6131,7 +6154,7 @@ GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg,
  * @param d handle to the daemon that was restarted
  * @param emsg NULL on success
  */
-void
+static void
 restart_callback(void *cls, const struct GNUNET_PeerIdentity *id,
                  const struct GNUNET_CONFIGURATION_Handle *cfg,
                  struct GNUNET_TESTING_Daemon *d, const char *emsg)
@@ -6170,7 +6193,7 @@ restart_callback(void *cls, const struct GNUNET_PeerIdentity *id,
  * @param emsg NULL on success, non-NULL on failure
  *
  */
-void
+static void
 churn_stop_callback(void *cls, const char *emsg)
 {
   struct ShutdownContext *shutdown_ctx = cls;
@@ -6274,6 +6297,7 @@ schedule_churn_shutdown_task(void *cls,
     }
 }
 
+
 /**
  * Simulate churn by stopping some peers (and possibly
  * re-starting others if churn is called multiple times).  This
@@ -6469,6 +6493,7 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg,
   GNUNET_free_non_null (stopped_permute);
 }
 
+
 /**
  * Restart all peers in the given group.
  *
@@ -6500,6 +6525,7 @@ GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg,
     }
 }
 
+
 /**
  * Start or stop an individual peer from the given group.
  *
@@ -6556,13 +6582,14 @@ GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg,
     GNUNET_break (0);
 }
 
+
 /**
  * Callback for shutting down peers in a peer group.
  *
  * @param cls closure (struct ShutdownContext)
  * @param emsg NULL on success
  */
-void
+static void
 internal_shutdown_callback(void *cls, const char *emsg)
 {
   struct PeerShutdownContext *peer_shutdown_ctx = cls;
@@ -6612,6 +6639,7 @@ internal_shutdown_callback(void *cls, const char *emsg)
   GNUNET_free(peer_shutdown_ctx);
 }
 
+
 /**
  * Task to rate limit the number of outstanding peer shutdown
  * requests.  This is necessary for making sure we don't do
@@ -6651,6 +6679,7 @@ schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 }
 
+
 /**
  * Shutdown all peers started in the given group.
  *
@@ -6729,12 +6758,12 @@ GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg,
         }
 #else
       if (pg->peers[off].allowed_peers != NULL)
-      GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers);
+       GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers);
       if (pg->peers[off].connect_peers != NULL)
-      GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers);
+       GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers);
       if (pg->peers[off].blacklisted_peers != NULL)
-      GNUNET_CONTAINER_multihashmap_destroy (pg->
-          peers[off].blacklisted_peers);
+       GNUNET_CONTAINER_multihashmap_destroy (pg->
+                                              peers[off].blacklisted_peers);
 #endif
     }
 }