aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-21 11:12:40 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-21 11:12:40 +0000
commit77d026cc9a58a9959b167ed60cfec50096476cd5 (patch)
tree5da2b9ef321bcd0a311c64c8d71849d89fef27a2 /src/testing
parent6e0aa5ff18fa982b574c48fc9b96baaeae7dea40 (diff)
downloadgnunet-77d026cc9a58a9959b167ed60cfec50096476cd5.tar.gz
gnunet-77d026cc9a58a9959b167ed60cfec50096476cd5.zip
cleaner handling of gnunet-peerinfo results
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.c117
1 files changed, 55 insertions, 62 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index a04c6c2de..adcc06193 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -173,7 +173,8 @@ testing_init (void *cls,
173 * @param tc unused 173 * @param tc unused
174 */ 174 */
175static void 175static void
176start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 176start_fsm (void *cls,
177 const struct GNUNET_SCHEDULER_TaskContext *tc)
177{ 178{
178 struct GNUNET_TESTING_Daemon *d = cls; 179 struct GNUNET_TESTING_Daemon *d = cls;
179 GNUNET_TESTING_NotifyDaemonRunning cb; 180 GNUNET_TESTING_NotifyDaemonRunning cb;
@@ -181,8 +182,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
181 unsigned long code; 182 unsigned long code;
182 char *dst; 183 char *dst;
183 int bytes_read; 184 int bytes_read;
184 static char hostkeybuf[105];
185 static const char temphostkey[104];
186 185
187#if DEBUG_TESTING 186#if DEBUG_TESTING
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -305,76 +304,71 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
305#endif 304#endif
306 d->phase = SP_HOSTKEY_CREATE; 305 d->phase = SP_HOSTKEY_CREATE;
307 d->task 306 d->task
308 = GNUNET_SCHEDULER_add_delayed (d->sched, 307 = GNUNET_SCHEDULER_add_read_file (d->sched,
309 GNUNET_CONSTANTS_EXEC_WAIT, 308 GNUNET_TIME_absolute_get_remaining(d->max_timeout),
310 &start_fsm, d); 309 GNUNET_DISK_pipe_handle(d->pipe_stdout,
310 GNUNET_DISK_PIPE_END_READ),
311 &start_fsm,
312 d);
311 break; 313 break;
312 case SP_HOSTKEY_CREATE: 314 case SP_HOSTKEY_CREATE:
313 315 bytes_read = GNUNET_DISK_file_read(GNUNET_DISK_pipe_handle(d->pipe_stdout,
314 bytes_read = GNUNET_DISK_file_read(GNUNET_DISK_pipe_handle(d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), &hostkeybuf, sizeof(hostkeybuf)); 316 GNUNET_DISK_PIPE_END_READ),
315 if (bytes_read == 104) /* Success, we have read in the hostkey */ 317 &d->hostkeybuf[d->hostkeybufpos],
316 { 318 sizeof(d->hostkeybuf) - d->hostkeybufpos);
317 if (hostkeybuf[103] == '\n') 319 if (bytes_read > 0)
318 hostkeybuf[103] = '\0'; 320 d->hostkeybufpos += bytes_read;
319 else 321
320 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Malformed output from gnunet-peerinfo!\n"); 322 if ( (d->hostkeybufpos < 104) &&
321 memcpy(&temphostkey, &hostkeybuf, bytes_read); 323 (bytes_read > 0) )
322 324 {
323 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (&temphostkey[0], 325 /* keep reading */
324 &d->id.hashPubKey))
325 {
326 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to peer identity!\n");
327 }
328 else
329 {
330 GNUNET_DISK_pipe_close(d->pipe_stdout);
331 d->pipe_stdout = NULL;
332 }
333 }
334
335 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
336 {
337 if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
338 {
339 cb = d->cb;
340 d->cb = NULL;
341 if (NULL != cb)
342 cb (d->cb_cls,
343 NULL,
344 d->cfg,
345 d,
346 (NULL == d->hostname)
347 ? _("`gnunet-peerinfo' does not seem to terminate.\n")
348 : _("`ssh' does not seem to terminate.\n"));
349
350 GNUNET_DISK_pipe_close(d->pipe_stdout);
351 return;
352 }
353 /* wait some more */
354 d->task 326 d->task
355 = GNUNET_SCHEDULER_add_delayed (d->sched, 327 = GNUNET_SCHEDULER_add_read_file (d->sched,
356 GNUNET_CONSTANTS_EXEC_WAIT, 328 GNUNET_TIME_absolute_get_remaining(d->max_timeout),
357 &start_fsm, d); 329 GNUNET_DISK_pipe_handle(d->pipe_stdout,
330 GNUNET_DISK_PIPE_END_READ),
331 &start_fsm,
332 d);
358 return; 333 return;
359 } 334 }
360#if DEBUG_TESTING 335 d->hostkeybuf[103] = '\0';
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 336 if ( (bytes_read < 0) ||
362 "Successfully got hostkey!\n"); 337 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
363#endif 338 &d->id.hashPubKey)) )
364 if (d->pipe_stdout != NULL) 339 {
365 { 340 /* error */
341 if (bytes_read < 0)
342 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
343 _("Error reading from gnunet-peerinfo: %s\n"),
344 STRERROR (errno));
345 else
346 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
347 _("Malformed output from gnunet-peerinfo!\n"));
366 cb = d->cb; 348 cb = d->cb;
367 d->cb = NULL; 349 d->cb = NULL;
350 GNUNET_DISK_pipe_close(d->pipe_stdout);
351 d->pipe_stdout = NULL;
352 (void) PLIBC_KILL (d->pid, SIGKILL);
353 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->pid));
354 d->pid = 0;
368 if (NULL != cb) 355 if (NULL != cb)
369 cb (d->cb_cls, 356 cb (d->cb_cls,
370 NULL, 357 NULL,
371 d->cfg, 358 d->cfg,
372 d, 359 d,
373 _("`Failed to get hostkey!\n")); 360 _("`Failed to get hostkey!\n"));
374 GNUNET_DISK_pipe_close(d->pipe_stdout); 361 return;
375 return; 362 }
376 } 363 GNUNET_DISK_pipe_close(d->pipe_stdout);
377 364 d->pipe_stdout = NULL;
365 (void) PLIBC_KILL (d->pid, SIGKILL);
366 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->pid));
367 d->pid = 0;
368#if DEBUG_TESTING
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 "Successfully got hostkey!\n");
371#endif
378 if (d->hostkey_callback != NULL) 372 if (d->hostkey_callback != NULL)
379 { 373 {
380 d->hostkey_callback(d->hostkey_cls, &d->id, d, NULL); 374 d->hostkey_callback(d->hostkey_cls, &d->id, d, NULL);
@@ -384,7 +378,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
384 { 378 {
385 d->phase = SP_TOPOLOGY_SETUP; 379 d->phase = SP_TOPOLOGY_SETUP;
386 } 380 }
387
388 /* Fall through */ 381 /* Fall through */
389 case SP_HOSTKEY_CREATED: 382 case SP_HOSTKEY_CREATED:
390 /* wait for topology finished */ 383 /* wait for topology finished */