diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-03-02 12:21:01 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-03-02 12:21:01 +0000 |
commit | 46bd048fea668f87f091b21fcff9a55b0a7b9dac (patch) | |
tree | d09044a5c0eb5ba0b30050346fe6987faf01894f /src | |
parent | fcf1e8ec9f3ebdeabb012394930deb4be351a4f6 (diff) | |
download | gnunet-46bd048fea668f87f091b21fcff9a55b0a7b9dac.tar.gz gnunet-46bd048fea668f87f091b21fcff9a55b0a7b9dac.zip |
Nothing ever is right the first time.
Diffstat (limited to 'src')
-rw-r--r-- | src/testing/testing.c | 226 |
1 files changed, 120 insertions, 106 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index 99e834096..ba91e4601 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -274,109 +274,119 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
274 | d->phase = SP_COPIED; | 274 | d->phase = SP_COPIED; |
275 | /* fall-through */ | 275 | /* fall-through */ |
276 | case SP_COPIED: | 276 | case SP_COPIED: |
277 | /* Start create hostkey process */ | 277 | /* Start create hostkey process if we don't already know the peer identity!*/ |
278 | d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES); | 278 | if (GNUNET_NO == d->have_hostkey) |
279 | if (d->pipe_stdout == NULL) | ||
280 | { | 279 | { |
281 | cb = d->cb; | 280 | d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES); |
282 | d->cb = NULL; | 281 | if (d->pipe_stdout == NULL) |
283 | if (NULL != cb) | ||
284 | cb (d->cb_cls, | ||
285 | NULL, | ||
286 | d->cfg, | ||
287 | d, | ||
288 | (NULL == d->hostname) | ||
289 | ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") | ||
290 | : _("Failed to create pipe for `ssh' process.\n")); | ||
291 | return; | ||
292 | } | ||
293 | if (NULL == d->hostname) | ||
294 | { | ||
295 | #if DEBUG_TESTING | ||
296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
297 | "Starting `%s', with command `%s %s %s %s'.\n", | ||
298 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | ||
299 | "-sq"); | ||
300 | #endif | ||
301 | d->proc = | ||
302 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | ||
303 | "gnunet-peerinfo", "-c", d->cfgfile, | ||
304 | "-sq", NULL); | ||
305 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
306 | GNUNET_DISK_PIPE_END_WRITE); | ||
307 | } | ||
308 | else | ||
309 | { | ||
310 | if (d->username != NULL) | ||
311 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
312 | else | ||
313 | dst = GNUNET_strdup (d->hostname); | ||
314 | |||
315 | #if DEBUG_TESTING | ||
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
317 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | ||
318 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", | ||
319 | d->cfgfile, "-sq"); | ||
320 | #endif | ||
321 | if (d->ssh_port_str == NULL) | ||
322 | { | 282 | { |
323 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | 283 | cb = d->cb; |
324 | "ssh", | 284 | d->cb = NULL; |
325 | #if !DEBUG_TESTING | 285 | if (NULL != cb) |
326 | "-q", | 286 | cb (d->cb_cls, |
327 | #endif | 287 | NULL, |
328 | dst, | 288 | d->cfg, |
329 | "gnunet-peerinfo", | 289 | d, |
330 | "-c", d->cfgfile, "-sq", | 290 | (NULL == d->hostname) |
331 | NULL); | 291 | ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") |
292 | : _("Failed to create pipe for `ssh' process.\n")); | ||
293 | return; | ||
294 | } | ||
295 | if (NULL == d->hostname) | ||
296 | { | ||
297 | #if DEBUG_TESTING | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
299 | "Starting `%s', with command `%s %s %s %s'.\n", | ||
300 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | ||
301 | "-sq"); | ||
302 | #endif | ||
303 | d->proc = | ||
304 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | ||
305 | "gnunet-peerinfo", "-c", d->cfgfile, | ||
306 | "-sq", NULL); | ||
307 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
308 | GNUNET_DISK_PIPE_END_WRITE); | ||
332 | } | 309 | } |
333 | else | 310 | else |
334 | { | 311 | { |
335 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | 312 | if (d->username != NULL) |
336 | "ssh", "-p", d->ssh_port_str, | 313 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); |
337 | #if !DEBUG_TESTING | 314 | else |
338 | "-q", | 315 | dst = GNUNET_strdup (d->hostname); |
339 | #endif | 316 | |
340 | dst, | 317 | #if DEBUG_TESTING |
341 | "gnunet-peerinfo", | 318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
342 | "-c", d->cfgfile, "-sq", | 319 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", |
343 | NULL); | 320 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", |
321 | d->cfgfile, "-sq"); | ||
322 | #endif | ||
323 | if (d->ssh_port_str == NULL) | ||
324 | { | ||
325 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | ||
326 | "ssh", | ||
327 | #if !DEBUG_TESTING | ||
328 | "-q", | ||
329 | #endif | ||
330 | dst, | ||
331 | "gnunet-peerinfo", | ||
332 | "-c", d->cfgfile, "-sq", | ||
333 | NULL); | ||
334 | } | ||
335 | else | ||
336 | { | ||
337 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | ||
338 | "ssh", "-p", d->ssh_port_str, | ||
339 | #if !DEBUG_TESTING | ||
340 | "-q", | ||
341 | #endif | ||
342 | dst, | ||
343 | "gnunet-peerinfo", | ||
344 | "-c", d->cfgfile, "-sq", | ||
345 | NULL); | ||
346 | } | ||
347 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
348 | GNUNET_DISK_PIPE_END_WRITE); | ||
349 | GNUNET_free (dst); | ||
344 | } | 350 | } |
345 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | 351 | if (NULL == d->proc) |
346 | GNUNET_DISK_PIPE_END_WRITE); | 352 | { |
347 | GNUNET_free (dst); | 353 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
354 | _("Could not start `%s' process to create hostkey.\n"), | ||
355 | (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh"); | ||
356 | cb = d->cb; | ||
357 | d->cb = NULL; | ||
358 | if (NULL != cb) | ||
359 | cb (d->cb_cls, | ||
360 | NULL, | ||
361 | d->cfg, | ||
362 | d, | ||
363 | (NULL == d->hostname) | ||
364 | ? _("Failed to start `gnunet-peerinfo' process.\n") | ||
365 | : _("Failed to start `ssh' process.\n")); | ||
366 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
367 | return; | ||
368 | } | ||
369 | #if DEBUG_TESTING | ||
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
371 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); | ||
372 | #endif | ||
373 | d->phase = SP_HOSTKEY_CREATE; | ||
374 | d->task | ||
375 | = | ||
376 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | ||
377 | (d->max_timeout), | ||
378 | GNUNET_DISK_pipe_handle | ||
379 | (d->pipe_stdout, | ||
380 | GNUNET_DISK_PIPE_END_READ), | ||
381 | &start_fsm, d); | ||
348 | } | 382 | } |
349 | if (NULL == d->proc) | 383 | else /* Already have a hostkey! */ |
350 | { | 384 | { |
351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 385 | d->phase = SP_HOSTKEY_CREATED; |
352 | _("Could not start `%s' process to create hostkey.\n"), | 386 | /* wait some more */ |
353 | (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh"); | 387 | d->task |
354 | cb = d->cb; | 388 | = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
355 | d->cb = NULL; | ||
356 | if (NULL != cb) | ||
357 | cb (d->cb_cls, | ||
358 | NULL, | ||
359 | d->cfg, | ||
360 | d, | ||
361 | (NULL == d->hostname) | ||
362 | ? _("Failed to start `gnunet-peerinfo' process.\n") | ||
363 | : _("Failed to start `ssh' process.\n")); | ||
364 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
365 | return; | ||
366 | } | 389 | } |
367 | #if DEBUG_TESTING | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
369 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); | ||
370 | #endif | ||
371 | d->phase = SP_HOSTKEY_CREATE; | ||
372 | d->task | ||
373 | = | ||
374 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | ||
375 | (d->max_timeout), | ||
376 | GNUNET_DISK_pipe_handle | ||
377 | (d->pipe_stdout, | ||
378 | GNUNET_DISK_PIPE_END_READ), | ||
379 | &start_fsm, d); | ||
380 | break; | 390 | break; |
381 | case SP_HOSTKEY_CREATE: | 391 | case SP_HOSTKEY_CREATE: |
382 | bytes_read = | 392 | bytes_read = |
@@ -432,11 +442,13 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
432 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | 442 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
433 | GNUNET_OS_process_close (d->proc); | 443 | GNUNET_OS_process_close (d->proc); |
434 | d->proc = NULL; | 444 | d->proc = NULL; |
445 | d->have_hostkey = GNUNET_YES; | ||
435 | #if DEBUG_TESTING | 446 | #if DEBUG_TESTING |
436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); | 447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); |
437 | #endif | 448 | #endif |
438 | /* Fall through */ | 449 | /* Fall through */ |
439 | case SP_HOSTKEY_CREATED: | 450 | case SP_HOSTKEY_CREATED: |
451 | GNUNET_assert(d->have_hostkey == GNUNET_YES); | ||
440 | if (d->hostkey_callback != NULL) | 452 | if (d->hostkey_callback != NULL) |
441 | { | 453 | { |
442 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | 454 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); |
@@ -949,6 +961,18 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
949 | "PATHS", | 961 | "PATHS", |
950 | "DEFAULTCONFIG", ret->cfgfile); | 962 | "DEFAULTCONFIG", ret->cfgfile); |
951 | 963 | ||
964 | if (hostkey != NULL) /* Get the peer identity from the hostkey */ | ||
965 | { | ||
966 | private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE); | ||
967 | GNUNET_assert(private_key != NULL); | ||
968 | GNUNET_CRYPTO_rsa_key_get_public (private_key, | ||
969 | &public_key); | ||
970 | GNUNET_CRYPTO_hash(&public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey); | ||
971 | ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id)); | ||
972 | ret->have_hostkey = GNUNET_YES; | ||
973 | GNUNET_free(private_key); | ||
974 | } | ||
975 | |||
952 | /* Write hostkey to file, if we were given one */ | 976 | /* Write hostkey to file, if we were given one */ |
953 | hostkeyfile = NULL; | 977 | hostkeyfile = NULL; |
954 | if (hostkey != NULL) | 978 | if (hostkey != NULL) |
@@ -1057,6 +1081,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1057 | GNUNET_free(servicehome); | 1081 | GNUNET_free(servicehome); |
1058 | return NULL; | 1082 | return NULL; |
1059 | } | 1083 | } |
1084 | |||
1060 | ret->task | 1085 | ret->task |
1061 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 1086 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
1062 | &start_fsm, ret); | 1087 | &start_fsm, ret); |
@@ -1068,18 +1093,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1068 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1069 | "No need to copy configuration file since we are running locally.\n"); | 1094 | "No need to copy configuration file since we are running locally.\n"); |
1070 | #endif | 1095 | #endif |
1071 | if (hostkey != NULL) /* Get the peer identity from the hostkey */ | 1096 | ret->phase = SP_COPIED; |
1072 | { | ||
1073 | private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE); | ||
1074 | GNUNET_assert(private_key != NULL); | ||
1075 | GNUNET_CRYPTO_rsa_key_get_public (private_key, | ||
1076 | &public_key); | ||
1077 | GNUNET_CRYPTO_hash(&public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey); | ||
1078 | ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id)); | ||
1079 | ret->phase = SP_HOSTKEY_CREATED; | ||
1080 | } | ||
1081 | else | ||
1082 | ret->phase = SP_COPIED; | ||
1083 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | 1097 | GNUNET_SCHEDULER_add_continuation (&start_fsm, |
1084 | ret, | 1098 | ret, |
1085 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1099 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |