[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6128 - GNUnet/src/applications/testing
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6128 - GNUnet/src/applications/testing |
Date: |
Sat, 26 Jan 2008 15:37:00 -0700 (MST) |
Author: nevans
Date: 2008-01-26 15:36:59 -0700 (Sat, 26 Jan 2008)
New Revision: 6128
Modified:
GNUnet/src/applications/testing/remote.c
GNUnet/src/applications/testing/remotetest.c
Log:
Modified: GNUnet/src/applications/testing/remote.c
===================================================================
--- GNUnet/src/applications/testing/remote.c 2008-01-25 00:05:46 UTC (rev
6127)
+++ GNUnet/src/applications/testing/remote.c 2008-01-26 22:36:59 UTC (rev
6128)
@@ -39,7 +39,30 @@
const unsigned long long MIN_NUMBER_DAEMONS = 1;
const unsigned long long MAX_NUMBER_DAEMONS = -1;
+void
+updatePort (struct GNUNET_GC_Configuration *cfg,
+ const char *section, unsigned short offset)
+{
+ unsigned long long old;
+ if ((GNUNET_YES == GNUNET_GC_have_configuration_value (cfg,
+ section,
+ "PORT")) &&
+ (0 == GNUNET_GC_get_configuration_value_number (cfg,
+ section,
+ "PORT",
+ 0, 65535, 65535, &old)))
+ {
+ old += offset;
+ GNUNET_GE_ASSERT (NULL,
+ 0 == GNUNET_GC_set_configuration_value_number (cfg,
+ NULL,
+ section,
+ "PORT",
+ old));
+ }
+}
+
/**
* Starts a single gnunet daemon on a remote machine
*
@@ -52,44 +75,27 @@
*/
int
GNUNET_REMOTE_start_daemon (char *gnunetd_home,
- char *localConfigPath,char *configFileName,char
*remote_config_path,char *ip_address,
+ char *localConfigPath,char *configFileName,char
*remote_config_path,char *hostname,
char *username)
{
char *cmd;
- char *newcmd;
+ int length;
- cmd = "scp ";
- newcmd = GNUNET_malloc (strlen (cmd) + strlen(localConfigPath) + 1 +
strlen(configFileName));
- strcpy(newcmd,cmd);
- //strcat(newcmd,(localConfigFile) " " (username) "@" (ip_address) ":"
(remote_config_path));
- strcat(newcmd,localConfigPath);
- strcat(newcmd,configFileName);
- strcat(newcmd," ");
- strcat(newcmd,username);
- strcat(newcmd,"@");
- strcat(newcmd,ip_address);
- strcat(newcmd,":");
- strcat(newcmd,remote_config_path);
+ length = snprintf(NULL,0,"scp %s%s
address@hidden:%s",localConfigPath,configFileName,username,hostname,remote_config_path);
+ cmd = GNUNET_malloc (length + 1);
+ snprintf(cmd,length + 1 ,"scp %s%s
address@hidden:%s",localConfigPath,configFileName,username,hostname,remote_config_path);
- //printf("scp command is : %s \n",newcmd);
- //system(newcmd);
+ printf("scp 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);
- cmd = "ssh ";
- GNUNET_free(newcmd);
- newcmd = GNUNET_malloc (strlen (cmd) + 128);
- strcpy(newcmd,cmd);
- strcat(newcmd,username);
- strcat(newcmd,"@");
- strcat(newcmd,ip_address);
- strcat(newcmd," ");
- strcat(newcmd,gnunetd_home);
- strcat(newcmd, DIR_SEPARATOR_STR "gnunetd -c ");
- strcat(newcmd, remote_config_path);
- strcat(newcmd, configFileName);
+ printf("ssh command is : %s \n",cmd);
- //printf("ssh command is : %s \n",newcmd);
-
- //system(newcmd);
+ //system(cmd);
return GNUNET_OK;
}
@@ -97,86 +103,169 @@
int
GNUNET_REMOTE_start_daemons(struct GNUNET_GC_Configuration **newcfg)
{
+ struct GNUNET_GC_Configuration *basecfg;
-
char *ssh_username;
char *control_host;
char *remote_config_path;
char *remote_gnunetd_path;
+ char *base_config;
unsigned long long starting_port;
unsigned long long port_increment;
unsigned long long number_of_daemons;
- char *client_ips;
+ unsigned long long daemons_per_machine;
+ char *hostnames;
+ char **hostlist;
+ char *temp;
+ char *temp_path;
+
+ unsigned int extra_daemons = 0;
unsigned int count = 0;
unsigned int length;
- unsigned int temp[4];
unsigned int num_machines = 0;
unsigned int i;
unsigned int j;
unsigned int pos;
- unsigned int cnt;
+ int ret;
-
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","SSH_USERNAME",NULL,&ssh_username);
-
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","CONTROL_HOST",NULL,&control_host);
-
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","CLIENT_IPS",NULL,&client_ips);
-
GNUNET_GC_get_configuration_value_number(*newcfg,"MULTIPLE_SERVER_TESTING","STARTING_PORT",MIN_STARTING_PORT,MAX_STARTING_PORT,0,&starting_port);
-
GNUNET_GC_get_configuration_value_number(*newcfg,"MULTIPLE_SERVER_TESTING","PORT_INCREMENT",MIN_PORT_INCREMENT,MAX_PORT_INCREMENT,0,&port_increment);
-
GNUNET_GC_get_configuration_value_number(*newcfg,"MULTIPLE_SERVER_TESTING","NUMBER_OF_DAEMONS",MIN_NUMBER_DAEMONS,MAX_NUMBER_DAEMONS,0,&number_of_daemons);
-
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","REMOTE_CONFIG_PATH",NULL,&remote_config_path);
-
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","REMOTE_GNUNETD_PATH",NULL,&remote_gnunetd_path);
-
-
- //printf("username : %s\n", ssh_username);
- //printf("control host : %s\n", control_host);
- //printf("client ip string : %s\n", client_ips);
- //printf("remote config path : %s\n", remote_config_path);
- //printf("remote gnunetd path : %s\n", remote_gnunetd_path);
-
- //printf("starting port : %lld\n", starting_port);
- //printf("port increment : %lld\n", port_increment);
- //printf("# of daemons : %lld\n", number_of_daemons);
-
- if (client_ips == NULL)
- return GNUNET_SYSERR;
+
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","SSH_USERNAME","",&ssh_username);
+
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","CONTROL_HOST","localhost",&control_host);
+
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","HOSTNAMES","localhost",&hostnames);
+
GNUNET_GC_get_configuration_value_number(*newcfg,"MULTIPLE_SERVER_TESTING","STARTING_PORT",MIN_STARTING_PORT,MAX_STARTING_PORT,1,&starting_port);
+
GNUNET_GC_get_configuration_value_number(*newcfg,"MULTIPLE_SERVER_TESTING","PORT_INCREMENT",MIN_PORT_INCREMENT,MAX_PORT_INCREMENT,2,&port_increment);
+
GNUNET_GC_get_configuration_value_number(*newcfg,"MULTIPLE_SERVER_TESTING","NUMBER_OF_DAEMONS",MIN_NUMBER_DAEMONS,MAX_NUMBER_DAEMONS,1,&number_of_daemons);
+
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","REMOTE_CONFIG_PATH","/tmp/",&remote_config_path);
+
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","REMOTE_GNUNETD_PATH","/tmp",&remote_gnunetd_path);
+
GNUNET_GC_get_configuration_value_string(*newcfg,"MULTIPLE_SERVER_TESTING","BASE_CONFIG","gnunetd.conf.skel",&base_config);
+
+ length = strlen(hostnames);
- length = strlen(client_ips);
-
while(count < length)
{
- if (client_ips[count] == ';')
+ if (hostnames[count] == ' ' || hostnames[count]=='\n')
++num_machines;
++count;
}
+ ++num_machines;
+ hostlist = (char **)malloc(num_machines * sizeof(char *));
+ for (i = 0; i < num_machines; i++)
+ {
+ hostlist[i] = GNUNET_malloc(sizeof(char));
+ }
+
i = 0;
pos = 0;
while (i < num_machines)
+ {
+ temp = GNUNET_malloc(sizeof(char));
+ if (1 == sscanf (&hostnames[pos],"%s",temp))
+ {
+ while(hostnames[pos] != ' ' && hostnames[pos] != '\n' &&
pos<length-1)
+ pos++;
+
+ ++pos;
+ strcpy(hostlist[i],temp);
+ ++i;
+ continue;
+ }
+ GNUNET_free(temp);
+ }
+
+ daemons_per_machine = number_of_daemons / num_machines;
+ extra_daemons = number_of_daemons - (daemons_per_machine * num_machines);
+
+ temp = GNUNET_malloc(sizeof(char));
+ for(i=0;i<num_machines;++i)
{
- cnt = sscanf (&client_ips[pos],
- "%u.%u.%u.%u;",
- &temp[0], &temp[1], &temp[2], &temp[3]);
- if (cnt == 4)
- {
- for (j = 0; j < 4; j++)
- if (temp[j] > 0xFF)
- {
- printf("Error with ip address in config file...\n");
- return NULL;
- }
-
- }
-
- while(client_ips[pos] != ';' && pos<length-1)
- pos++;
- pos++;
- i++;
-
- printf("ip address is %u.%u.%u.%u\n",temp[0],temp[1],temp[2],temp[3]);
+ basecfg = GNUNET_GC_create();
+
+ if (-1 == GNUNET_GC_parse_configuration (basecfg, base_config))
+ {
+ fprintf (stderr,
+ "Failed to read default configuration file `%s'\n",
base_config);
+ GNUNET_GC_free (basecfg);
+ }
+
+ GNUNET_GC_set_configuration_value_number
(basecfg,NULL,"NETWORK","PORT",starting_port);
+ GNUNET_GC_set_configuration_value_number
(basecfg,NULL,"NETWORK","TCP",starting_port + 1);
+ GNUNET_GC_set_configuration_value_number
(basecfg,NULL,"NETWORK","UDP",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);
+
+ for(j=0;j<daemons_per_machine;++j)
+ {
+ updatePort(basecfg,"NETWORK",j*port_increment);
+ updatePort(basecfg,"TCP",j*port_increment);
+ updatePort(basecfg,"UDP",j*port_increment);
+
+ temp_path = GNUNET_strdup ("/tmp/gnunetd.conf.XXXXXX");
+ ret = mkstemp (temp_path);
+
+ if (ret == -1)
+ {
+ GNUNET_GE_LOG_STRERROR_FILE (NULL,
+ GNUNET_GE_ERROR |
GNUNET_GE_USER |
+ GNUNET_GE_BULK, "mkstemp",
temp_path);
+ break;
+ }
+ CLOSE (ret);
+ if (0 != GNUNET_GC_write_configuration (basecfg,
temp_path))
+ {
+ fprintf (stderr,
+ "Failed to write peer configuration file
`%s'\n", temp_path);
+ break;
+ }
+
+ if (1 == sscanf (temp_path,"/tmp/%s",temp))
+ {
+ GNUNET_REMOTE_start_daemon
(remote_gnunetd_path,"/tmp/",temp,remote_config_path,hostlist[j],ssh_username);
+ }
+
+ if ((i<extra_daemons)&&(j==daemons_per_machine-1))
+ {
+ updatePort(basecfg,"NETWORK",(j+1)*port_increment);
+ updatePort(basecfg,"TCP",(j+1)*port_increment);
+ updatePort(basecfg,"UDP",(j+1)*port_increment);
+ temp_path = GNUNET_strdup ("/tmp/gnunetd.conf.XXXXXX");
+ ret = mkstemp (temp_path);
+
+ if (ret == -1)
+ {
+ GNUNET_GE_LOG_STRERROR_FILE (NULL,
+ GNUNET_GE_ERROR |
GNUNET_GE_USER |
+ GNUNET_GE_BULK,
"mkstemp", temp_path);
+ break;
+ }
+ CLOSE (ret);
+ if (0 != GNUNET_GC_write_configuration
(basecfg, temp_path))
+ {
+ fprintf (stderr,
+ "Failed to write peer configuration file
`%s'\n", temp_path);
+ break;
+ }
+ }
+ }
+
+ GNUNET_GC_free(basecfg);
}
+
+ for (i = 0; i < num_machines; i++)
+ {
+ GNUNET_free(hostlist[i]);
+ }
+
+ GNUNET_free(hostlist);
+
+ GNUNET_free(ssh_username);
+ GNUNET_free(control_host);
+ GNUNET_free(hostnames);
+ GNUNET_free(remote_config_path);
+ GNUNET_free(remote_gnunetd_path);
-
+ return GNUNET_OK;
}
int GNUNET_REMOTE_read_config(const char *config_file,struct
GNUNET_GC_Configuration **newcfg)
@@ -199,4 +288,6 @@
return GNUNET_OK;
}
+
+
/* end of remote.c */
Modified: GNUnet/src/applications/testing/remotetest.c
===================================================================
--- GNUnet/src/applications/testing/remotetest.c 2008-01-25 00:05:46 UTC
(rev 6127)
+++ GNUnet/src/applications/testing/remotetest.c 2008-01-26 22:36:59 UTC
(rev 6128)
@@ -28,6 +28,16 @@
#include "gnunet_protocols.h"
#include "gnunet_remote_lib.h"
+static char *configFile;
+static struct GNUNET_CommandLineOption gnunetRemoteOptions[] = {
+ GNUNET_COMMAND_LINE_OPTION_CFG_FILE (&configFile), /* -c */
+ GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Set up multiple gnunetd
daemons across multiple hosts.")), /* -h */
+ GNUNET_COMMAND_LINE_OPTION_HOSTNAME, /* -H */
+ GNUNET_COMMAND_LINE_OPTION_LOGGING, /* -L */
+ GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
+ GNUNET_COMMAND_LINE_OPTION_END,
+};
+
/**
* Testcase
* @return 0: ok, -1: error
@@ -35,26 +45,14 @@
int
main (int argc, const char **argv)
{
- static char *configFile = "/tmp/fake.conf";
+ configFile = "/tmp/fake.conf";
static char *path;
static char *fullpath;
int res;
struct GNUNET_GC_Configuration *cfg;
struct GNUNET_GE_Context *ectx;
struct GNUNET_GC_Configuration *hostConfig;
-
-
-static struct GNUNET_CommandLineOption gnunetRemoteOptions[] = {
- GNUNET_COMMAND_LINE_OPTION_CFG_FILE (&configFile), /* -c */
- GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Set up multiple gnunetd
daemons across multiple hosts.")), /* -h */
- GNUNET_COMMAND_LINE_OPTION_HOSTNAME, /* -H */
- GNUNET_COMMAND_LINE_OPTION_LOGGING, /* -L */
- GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
- GNUNET_COMMAND_LINE_OPTION_END,
-};
-
-
-
+
res = GNUNET_init (argc,
argv,
"testingtest",
@@ -67,7 +65,7 @@
GNUNET_GC_get_configuration_value_filename(cfg,"","CONFIG","",&path);
- fullpath = GNUNET_malloc(strlen(path) + 64);
+ fullpath = GNUNET_malloc(strlen(path) + strlen(configFile) + 1);
strcpy(fullpath,path);
strcat(fullpath,configFile);
@@ -76,14 +74,12 @@
if (GNUNET_OK != GNUNET_REMOTE_read_config (fullpath,&hostConfig))
{
printf("Problem with main host configuration file...\n");
- exit(1);
+ return(-1);
}
-
-
- //GNUNET_TESTING_remote_start_daemon(one,two,six,three,four,five);
-
+
GNUNET_REMOTE_start_daemons(&hostConfig);
-
+
+ GNUNET_free(fullpath);
return GNUNET_OK;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6128 - GNUnet/src/applications/testing,
gnunet <=