[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8329 - GNUnet/src/applications/testing
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8329 - GNUnet/src/applications/testing |
Date: |
Wed, 11 Mar 2009 16:15:08 -0600 |
Author: nevans
Date: 2009-03-11 16:15:08 -0600 (Wed, 11 Mar 2009)
New Revision: 8329
Modified:
GNUnet/src/applications/testing/remote.c
GNUnet/src/applications/testing/remote.h
GNUnet/src/applications/testing/remotetopologies.c
Log:
changed api
Modified: GNUnet/src/applications/testing/remote.c
===================================================================
--- GNUnet/src/applications/testing/remote.c 2009-03-11 22:00:19 UTC (rev
8328)
+++ GNUnet/src/applications/testing/remote.c 2009-03-11 22:15:08 UTC (rev
8329)
@@ -53,44 +53,157 @@
{
char *cmd;
int length;
+ unsigned int is_local = 0;
- length =
- snprintf (NULL, 0, "scp %s%s address@hidden:%s", localConfigPath,
configFileName,
- username, hostname, remote_config_path);
- cmd = GNUNET_malloc (length + 1);
- GNUNET_snprintf (cmd, length + 1, "scp %s%s address@hidden:%s",
localConfigPath,
- configFileName, username, hostname, remote_config_path);
+ if (strcmp (hostname, "localhost") == 0)
+ {
+ is_local = 1;
+ }
+ if (is_local)
+ {
+ length =
+ snprintf (NULL, 0, "cp %s%s %s", localConfigPath, configFileName,
+ remote_config_path);
+ cmd = GNUNET_malloc (length + 1);
+ GNUNET_snprintf (cmd, length + 1, "cp %s%s %s", localConfigPath,
+ configFileName, remote_config_path);
+ }
+ else
+ {
+ length =
+ snprintf (NULL, 0, "scp %s%s address@hidden:%s", localConfigPath,
+ configFileName, username, hostname, remote_config_path);
+ cmd = GNUNET_malloc (length + 1);
+ GNUNET_snprintf (cmd, length + 1, "scp %s%s address@hidden:%s",
localConfigPath,
+ configFileName, username, hostname,
+ remote_config_path);
+ }
/* To me this seems like information that will always be appreciated by the
user
* if this is contested by anyone, please mark it here as well as how it
should be
* done, and I can change it everywhere else by example! NE
*/
- fprintf (stderr, _("scp command is : %s \n"), cmd);
+ fprintf (stderr, _("cp command is : %s \n"), cmd);
system (cmd);
GNUNET_free (cmd);
- length =
- snprintf (NULL, 0, "ssh address@hidden %sgnunet-update -c %s%s", username,
- hostname, gnunetd_home, remote_config_path, configFileName);
- cmd = GNUNET_malloc (length + 1);
- snprintf (cmd, length + 1, "ssh address@hidden %sgnunet-update -c %s%s",
username,
- hostname, gnunetd_home, remote_config_path, configFileName);
+ if (is_local)
+ {
+ length =
+ snprintf (NULL, 0, "%sgnunet-update -c %s%s", gnunetd_home,
+ remote_config_path, configFileName);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "%sgnunet-update -c %s%s", gnunetd_home,
+ remote_config_path, configFileName);
+ }
+ else
+ {
+ length =
+ snprintf (NULL, 0, "ssh address@hidden %sgnunet-update -c %s%s",
username,
+ hostname, gnunetd_home, remote_config_path, configFileName);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "ssh address@hidden %sgnunet-update -c %s%s",
+ username, hostname, gnunetd_home, remote_config_path,
+ configFileName);
+ }
+ fprintf (stderr, _("exec command is : %s \n"), cmd);
- fprintf (stderr, _("ssh command is : %s \n"), cmd);
+ system (cmd);
+ GNUNET_free (cmd);
+ if (is_local)
+ {
+ length =
+ snprintf (NULL, 0, "%sgnunetd -d -c %s%s &",
+ gnunetd_home, remote_config_path, configFileName);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "%sgnunetd -d -c %s%s &", gnunetd_home,
+ remote_config_path, configFileName);
+ }
+ else
+ {
+ length =
+ snprintf (NULL, 0, "ssh address@hidden %sgnunetd -d -c %s%s &",
username,
+ hostname, gnunetd_home, remote_config_path, configFileName);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "ssh address@hidden %sgnunetd -d -c %s%s &",
+ username, hostname, gnunetd_home, remote_config_path,
+ configFileName);
+
+ }
+
+ fprintf (stderr, _("exec command is : %s \n"), cmd);
+
system (cmd);
+
GNUNET_free (cmd);
- length =
- snprintf (NULL, 0, "ssh address@hidden %sgnunetd -c %s%s", username,
hostname,
- gnunetd_home, remote_config_path, configFileName);
- cmd = GNUNET_malloc (length + 1);
- snprintf (cmd, length + 1, "ssh address@hidden %sgnunetd -c %s%s", username,
- hostname, gnunetd_home, remote_config_path, configFileName);
- fprintf (stderr, _("ssh command is : %s \n"), cmd);
+ return GNUNET_OK;
+}
+int
+GNUNET_REMOTE_kill_daemon (struct GNUNET_REMOTE_TESTING_DaemonContext *tokill)
+{
+ char *cmd;
+ int length;
+ unsigned int is_local = 0;
+ FILE *output;
+ pid_t pid;
+
+ if (strcmp (tokill->hostname, "localhost") == 0)
+ {
+ is_local = 1;
+ }
+
+ if (is_local)
+ {
+ length = snprintf (NULL, 0, "cat %s", tokill->pid);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "cat %s", tokill->pid);
+ }
+ else
+ {
+ length =
+ snprintf (NULL, 0, "ssh address@hidden cat %s", tokill->username,
+ tokill->hostname, tokill->pid);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "ssh address@hidden cat %s", tokill->username,
+ tokill->hostname, tokill->pid);
+ }
+ fprintf (stderr, _("exec command is : %s \n"), cmd);
+
+ output = popen (cmd, "r");
+ GNUNET_free (cmd);
+ if (fscanf (output, "%d", &pid) == 1)
+ {
+ fprintf (stderr, "Got pid %d\n", pid);
+ }
+ else
+ {
+ return -1;
+ }
+
+ if (is_local)
+ {
+ length = snprintf (NULL, 0, "kill %d", pid);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "kill %d", pid);
+ }
+ else
+ {
+ length =
+ snprintf (NULL, 0, "ssh address@hidden kill %d", tokill->username,
+ tokill->hostname, pid);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "ssh address@hidden kill %d",
+ tokill->username, tokill->hostname, pid);
+
+ }
+
+ fprintf (stderr, _("exec command is : %s \n"), cmd);
+
system (cmd);
GNUNET_free (cmd);
@@ -99,17 +212,24 @@
return GNUNET_OK;
}
-int
+
+struct GNUNET_REMOTE_TESTING_DaemonContext *
GNUNET_REMOTE_start_daemons (struct GNUNET_GC_Configuration *newcfg,
unsigned long long number_of_daemons)
{
struct GNUNET_GC_Configuration *basecfg;
+ struct GNUNET_GC_Configuration *tempcfg;
struct GNUNET_REMOTE_host_list *array_of_pointers[number_of_daemons];
struct GNUNET_REMOTE_host_list *temp_pos;
GNUNET_REMOTE_TOPOLOGIES type_of_topology;
+ struct GNUNET_REMOTE_TESTING_DaemonContext *ret_peers;
+ struct GNUNET_REMOTE_TESTING_DaemonContext *next_peer;
+
+ ret_peers = NULL;
list_as_array = &array_of_pointers[0];
FILE *dotOutFile;
+ char host[128];
char *ssh_username;
char *control_host;
char *percentage_string;
@@ -281,8 +401,8 @@
"GNUNETD", "PIDFILE",
temp_pid_file);
- GNUNET_free (temp_pid_file);
+
temp_remote_config_path_length =
snprintf (NULL, 0, "%s%d", remote_config_path, j);
temp_remote_config_path =
@@ -350,6 +470,27 @@
curr_host, ssh_username,
temp_pos->remote_friend_file_path);
+ next_peer =
+ GNUNET_malloc (sizeof
+ (struct GNUNET_REMOTE_TESTING_DaemonContext));
+ next_peer->next = ret_peers;
+ next_peer->hostname = GNUNET_strdup (curr_host);
+ next_peer->username = GNUNET_strdup (ssh_username);
+ next_peer->port = starting_port + (j * port_increment);
+ next_peer->pid = GNUNET_strdup (temp_pid_file);
+ tempcfg = GNUNET_GC_create ();
+ GNUNET_snprintf (host, 128, "%s:%u", next_peer->hostname,
+ next_peer->port);
+ GNUNET_GC_set_configuration_value_string (tempcfg, NULL,
+ "NETWORK", "HOST",
+ host);
+ next_peer->config = tempcfg;
+ next_peer->peer =
+ GNUNET_REMOTE_get_daemon_information (next_peer->hostname,
+ next_peer->port);
+
+ ret_peers = next_peer;
+
GNUNET_GC_get_configuration_value_number (basecfg,
"NETWORK",
"PORT",
@@ -361,7 +502,7 @@
array_of_pointers[count_started] = temp_pos;
count_started++;
}
-
+ GNUNET_free (temp_pid_file);
GNUNET_free (temp_remote_config_path);
GNUNET_free (temp);
UNLINK (temp_path);
@@ -369,6 +510,31 @@
if ((i < extra_daemons) && (j == daemons_per_machine - 1))
{
+
+ basecfg = GNUNET_GC_create ();
+
+ if (-1 == GNUNET_GC_parse_configuration (basecfg, base_config))
+ {
+ ret = GNUNET_SYSERR;
+ break;
+ }
+
+ GNUNET_GC_set_configuration_value_number (basecfg, NULL,
+ "NETWORK", "PORT",
+ starting_port);
+ GNUNET_GC_set_configuration_value_number (basecfg, NULL, "TCP",
+ "PORT",
+ starting_port + 1);
+ GNUNET_GC_set_configuration_value_number (basecfg, NULL, "UDP",
+ "PORT",
+ starting_port + 1);
+ GNUNET_GC_set_configuration_value_string (basecfg, NULL,
+ "NETWORK", "TRUSTED",
+ control_host);
+ GNUNET_GC_set_configuration_value_string (basecfg, NULL,
+ "PATHS",
+ "GNUNETD_HOME",
+ remote_config_path);
length_temp =
snprintf (NULL, 0, "%s%s%d", remote_pid_path, "pid", j + 1);
temp_pid_file = GNUNET_malloc (length_temp + 1);
@@ -379,7 +545,6 @@
"GNUNETD",
"PIDFILE",
temp_pid_file);
- GNUNET_free (temp_pid_file);
temp_remote_config_path_length =
snprintf (NULL, 0, "%s%d", remote_config_path, j);
@@ -457,6 +622,28 @@
temp_pos->
remote_friend_file_path);
+ next_peer =
+ GNUNET_malloc (sizeof
+ (struct
+ GNUNET_REMOTE_TESTING_DaemonContext));
+ next_peer->next = ret_peers;
+ next_peer->hostname = GNUNET_strdup (curr_host);
+ next_peer->port =
+ starting_port + ((j + 1) * port_increment);
+ next_peer->username = GNUNET_strdup (ssh_username);
+ next_peer->pid = GNUNET_strdup (temp_pid_file);
+ tempcfg = GNUNET_GC_create ();
+ GNUNET_snprintf (host, 128, "%s:%u", next_peer->hostname,
+ next_peer->port);
+ GNUNET_GC_set_configuration_value_string (tempcfg, NULL,
+ "NETWORK", "HOST",
+ host);
+ next_peer->config = tempcfg;
+ next_peer->peer =
+ GNUNET_REMOTE_get_daemon_information (next_peer->hostname,
+ next_peer->port);
+ ret_peers = next_peer;
+
GNUNET_GC_get_configuration_value_number (basecfg,
"NETWORK",
"PORT",
@@ -469,6 +656,8 @@
array_of_pointers[count_started] = temp_pos;
count_started++;
}
+
+ GNUNET_free (temp_pid_file);
GNUNET_free (temp_remote_config_path);
UNLINK (temp_path);
GNUNET_free (temp_path);
@@ -499,7 +688,7 @@
GNUNET_free (remote_config_path);
GNUNET_free (remote_gnunetd_path);
- return ret;
+ return ret_peers;
}
int
@@ -540,6 +729,9 @@
fprintf (stderr, "Creating Erdos-Renyi topology\n");
ret = GNUNET_REMOTE_connect_erdos_renyi (percentage, head, dotOutFile);
break;
+ case GNUNET_REMOTE_NONE:
+ return ret;
+ break;
default:
ret = GNUNET_SYSERR;
break;
@@ -564,14 +756,26 @@
}
fclose (temp_friend_handle);
- length =
- snprintf (NULL, 0, "scp %s address@hidden:%s", "friend.temp",
- pos->username, pos->hostname,
- pos->remote_friend_file_path);
- cmd = GNUNET_malloc (length + 1);
- snprintf (cmd, length + 1, "scp %s address@hidden:%s", "friend.temp",
- pos->username, pos->hostname,
- pos->remote_friend_file_path);
+ if (strcmp (pos->hostname, "localhost") == 0)
+ {
+ length =
+ snprintf (NULL, 0, "cp %s %s", "friend.temp",
+ pos->remote_friend_file_path);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "cp %s %s", "friend.temp",
+ pos->remote_friend_file_path);
+ }
+ else
+ {
+ length =
+ snprintf (NULL, 0, "scp %s address@hidden:%s", "friend.temp",
+ pos->username, pos->hostname,
+ pos->remote_friend_file_path);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf (cmd, length + 1, "scp %s address@hidden:%s",
"friend.temp",
+ pos->username, pos->hostname,
+ pos->remote_friend_file_path);
+ }
fprintf (stderr, _("scp command for friend file copy is : %s \n"),
cmd);
Modified: GNUnet/src/applications/testing/remote.h
===================================================================
--- GNUnet/src/applications/testing/remote.h 2009-03-11 22:00:19 UTC (rev
8328)
+++ GNUnet/src/applications/testing/remote.h 2009-03-11 22:15:08 UTC (rev
8329)
@@ -98,7 +98,11 @@
int number_of_daemons, FILE * dotOufFile,
double percentage);
+GNUNET_PeerIdentity *GNUNET_REMOTE_get_daemon_information (char *hostname,
+ unsigned short
+ port);
+
#endif /*REMOTE_H_ */
/* end of remote.h */
Modified: GNUnet/src/applications/testing/remotetopologies.c
===================================================================
--- GNUnet/src/applications/testing/remotetopologies.c 2009-03-11 22:00:19 UTC
(rev 8328)
+++ GNUnet/src/applications/testing/remotetopologies.c 2009-03-11 22:15:08 UTC
(rev 8329)
@@ -72,7 +72,8 @@
&node2))
{
temp_rand = ((double) RANDOM () / RAND_MAX);
- fprintf(stderr, "rand is %f probability is
%f\n",temp_rand,probability);
+ fprintf (stderr, "rand is %f probability is %f\n", temp_rand,
+ probability);
if (temp_rand < probability)
{
node1temp =
@@ -384,6 +385,7 @@
* @param port2 client port of the second daemon
* @param ip1 client ip or hostname for the first daemon
* @param ip2 client ip or hostname for the second daemon
+* @param dotOutFile file to write dot style graph info to
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
@@ -576,6 +578,60 @@
return ret;
}
+GNUNET_PeerIdentity *
+GNUNET_REMOTE_get_daemon_information (char *hostname, unsigned short port)
+{
+ char host[128];
+ struct GNUNET_GC_Configuration *cfg1 = GNUNET_GC_create ();
+ struct GNUNET_ClientServerConnection *sock1;
+ GNUNET_PeerIdentity *retval;
+ int ret;
+ GNUNET_MessageHello *h1;
+ ret = GNUNET_SYSERR;
+ GNUNET_snprintf (host, 128, "%s:%u", hostname, port);
+ GNUNET_GC_set_configuration_value_string (cfg1, NULL, "NETWORK", "HOST",
+ host);
+ retval = NULL;
+ if (GNUNET_OK ==
+ GNUNET_wait_for_daemon_running (NULL, cfg1, 30 * GNUNET_CRON_SECONDS))
+ {
+ sock1 = GNUNET_client_connection_create (NULL, cfg1);
+
+ ret = -20;
+ while ((ret++ < -1) && (GNUNET_shutdown_test () == GNUNET_NO))
+ {
+ h1 = NULL;
+
+ if (GNUNET_OK == GNUNET_IDENTITY_get_self (sock1, &h1))
+ {
+ ret = GNUNET_OK;
+ break;
+ }
+
+ GNUNET_thread_sleep (100 * GNUNET_CRON_MILLISECONDS);
+ }
+ if (ret == GNUNET_OK)
+ {
+ retval = GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
+ memcpy (retval, &h1->senderIdentity, sizeof (GNUNET_PeerIdentity));
+ }
+
+ GNUNET_free_non_null (h1);
+
+ GNUNET_client_connection_destroy (sock1);
+ }
+ else
+ {
+ fprintf (stderr, _("Failed to establish connection with peers.\n"));
+ }
+ GNUNET_GC_free (cfg1);
+ if (ret != GNUNET_SYSERR)
+ return retval;
+ else
+ return NULL;
+}
+
+
/* end of remotetopologies.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8329 - GNUnet/src/applications/testing,
gnunet <=