+ //struct GNUNET_TESTBED_Host **host_array;
+ struct GNUNET_TESTBED_Host *starting_host;
+ char *data;
+ char *buf;
+ char username[256];
+ char hostname[256];
+ uint64_t fs;
+ short int port;
+ int ret;
+ unsigned int offset;
+ unsigned int count;
+
+
+ GNUNET_assert (NULL != filename);
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename);
+ return 0;
+ }
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
+ fs = 0;
+ if (0 == fs)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s has no data\n"), filename);
+ return 0;
+ }
+ data = GNUNET_malloc (fs);
+ if (fs != GNUNET_DISK_fn_read (filename, data, fs))
+ {
+ GNUNET_free (data);
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s cannot be read\n"),
+ filename);
+ return 0;
+ }
+ buf = data;
+ offset = 0;
+ starting_host = NULL;
+ count = 0;
+ while (offset < (fs - 1))
+ {
+ offset++;
+ if (((data[offset] == '\n')) && (buf != &data[offset]))
+ {
+ data[offset] = '\0';
+ ret = SSCANF (buf, "%255[a-zA-Z0-9_]@%255[a-zA-Z0-9.]:%5hd",
+ username, hostname, &port);
+ if (3 == ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully read host %s, port %d and user %s from file\n",
+ hostname, port, username);
+ /* We store hosts in a static list; hence we only require the starting
+ host pointer in that list to access the newly created list of hosts */
+ if (NULL == starting_host)
+ starting_host = GNUNET_TESTBED_host_create (hostname, username,
+ port);
+ else
+ (void) GNUNET_TESTBED_host_create (hostname, username, port);
+ count++;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Error reading line `%s' in hostfile\n", buf);
+ buf = &data[offset + 1];
+ }
+ else if ((data[offset] == '\n') || (data[offset] == '\0'))
+ buf = &data[offset + 1];
+ }
+ GNUNET_free (data);
+ if (NULL == starting_host)
+ return 0;
+ *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count);
+ memcpy (*hosts,
+ &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
+ sizeof (struct GNUNET_TESTBED_Host *) * count);
+ return count;