diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-19 07:51:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-19 07:51:18 +0000 |
commit | 6df0871923df44be6602b115088b1c292ddac3be (patch) | |
tree | b68b92d7dc1cf7a9f14afb1931adda87a88f032e /src/testing | |
parent | 35430e08f99302862e9569f0d8c4f8528f346ed2 (diff) | |
download | gnunet-6df0871923df44be6602b115088b1c292ddac3be.tar.gz gnunet-6df0871923df44be6602b115088b1c292ddac3be.zip |
-actually use testing libs hostkey functions
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/gnunet-testing.c | 138 |
1 files changed, 35 insertions, 103 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c index b7e115761..a84c512a7 100644 --- a/src/testing/gnunet-testing.c +++ b/src/testing/gnunet-testing.c | |||
@@ -29,20 +29,19 @@ | |||
29 | 29 | ||
30 | #define HOSTKEYFILESIZE 914 | 30 | #define HOSTKEYFILESIZE 914 |
31 | 31 | ||
32 | |||
32 | /** | 33 | /** |
33 | * Final status code. | 34 | * Final status code. |
34 | */ | 35 | */ |
35 | static int ret; | 36 | static int ret; |
36 | 37 | ||
37 | static unsigned int create_hostkey; | 38 | static char *create_hostkey; |
38 | |||
39 | static unsigned int create_cfg; | ||
40 | 39 | ||
41 | static int create_no; | 40 | static int create_cfg; |
42 | 41 | ||
43 | static char * create_cfg_template; | 42 | static unsigned int create_no; |
44 | 43 | ||
45 | static char * create_hostkey_file; | 44 | static char *create_cfg_template; |
46 | 45 | ||
47 | 46 | ||
48 | static int | 47 | static int |
@@ -105,7 +104,7 @@ create_unique_cfgs (const char * template, const unsigned int no) | |||
105 | } | 104 | } |
106 | GNUNET_CONFIGURATION_destroy (cfg_new); | 105 | GNUNET_CONFIGURATION_destroy (cfg_new); |
107 | GNUNET_free (cur_file); | 106 | GNUNET_free (cur_file); |
108 | if (fail == GNUNET_YES) | 107 | if (GNUNET_YES == fail) |
109 | break; | 108 | break; |
110 | } | 109 | } |
111 | GNUNET_CONFIGURATION_destroy(cfg_tmpl); | 110 | GNUNET_CONFIGURATION_destroy(cfg_tmpl); |
@@ -119,85 +118,29 @@ create_unique_cfgs (const char * template, const unsigned int no) | |||
119 | static int | 118 | static int |
120 | create_hostkeys (const unsigned int no) | 119 | create_hostkeys (const unsigned int no) |
121 | { | 120 | { |
121 | struct GNUNET_TESTING_System *system; | ||
122 | struct GNUNET_PeerIdentity id; | ||
122 | struct GNUNET_DISK_FileHandle *fd; | 123 | struct GNUNET_DISK_FileHandle *fd; |
123 | int cur = 0; | 124 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; |
124 | uint64_t fs; | 125 | |
125 | uint64_t total_hostkeys; | 126 | system = GNUNET_TESTING_system_create ("testing", NULL); |
126 | char *hostkey_data; | 127 | pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); |
127 | char *hostkey_src_file; | 128 | fd = GNUNET_DISK_file_open (create_hostkey, |
128 | char *hostkey_dest_file; | 129 | GNUNET_DISK_OPEN_READWRITE | |
129 | 130 | GNUNET_DISK_OPEN_CREATE, | |
130 | /* prepare hostkeys */ | 131 | GNUNET_DISK_PERM_USER_READ | |
131 | if (create_hostkey_file == NULL) | 132 | GNUNET_DISK_PERM_USER_WRITE); |
132 | hostkey_src_file = "../../contrib/testing_hostkeys.dat"; | 133 | GNUNET_assert (fd != NULL); |
133 | else | 134 | GNUNET_assert (HOSTKEYFILESIZE == |
134 | { | 135 | GNUNET_DISK_file_write (fd, pk, HOSTKEYFILESIZE)); |
135 | hostkey_src_file = create_hostkey_file; | 136 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); |
136 | } | 137 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
137 | 138 | "Wrote hostkey to file: `%s'\n", create_hostkey); | |
138 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkey_src_file)) | 139 | GNUNET_CRYPTO_rsa_key_free (pk); |
139 | { | ||
140 | if (create_hostkey_file == NULL) | ||
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read hostkeys file, specify hostkey file with -H!\n")); | ||
142 | else | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Specified hostkey file `%s' not found!\n"), create_hostkey_file); | ||
144 | return 1; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | /* Check hostkey file size, read entire thing into memory */ | ||
149 | fd = GNUNET_DISK_file_open (hostkey_src_file, GNUNET_DISK_OPEN_READ, | ||
150 | GNUNET_DISK_PERM_NONE); | ||
151 | if (NULL == fd) | ||
152 | { | ||
153 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkey_src_file); | ||
154 | return 1; | ||
155 | } | ||
156 | |||
157 | if (GNUNET_OK != GNUNET_DISK_file_size (hostkey_src_file, &fs, GNUNET_YES, GNUNET_YES)) | ||
158 | fs = 0; | ||
159 | |||
160 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
161 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
163 | "File size %llu seems incorrect for hostkeys...\n", fs); | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
168 | hostkey_data = GNUNET_malloc_large (fs); | ||
169 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, fs)); | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
171 | "Read %llu hostkeys from file\n", total_hostkeys); | ||
172 | } | ||
173 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
174 | } | ||
175 | |||
176 | while (cur < no) | ||
177 | { | ||
178 | GNUNET_asprintf (&hostkey_dest_file, "%04u-hostkey",cur); | ||
179 | GNUNET_assert (GNUNET_OK == | ||
180 | GNUNET_DISK_directory_create_for_file (hostkey_dest_file)); | ||
181 | fd = GNUNET_DISK_file_open (hostkey_dest_file, | ||
182 | GNUNET_DISK_OPEN_READWRITE | | ||
183 | GNUNET_DISK_OPEN_CREATE, | ||
184 | GNUNET_DISK_PERM_USER_READ | | ||
185 | GNUNET_DISK_PERM_USER_WRITE); | ||
186 | GNUNET_assert (fd != NULL); | ||
187 | GNUNET_assert (HOSTKEYFILESIZE == | ||
188 | GNUNET_DISK_file_write (fd, &hostkey_data[cur * HOSTKEYFILESIZE], HOSTKEYFILESIZE)); | ||
189 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
190 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
191 | "Wrote hostkey to file: `%s' \n", hostkey_dest_file); | ||
192 | GNUNET_free (hostkey_dest_file); | ||
193 | cur ++; | ||
194 | } | ||
195 | |||
196 | GNUNET_free (hostkey_data); | ||
197 | |||
198 | return 0; | 140 | return 0; |
199 | } | 141 | } |
200 | 142 | ||
143 | |||
201 | /** | 144 | /** |
202 | * Main function that will be run by the scheduler. | 145 | * Main function that will be run by the scheduler. |
203 | * | 146 | * |
@@ -211,11 +154,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
211 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 154 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
212 | { | 155 | { |
213 | /* main code here */ | 156 | /* main code here */ |
214 | if (create_cfg == GNUNET_YES) | 157 | if (GNUNET_YES == create_cfg) |
215 | { | 158 | { |
216 | if (create_no > 0) | 159 | if (create_no > 0) |
217 | { | 160 | { |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template); | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
162 | "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template); | ||
219 | ret = create_unique_cfgs (create_cfg_template, create_no); | 163 | ret = create_unique_cfgs (create_cfg_template, create_no); |
220 | } | 164 | } |
221 | else | 165 | else |
@@ -224,21 +168,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
224 | ret = 1; | 168 | ret = 1; |
225 | } | 169 | } |
226 | } | 170 | } |
227 | 171 | if (NULL != create_hostkey) | |
228 | if (create_hostkey == GNUNET_YES) | ||
229 | { | 172 | { |
230 | if (create_no > 0) | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no); |
231 | { | 174 | ret = create_hostkeys (create_no); |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u hostkeys \n", create_no); | ||
233 | ret = create_hostkeys (create_no); | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n"); | ||
238 | ret = 1; | ||
239 | } | ||
240 | } | 175 | } |
241 | |||
242 | GNUNET_free_non_null (create_cfg_template); | 176 | GNUNET_free_non_null (create_cfg_template); |
243 | } | 177 | } |
244 | 178 | ||
@@ -256,13 +190,11 @@ main (int argc, char *const *argv) | |||
256 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 190 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
257 | {'C', "cfg", NULL, gettext_noop ("create unique configuration files"), | 191 | {'C', "cfg", NULL, gettext_noop ("create unique configuration files"), |
258 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg}, | 192 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg}, |
259 | {'k', "key", NULL, gettext_noop ("create hostkey files from pre-computed hostkey list"), | 193 | {'k', "key", "FILENAME", gettext_noop ("extract hostkey file from pre-computed hostkey list"), |
260 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_hostkey}, | 194 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_hostkey}, |
261 | {'H', "hostkeys", NULL, gettext_noop ("host key file"), | 195 | {'n', "number", "NUMBER", gettext_noop ("number of unique configuration files to create, or number of the hostkey to extract"), |
262 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_hostkey_file}, | ||
263 | {'n', "number", NULL, gettext_noop ("number of unique configuration files or hostkeys to create"), | ||
264 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_no}, | 196 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_no}, |
265 | {'t', "template", NULL, gettext_noop ("configuration template"), | 197 | {'t', "template", "FILENAME", gettext_noop ("configuration template"), |
266 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_cfg_template}, | 198 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_cfg_template}, |
267 | GNUNET_GETOPT_OPTION_END | 199 | GNUNET_GETOPT_OPTION_END |
268 | }; | 200 | }; |