aboutsummaryrefslogtreecommitdiff
path: root/src/testing/gnunet-testing.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-12-07 17:02:52 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-12-07 17:02:52 +0000
commit120aa8991b21da50477386413911afe1f5dfcc19 (patch)
treee965c03f45c009a355d11516978345c3620b7b53 /src/testing/gnunet-testing.c
parent81f52a300c6569a292db1137690347b0986fe953 (diff)
downloadgnunet-120aa8991b21da50477386413911afe1f5dfcc19.tar.gz
gnunet-120aa8991b21da50477386413911afe1f5dfcc19.zip
added hostkey generation functionality
Diffstat (limited to 'src/testing/gnunet-testing.c')
-rw-r--r--src/testing/gnunet-testing.c133
1 files changed, 120 insertions, 13 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index e0d5d4f28..e15cacdcd 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -28,14 +28,18 @@
28#include "gnunet_program_lib.h" 28#include "gnunet_program_lib.h"
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31#define HOSTKEYFILESIZE 914
32
31/** 33/**
32 * Final status code. 34 * Final status code.
33 */ 35 */
34static int ret; 36static int ret;
35 37
36unsigned int create_cfg; 38static unsigned int create_hostkey;
39
40static unsigned int create_cfg;
37 41
38 int create_cfg_no; 42static int create_no;
39 43
40static char * create_cfg_template; 44static char * create_cfg_template;
41 45
@@ -57,8 +61,13 @@ create_unique_cfgs (const char * template, const unsigned int no)
57 61
58 int cur = 0; 62 int cur = 0;
59 char * cur_file; 63 char * cur_file;
60 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl = GNUNET_CONFIGURATION_create(); 64 char *service_home = NULL;
65 char *cur_service_home = NULL;
66
61 struct GNUNET_CONFIGURATION_Handle *cfg_new = NULL; 67 struct GNUNET_CONFIGURATION_Handle *cfg_new = NULL;
68 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl = GNUNET_CONFIGURATION_create();
69
70
62 71
63 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template)) 72 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template))
64 { 73 {
@@ -68,20 +77,38 @@ create_unique_cfgs (const char * template, const unsigned int no)
68 return 1; 77 return 1;
69 } 78 }
70 79
80 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg_tmpl, "PATHS", "SERVICEHOME", &service_home))
81 {
82 GNUNET_asprintf(&service_home, "%s", "/tmp/testing");
83 }
84 else
85 {
86 int s = strlen (service_home);
87 if (service_home[s-1] == DIR_SEPARATOR)
88 service_home[s-1] = '\0';
89 }
90
71 while (cur < no) 91 while (cur < no)
72 { 92 {
73 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating configuration no. %u \n", cur); 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur);
74 GNUNET_asprintf(&cur_file,"%04u-%s",cur, create_cfg_template); 94 GNUNET_asprintf (&cur_file,"%04u-%s",cur, create_cfg_template);
95
96
97 GNUNET_asprintf (&cur_service_home, "%s-%04u%c",service_home, cur, DIR_SEPARATOR);
98 GNUNET_CONFIGURATION_set_value_string (cfg_tmpl,"PATHS","SERVICEHOME", cur_service_home);
99 GNUNET_CONFIGURATION_set_value_string (cfg_tmpl,"PATHS","DEFAULTCONFIG", cur_file);
100 GNUNET_free (cur_service_home);
101
75 cfg_new = GNUNET_TESTING_create_cfg(cfg_tmpl, cur, &port, &upnum, NULL, &fdnum); 102 cfg_new = GNUNET_TESTING_create_cfg(cfg_tmpl, cur, &port, &upnum, NULL, &fdnum);
76 103
77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Writing configuration no. %u to file `%s' \n", cur, cur_file); 104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing configuration no. %u to file `%s' \n", cur, cur_file);
78 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file)) 105 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file))
79 { 106 {
80 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write configuration no. %u \n", cur); 107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write configuration no. %u \n", cur);
81 fail = GNUNET_YES; 108 fail = GNUNET_YES;
82 } 109 }
83 110
84 111 GNUNET_CONFIGURATION_destroy (cfg_new);
85 GNUNET_free (cur_file); 112 GNUNET_free (cur_file);
86 if (fail == GNUNET_YES) 113 if (fail == GNUNET_YES)
87 break; 114 break;
@@ -89,12 +116,85 @@ create_unique_cfgs (const char * template, const unsigned int no)
89 } 116 }
90 117
91 GNUNET_CONFIGURATION_destroy(cfg_tmpl); 118 GNUNET_CONFIGURATION_destroy(cfg_tmpl);
119 GNUNET_free (service_home);
92 if (fail == GNUNET_NO) 120 if (fail == GNUNET_NO)
93 return 0; 121 return 0;
94 else 122 else
95 return 1; 123 return 1;
96} 124}
97 125
126static int
127create_hostkeys (const unsigned int no)
128{
129 struct GNUNET_DISK_FileHandle *fd;
130 int cur = 0;
131 uint64_t fs;
132 uint64_t total_hostkeys;
133 char *hostkey_data;
134 char *hostkeyfile;
135
136 /* prepare hostkeys */
137 const char *hostkeys_file = "../../contrib/testing_hostkeys.dat";
138
139 if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
140 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read hostkeys file!\n"));
142 }
143 else
144 {
145 /* Check hostkey file size, read entire thing into memory */
146 fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ,
147 GNUNET_DISK_PERM_NONE);
148 if (NULL == fd)
149 {
150 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_file);
151 return 1;
152 }
153
154 if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES))
155 fs = 0;
156
157 if (0 != (fs % HOSTKEYFILESIZE))
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "File size %llu seems incorrect for hostkeys...\n", fs);
161 }
162 else
163 {
164 total_hostkeys = fs / HOSTKEYFILESIZE;
165 hostkey_data = GNUNET_malloc_large (fs);
166 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, fs));
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "Read %llu hostkeys from file\n", total_hostkeys);
169 }
170 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
171 }
172
173 while (cur < no)
174 {
175 GNUNET_asprintf (&hostkeyfile, "%04u-hostkey",cur);
176 GNUNET_assert (GNUNET_OK ==
177 GNUNET_DISK_directory_create_for_file (hostkeyfile));
178 fd = GNUNET_DISK_file_open (hostkeyfile,
179 GNUNET_DISK_OPEN_READWRITE |
180 GNUNET_DISK_OPEN_CREATE,
181 GNUNET_DISK_PERM_USER_READ |
182 GNUNET_DISK_PERM_USER_WRITE);
183 GNUNET_assert (fd != NULL);
184 GNUNET_assert (HOSTKEYFILESIZE ==
185 GNUNET_DISK_file_write (fd, &hostkey_data[cur * HOSTKEYFILESIZE], HOSTKEYFILESIZE));
186 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
188 "Wrote hostkey to file: `%s' \n", hostkeyfile);
189 GNUNET_free (hostkeyfile);
190 cur ++;
191 }
192
193 GNUNET_free (hostkey_data);
194
195 return 0;
196}
197
98/** 198/**
99 * Main function that will be run by the scheduler. 199 * Main function that will be run by the scheduler.
100 * 200 *
@@ -109,11 +209,16 @@ run (void *cls, char *const *args, const char *cfgfile,
109{ 209{
110 /* main code here */ 210 /* main code here */
111 if ((create_cfg == GNUNET_YES) && 211 if ((create_cfg == GNUNET_YES) &&
112 (create_cfg_no > 0) && 212 (create_no > 0) &&
113 (create_cfg_template != NULL)) 213 (create_cfg_template != NULL))
114 { 214 {
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u configuration files based on template `%s'\n", create_cfg_no, create_cfg_template); 215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template);
116 ret = create_unique_cfgs (create_cfg_template, create_cfg_no); 216 ret = create_unique_cfgs (create_cfg_template, create_no);
217 }
218 else if ((create_hostkey == GNUNET_YES) && (create_no > 0))
219 {
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u hostkeys \n", create_no);
221 ret = create_hostkeys (create_no);
117 } 222 }
118 else 223 else
119 { 224 {
@@ -134,10 +239,12 @@ int
134main (int argc, char *const *argv) 239main (int argc, char *const *argv)
135{ 240{
136 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 241 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
137 {'C', "create", NULL, gettext_noop ("create unique configuration files"), 242 {'C', "cfg", NULL, gettext_noop ("create unique configuration files"),
138 GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg}, 243 GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg},
139 {'n', "number", NULL, gettext_noop ("number of unique configuration files to create"), 244 {'k', "key", NULL, gettext_noop ("create hostkey files from pre-computed hostkey list"),
140 GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_cfg_no}, 245 GNUNET_NO, &GNUNET_GETOPT_set_one, &create_hostkey},
246 {'n', "number", NULL, gettext_noop ("number of unique configuration files or hostkeys to create"),
247 GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_no},
141 {'t', "template", NULL, gettext_noop ("configuration template"), 248 {'t', "template", NULL, gettext_noop ("configuration template"),
142 GNUNET_YES, &GNUNET_GETOPT_set_string, &create_cfg_template}, 249 GNUNET_YES, &GNUNET_GETOPT_set_string, &create_cfg_template},
143 GNUNET_GETOPT_OPTION_END 250 GNUNET_GETOPT_OPTION_END