return;
}
d->hostkeybuf[103] = '\0';
+
if ((bytes_read < 0) ||
(GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
&d->id.hashPubKey)))
* (use NULL for localhost).
* @param ssh_username ssh username to use when connecting to hostname
* @param sshport port to pass to ssh process when connecting to hostname
+ * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
* @param hostkey_callback function to call once the hostkey has been
* generated for this peer, but it hasn't yet been started
* (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
const char *hostname,
const char *ssh_username,
uint16_t sshport,
+ const char *hostkey,
GNUNET_TESTING_NotifyHostkeyCreated
hostkey_callback, void *hostkey_cls,
GNUNET_TESTING_NotifyDaemonRunning cb,
struct GNUNET_TESTING_Daemon *ret;
char *arg;
char *username;
+ char *servicehome;
+ char *hostkeyfile;
+ struct GNUNET_DISK_FileHandle *fn;
ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
GNUNET_CONFIGURATION_set_value_string (ret->cfg,
"PATHS",
"DEFAULTCONFIG", ret->cfgfile);
+ if (hostkey != NULL)
+ {
+ GNUNET_assert(GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (ret->cfg,
+ "PATHS",
+ "SERVICEHOME",
+ &servicehome));
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome));
+ GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome);
+ fn =
+ GNUNET_DISK_file_open (hostkeyfile,
+ GNUNET_DISK_OPEN_READWRITE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_assert(fn != NULL);
+ GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE));
+ GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn));
+ GNUNET_free(servicehome);
+ GNUNET_free(hostkeyfile);
+ }
+
/* 1) write configuration to temporary file */
if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
{
*/
const char *username;
+ /**
+ * Pointer to starting memory location of a hostkey
+ */
+ const char *hostkey;
+
/**
* Port to use for ssh.
*/
uint32_t first_uid;
};
+struct RandomContext
+{
+ /**
+ * The peergroup
+ */
+ struct GNUNET_TESTING_PeerGroup *pg;
+
+ /**
+ * uid of the first peer
+ */
+ uint32_t first_uid;
+
+ /**
+ * Peer data for first peer.
+ */
+ struct PeerData *first;
+
+ /**
+ * Random percentage to use
+ */
+ double percentage;
+};
+
+struct MinimumContext
+{
+ /**
+ * The peergroup
+ */
+ struct GNUNET_TESTING_PeerGroup *pg;
+
+ /**
+ * uid of the first peer
+ */
+ uint32_t first_uid;
+
+ /**
+ * Peer data for first peer.
+ */
+ struct PeerData *first;
+
+ /**
+ * Number of conns per peer
+ */
+ unsigned int num_to_add;
+
+ /**
+ * Permuted array of all possible connections. Only add the Nth
+ * peer if it's in the Nth position.
+ */
+ unsigned int *pg_array;
+
+ /**
+ * What number is the current element we are iterating over?
+ */
+ unsigned int current;
+};
+
+struct DFSContext
+{
+ /**
+ * The peergroup
+ */
+ struct GNUNET_TESTING_PeerGroup *pg;
+
+ /**
+ * uid of the first peer
+ */
+ uint32_t first_uid;
+
+ /**
+ * uid of the second peer
+ */
+ uint32_t second_uid;
+
+ /**
+ * Peer data for first peer.
+ */
+ struct PeerData *first;
+
+ /**
+ * Which peer has been chosen as the one to add?
+ */
+ unsigned int chosen;
+
+ /**
+ * What number is the current element we are iterating over?
+ */
+ unsigned int current;
+};
+
/**
* Convert unique ID to hash code.
*
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++;
return connect_attempts;
}
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read second peer index %u\n", second_peer_index);
- while((buf[count] != '\n') && (buf[count] != ' ') && (count < frstat.st_size - 1))
+ /* 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);
+ while((buf[count] != '\n') && (buf[count] != ',') && (count < frstat.st_size - 1))
count++;
if (buf[count] == '\n')
{
curr_state = PEER_INDEX;
}
- else if (buf[count] != ' ')
+ else if (buf[count] != ',')
{
curr_state = OTHER_PEER_INDEX;
}
count++;
- curr_state = OTHER_PEER_INDEX;
break;
default:
GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Found bad data in topology file while in state %d!\n", curr_state);
return num_connections;
}
-struct RandomContext
-{
- /**
- * The peergroup
- */
- struct GNUNET_TESTING_PeerGroup *pg;
-
- /**
- * uid of the first peer
- */
- uint32_t first_uid;
-
- /**
- * Peer data for first peer.
- */
- struct PeerData *first;
-
- /**
- * Random percentage to use
- */
- double percentage;
-};
-
-struct MinimumContext
-{
- /**
- * The peergroup
- */
- struct GNUNET_TESTING_PeerGroup *pg;
-
- /**
- * uid of the first peer
- */
- uint32_t first_uid;
-
- /**
- * Peer data for first peer.
- */
- struct PeerData *first;
-
- /**
- * Number of conns per peer
- */
- unsigned int num_to_add;
-
- /**
- * Permuted array of all possible connections. Only add the Nth
- * peer if it's in the Nth position.
- */
- unsigned int *pg_array;
-
- /**
- * What number is the current element we are iterating over?
- */
- unsigned int current;
-};
-
-struct DFSContext
-{
- /**
- * The peergroup
- */
- struct GNUNET_TESTING_PeerGroup *pg;
-
- /**
- * uid of the first peer
- */
- uint32_t first_uid;
-
- /**
- * uid of the second peer
- */
- uint32_t second_uid;
-
- /**
- * Peer data for first peer.
- */
- struct PeerData *first;
-
- /**
- * Which peer has been chosen as the one to add?
- */
- unsigned int chosen;
-
- /**
- * What number is the current element we are iterating over?
- */
- unsigned int current;
-};
/**
* Iterator for choosing random peers to connect.
internal_context->hostname,
internal_context->username,
internal_context->sshport,
+ internal_context->hostkey,
&internal_hostkey_callback,
internal_context,
&internal_startup_callback,
char *baseservicehome;
char *newservicehome;
char *tmpdir;
+ char *hostkeys_file;
+ char *hostkey_data;
+ struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_CONFIGURATION_Handle *pcfg;
unsigned int off;
unsigned int hostcnt;
uint16_t sshport;
uint32_t upnum;
uint32_t fdnum;
+ uint64_t fs;
+ uint64_t total_hostkeys;
if (0 == total)
{
GNUNET_break (0);
return NULL;
}
+ hostkey_data = NULL;
upnum = 0;
fdnum = 0;
pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup));
hostcnt = 0;
minport = LOW_PORT;
}
+
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE",
+ &hostkeys_file))
+ {
+ if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!");
+ else
+ {
+ /* Check hostkey file size, read entire thing into memory */
+ 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);
+ return NULL;
+ }
+
+ if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES))
+ fs = 0;
+
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE);
+
+ if (fs % HOSTKEYFILESIZE != 0)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "File size %llu seems incorrect for hostkeys...\n", fs);
+ }
+ else
+ {
+ total_hostkeys = fs / HOSTKEYFILESIZE;
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Will read %llu hostkeys from file\n", total_hostkeys);
+ hostkey_data = GNUNET_malloc_large (fs);
+ GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, fs));
+ }
+ }
+ }
+
for (off = 0; off < total; off++)
{
if (hostcnt > 0)
pg->peers[off].internal_context.hostname = hostname;
pg->peers[off].internal_context.username = username;
pg->peers[off].internal_context.sshport = sshport;
+ if (hostkey_data != NULL)
+ pg->peers[off].internal_context.hostkey = &hostkey_data[off * HOSTKEYFILESIZE];
pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
pg->peers[off].internal_context.start_cb = cb;