diff options
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 2691 |
1 files changed, 1346 insertions, 1345 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index 975f34496..c21166775 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -67,13 +67,13 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} }; | |||
67 | 67 | ||
68 | #if EMPTY_HACK | 68 | #if EMPTY_HACK |
69 | static int | 69 | static int |
70 | test_address (void *cls, | 70 | test_address (void *cls, |
71 | const char *tname, | 71 | const char *tname, |
72 | struct GNUNET_TIME_Absolute expiration, | 72 | struct GNUNET_TIME_Absolute expiration, |
73 | const void *addr, | 73 | const void *addr, uint16_t addrlen) |
74 | uint16_t addrlen) | ||
75 | { | 74 | { |
76 | int *empty = cls; | 75 | int *empty = cls; |
76 | |||
77 | *empty = GNUNET_NO; | 77 | *empty = GNUNET_NO; |
78 | return GNUNET_OK; | 78 | return GNUNET_OK; |
79 | } | 79 | } |
@@ -87,11 +87,11 @@ test_address (void *cls, | |||
87 | * @param message HELLO message of peer | 87 | * @param message HELLO message of peer |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | process_hello (void *cls, | 90 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
91 | const struct GNUNET_MessageHeader *message) | ||
92 | { | 91 | { |
93 | struct GNUNET_TESTING_Daemon *daemon = cls; | 92 | struct GNUNET_TESTING_Daemon *daemon = cls; |
94 | int msize; | 93 | int msize; |
94 | |||
95 | #if WAIT_FOR_HELLO | 95 | #if WAIT_FOR_HELLO |
96 | GNUNET_TESTING_NotifyDaemonRunning cb; | 96 | GNUNET_TESTING_NotifyDaemonRunning cb; |
97 | #endif | 97 | #endif |
@@ -100,50 +100,48 @@ process_hello (void *cls, | |||
100 | 100 | ||
101 | empty = GNUNET_YES; | 101 | empty = GNUNET_YES; |
102 | GNUNET_assert (message != NULL); | 102 | GNUNET_assert (message != NULL); |
103 | GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message*) message, | 103 | GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) message, |
104 | GNUNET_NO, | 104 | GNUNET_NO, &test_address, &empty); |
105 | &test_address, | ||
106 | &empty); | ||
107 | if (GNUNET_YES == empty) | 105 | if (GNUNET_YES == empty) |
108 | { | 106 | { |
109 | #if DEBUG_TESTING | 107 | #if DEBUG_TESTING |
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping empty HELLO address\n"); |
111 | "Skipping empty HELLO address\n"); | ||
112 | #endif | 109 | #endif |
113 | return; | 110 | return; |
114 | } | 111 | } |
115 | #endif | 112 | #endif |
116 | if (daemon == NULL) | 113 | if (daemon == NULL) |
117 | return; | 114 | return; |
118 | 115 | ||
119 | GNUNET_assert (daemon->phase == SP_GET_HELLO || daemon->phase == SP_START_DONE); | 116 | GNUNET_assert (daemon->phase == SP_GET_HELLO || |
117 | daemon->phase == SP_START_DONE); | ||
120 | #if WAIT_FOR_HELLO | 118 | #if WAIT_FOR_HELLO |
121 | cb = daemon->cb; | 119 | cb = daemon->cb; |
122 | #endif | 120 | #endif |
123 | daemon->cb = NULL; | 121 | daemon->cb = NULL; |
124 | if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */ | 122 | if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */ |
125 | GNUNET_SCHEDULER_cancel(daemon->task); | 123 | GNUNET_SCHEDULER_cancel (daemon->task); |
126 | 124 | ||
127 | if (daemon->server != NULL) | 125 | if (daemon->server != NULL) |
128 | { | 126 | { |
129 | #if DEBUG_TESTING | 127 | #if DEBUG_TESTING |
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
131 | "Received `%s' from transport service of `%4s', disconnecting core!\n", | 129 | "Received `%s' from transport service of `%4s', disconnecting core!\n", |
132 | "HELLO", GNUNET_i2s (&daemon->id)); | 130 | "HELLO", GNUNET_i2s (&daemon->id)); |
133 | #endif | 131 | #endif |
134 | GNUNET_CORE_disconnect (daemon->server); | 132 | GNUNET_CORE_disconnect (daemon->server); |
135 | daemon->server = NULL; | 133 | daemon->server = NULL; |
136 | } | 134 | } |
137 | 135 | ||
138 | msize = ntohs (message->size); | 136 | msize = ntohs (message->size); |
139 | if (msize < 1) | 137 | if (msize < 1) |
140 | { | 138 | { |
141 | return; | 139 | return; |
142 | } | 140 | } |
143 | if (daemon->th != NULL) | 141 | if (daemon->th != NULL) |
144 | { | 142 | { |
145 | GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon); | 143 | GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon); |
146 | } | 144 | } |
147 | #if DEBUG_TESTING | 145 | #if DEBUG_TESTING |
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
149 | "Received `%s' from transport service of `%4s'\n", | 147 | "Received `%s' from transport service of `%4s'\n", |
@@ -155,18 +153,15 @@ process_hello (void *cls, | |||
155 | memcpy (daemon->hello, message, msize); | 153 | memcpy (daemon->hello, message, msize); |
156 | 154 | ||
157 | if (daemon->th != NULL) | 155 | if (daemon->th != NULL) |
158 | { | 156 | { |
159 | GNUNET_TRANSPORT_disconnect (daemon->th); | 157 | GNUNET_TRANSPORT_disconnect (daemon->th); |
160 | daemon->th = NULL; | 158 | daemon->th = NULL; |
161 | } | 159 | } |
162 | daemon->phase = SP_START_DONE; | 160 | daemon->phase = SP_START_DONE; |
163 | 161 | ||
164 | #if WAIT_FOR_HELLO | 162 | #if WAIT_FOR_HELLO |
165 | if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */ | 163 | if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */ |
166 | cb (daemon->cb_cls, | 164 | cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL); |
167 | &daemon->id, | ||
168 | daemon->cfg, | ||
169 | daemon, NULL); | ||
170 | #endif | 165 | #endif |
171 | } | 166 | } |
172 | 167 | ||
@@ -198,36 +193,36 @@ testing_init (void *cls, | |||
198 | d->phase = SP_GET_HELLO; | 193 | d->phase = SP_GET_HELLO; |
199 | 194 | ||
200 | if (server == NULL) | 195 | if (server == NULL) |
201 | { | 196 | { |
202 | d->server = NULL; | 197 | d->server = NULL; |
203 | if (GNUNET_YES == d->dead) | 198 | if (GNUNET_YES == d->dead) |
204 | GNUNET_TESTING_daemon_stop (d, | 199 | GNUNET_TESTING_daemon_stop (d, |
205 | GNUNET_TIME_absolute_get_remaining | 200 | GNUNET_TIME_absolute_get_remaining |
206 | (d->max_timeout), d->dead_cb, | 201 | (d->max_timeout), d->dead_cb, |
207 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 202 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
208 | else if (NULL != d->cb) | 203 | else if (NULL != d->cb) |
209 | d->cb (d->cb_cls, NULL, d->cfg, d, | 204 | d->cb (d->cb_cls, NULL, d->cfg, d, |
210 | _("Failed to connect to core service\n")); | 205 | _("Failed to connect to core service\n")); |
211 | return; | 206 | return; |
212 | } | 207 | } |
213 | #if DEBUG_TESTING | 208 | #if DEBUG_TESTING |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); | 210 | "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); |
216 | #endif | 211 | #endif |
217 | d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */ | 212 | d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */ |
218 | if (d->shortname == NULL) | 213 | if (d->shortname == NULL) |
219 | d->shortname = strdup (GNUNET_i2s (my_identity)); | 214 | d->shortname = strdup (GNUNET_i2s (my_identity)); |
220 | d->server = server; | 215 | d->server = server; |
221 | d->running = GNUNET_YES; | 216 | d->running = GNUNET_YES; |
222 | 217 | ||
223 | if (GNUNET_NO == d->running) | 218 | if (GNUNET_NO == d->running) |
224 | { | 219 | { |
225 | #if DEBUG_TESTING | 220 | #if DEBUG_TESTING |
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
227 | "Peer is dead (d->running == GNUNET_NO)\n"); | 222 | "Peer is dead (d->running == GNUNET_NO)\n"); |
228 | #endif | 223 | #endif |
229 | return; | 224 | return; |
230 | } | 225 | } |
231 | #if DEBUG_TESTING | 226 | #if DEBUG_TESTING |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
233 | "Successfully started peer `%4s', connecting to transport service.\n", | 228 | "Successfully started peer `%4s', connecting to transport service.\n", |
@@ -236,17 +231,17 @@ testing_init (void *cls, | |||
236 | 231 | ||
237 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | 232 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); |
238 | if (d->th == NULL) | 233 | if (d->th == NULL) |
239 | { | 234 | { |
240 | if (GNUNET_YES == d->dead) | 235 | if (GNUNET_YES == d->dead) |
241 | GNUNET_TESTING_daemon_stop (d, | 236 | GNUNET_TESTING_daemon_stop (d, |
242 | GNUNET_TIME_absolute_get_remaining | 237 | GNUNET_TIME_absolute_get_remaining |
243 | (d->max_timeout), d->dead_cb, | 238 | (d->max_timeout), d->dead_cb, |
244 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 239 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
245 | else if (NULL != d->cb) | 240 | else if (NULL != d->cb) |
246 | d->cb (d->cb_cls, &d->id, d->cfg, d, | 241 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
247 | _("Failed to connect to transport service!\n")); | 242 | _("Failed to connect to transport service!\n")); |
248 | return; | 243 | return; |
249 | } | 244 | } |
250 | #if DEBUG_TESTING | 245 | #if DEBUG_TESTING |
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
252 | "Connected to transport service `%s', getting HELLO\n", | 247 | "Connected to transport service `%s', getting HELLO\n", |
@@ -256,10 +251,10 @@ testing_init (void *cls, | |||
256 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | 251 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); |
257 | /* wait some more */ | 252 | /* wait some more */ |
258 | if (d->task != GNUNET_SCHEDULER_NO_TASK) | 253 | if (d->task != GNUNET_SCHEDULER_NO_TASK) |
259 | GNUNET_SCHEDULER_cancel(d->task); | 254 | GNUNET_SCHEDULER_cancel (d->task); |
260 | d->task | 255 | d->task |
261 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 256 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
262 | &start_fsm, d); | 257 | &start_fsm, d); |
263 | } | 258 | } |
264 | #endif | 259 | #endif |
265 | 260 | ||
@@ -273,8 +268,7 @@ testing_init (void *cls, | |||
273 | * @param tc task scheduler context | 268 | * @param tc task scheduler context |
274 | */ | 269 | */ |
275 | static void | 270 | static void |
276 | notify_daemon_started (void *cls, | 271 | notify_daemon_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
277 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
278 | { | 272 | { |
279 | struct GNUNET_TESTING_Daemon *d = cls; | 273 | struct GNUNET_TESTING_Daemon *d = cls; |
280 | GNUNET_TESTING_NotifyDaemonRunning cb; | 274 | GNUNET_TESTING_NotifyDaemonRunning cb; |
@@ -303,711 +297,697 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
303 | int bytes_read; | 297 | int bytes_read; |
304 | 298 | ||
305 | #if DEBUG_TESTING | 299 | #if DEBUG_TESTING |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer FSM is in phase %u.\n", d->phase); |
307 | "Peer FSM is in phase %u.\n", d->phase); | ||
308 | #endif | 301 | #endif |
309 | 302 | ||
310 | d->task = GNUNET_SCHEDULER_NO_TASK; | 303 | d->task = GNUNET_SCHEDULER_NO_TASK; |
311 | switch (d->phase) | 304 | switch (d->phase) |
305 | { | ||
306 | case SP_COPYING: | ||
307 | /* confirm copying complete */ | ||
308 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
309 | { | ||
310 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
311 | { | ||
312 | cb = d->cb; | ||
313 | d->cb = NULL; | ||
314 | if (NULL != cb) | ||
315 | cb (d->cb_cls, | ||
316 | NULL, | ||
317 | d->cfg, d, | ||
318 | _ | ||
319 | ("`scp' does not seem to terminate (timeout copying config).\n")); | ||
320 | return; | ||
321 | } | ||
322 | /* wait some more */ | ||
323 | d->task | ||
324 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
325 | &start_fsm, d); | ||
326 | return; | ||
327 | } | ||
328 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
312 | { | 329 | { |
313 | case SP_COPYING: | 330 | cb = d->cb; |
314 | /* confirm copying complete */ | 331 | d->cb = NULL; |
315 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 332 | if (NULL != cb) |
333 | cb (d->cb_cls, NULL, d->cfg, d, _("`scp' did not complete cleanly.\n")); | ||
334 | return; | ||
335 | } | ||
336 | GNUNET_OS_process_close (d->proc); | ||
337 | #if DEBUG_TESTING | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
339 | "Successfully copied configuration file.\n"); | ||
340 | #endif | ||
341 | d->phase = SP_COPIED; | ||
342 | /* fall-through */ | ||
343 | case SP_COPIED: | ||
344 | /* Start create hostkey process if we don't already know the peer identity! */ | ||
345 | if (GNUNET_NO == d->have_hostkey) | ||
346 | { | ||
347 | d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES); | ||
348 | if (d->pipe_stdout == NULL) | ||
349 | { | ||
350 | cb = d->cb; | ||
351 | d->cb = NULL; | ||
352 | if (NULL != cb) | ||
353 | cb (d->cb_cls, | ||
354 | NULL, | ||
355 | d->cfg, | ||
356 | d, | ||
357 | (NULL == d->hostname) | ||
358 | ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") | ||
359 | : _("Failed to create pipe for `ssh' process.\n")); | ||
360 | return; | ||
361 | } | ||
362 | if (NULL == d->hostname) | ||
363 | { | ||
364 | #if DEBUG_TESTING | ||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
366 | "Starting `%s', with command `%s %s %s %s'.\n", | ||
367 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | ||
368 | "-sq"); | ||
369 | #endif | ||
370 | d->proc = | ||
371 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | ||
372 | "gnunet-peerinfo", "-c", d->cfgfile, | ||
373 | "-sq", NULL); | ||
374 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | if (d->username != NULL) | ||
379 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
380 | else | ||
381 | dst = GNUNET_strdup (d->hostname); | ||
382 | |||
383 | #if DEBUG_TESTING | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | ||
386 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", | ||
387 | d->cfgfile, "-sq"); | ||
388 | #endif | ||
389 | if (d->ssh_port_str == NULL) | ||
316 | { | 390 | { |
317 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 391 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", |
318 | 0) | 392 | #if !DEBUG_TESTING |
319 | { | 393 | "-q", |
320 | cb = d->cb; | 394 | #endif |
321 | d->cb = NULL; | 395 | dst, |
322 | if (NULL != cb) | 396 | "gnunet-peerinfo", |
323 | cb (d->cb_cls, | 397 | "-c", d->cfgfile, "-sq", NULL); |
324 | NULL, | ||
325 | d->cfg, d, | ||
326 | _ | ||
327 | ("`scp' does not seem to terminate (timeout copying config).\n")); | ||
328 | return; | ||
329 | } | ||
330 | /* wait some more */ | ||
331 | d->task | ||
332 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
333 | &start_fsm, d); | ||
334 | return; | ||
335 | } | 398 | } |
336 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | 399 | else |
337 | { | 400 | { |
338 | cb = d->cb; | 401 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", |
339 | d->cb = NULL; | 402 | "ssh", "-p", d->ssh_port_str, |
340 | if (NULL != cb) | 403 | #if !DEBUG_TESTING |
341 | cb (d->cb_cls, | 404 | "-q", |
342 | NULL, d->cfg, d, _("`scp' did not complete cleanly.\n")); | 405 | #endif |
343 | return; | 406 | dst, |
407 | "gnunet-peerinfo", | ||
408 | "-c", d->cfgfile, "-sq", NULL); | ||
344 | } | 409 | } |
345 | GNUNET_OS_process_close(d->proc); | 410 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); |
411 | GNUNET_free (dst); | ||
412 | } | ||
413 | if (NULL == d->proc) | ||
414 | { | ||
415 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
416 | _("Could not start `%s' process to create hostkey.\n"), | ||
417 | (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh"); | ||
418 | cb = d->cb; | ||
419 | d->cb = NULL; | ||
420 | if (NULL != cb) | ||
421 | cb (d->cb_cls, | ||
422 | NULL, | ||
423 | d->cfg, | ||
424 | d, | ||
425 | (NULL == d->hostname) | ||
426 | ? _("Failed to start `gnunet-peerinfo' process.\n") | ||
427 | : _("Failed to start `ssh' process.\n")); | ||
428 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
429 | return; | ||
430 | } | ||
346 | #if DEBUG_TESTING | 431 | #if DEBUG_TESTING |
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
348 | "Successfully copied configuration file.\n"); | 433 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); |
349 | #endif | 434 | #endif |
350 | d->phase = SP_COPIED; | 435 | d->phase = SP_HOSTKEY_CREATE; |
351 | /* fall-through */ | 436 | d->task |
352 | case SP_COPIED: | 437 | = |
353 | /* Start create hostkey process if we don't already know the peer identity!*/ | 438 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
354 | if (GNUNET_NO == d->have_hostkey) | 439 | (d->max_timeout), |
355 | { | 440 | GNUNET_DISK_pipe_handle |
356 | d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES); | 441 | (d->pipe_stdout, |
357 | if (d->pipe_stdout == NULL) | 442 | GNUNET_DISK_PIPE_END_READ), |
358 | { | 443 | &start_fsm, d); |
359 | cb = d->cb; | 444 | } |
360 | d->cb = NULL; | 445 | else /* Already have a hostkey! */ |
361 | if (NULL != cb) | 446 | { |
362 | cb (d->cb_cls, | 447 | if (d->hostkey_callback != NULL) |
363 | NULL, | 448 | { |
364 | d->cfg, | 449 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); |
365 | d, | 450 | d->hostkey_callback = NULL; |
366 | (NULL == d->hostname) | 451 | d->phase = SP_HOSTKEY_CREATED; |
367 | ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") | 452 | } |
368 | : _("Failed to create pipe for `ssh' process.\n")); | 453 | else |
369 | return; | 454 | d->phase = SP_TOPOLOGY_SETUP; |
370 | } | 455 | |
371 | if (NULL == d->hostname) | 456 | /* wait some more */ |
372 | { | 457 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
373 | #if DEBUG_TESTING | 458 | } |
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 459 | break; |
375 | "Starting `%s', with command `%s %s %s %s'.\n", | 460 | case SP_HOSTKEY_CREATE: |
376 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | 461 | bytes_read = |
377 | "-sq"); | ||
378 | #endif | ||
379 | d->proc = | ||
380 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | ||
381 | "gnunet-peerinfo", "-c", d->cfgfile, | ||
382 | "-sq", NULL); | ||
383 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
384 | GNUNET_DISK_PIPE_END_WRITE); | ||
385 | } | ||
386 | else | ||
387 | { | ||
388 | if (d->username != NULL) | ||
389 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
390 | else | ||
391 | dst = GNUNET_strdup (d->hostname); | ||
392 | |||
393 | #if DEBUG_TESTING | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | ||
396 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", | ||
397 | d->cfgfile, "-sq"); | ||
398 | #endif | ||
399 | if (d->ssh_port_str == NULL) | ||
400 | { | ||
401 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | ||
402 | "ssh", | ||
403 | #if !DEBUG_TESTING | ||
404 | "-q", | ||
405 | #endif | ||
406 | dst, | ||
407 | "gnunet-peerinfo", | ||
408 | "-c", d->cfgfile, "-sq", | ||
409 | NULL); | ||
410 | } | ||
411 | else | ||
412 | { | ||
413 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | ||
414 | "ssh", "-p", d->ssh_port_str, | ||
415 | #if !DEBUG_TESTING | ||
416 | "-q", | ||
417 | #endif | ||
418 | dst, | ||
419 | "gnunet-peerinfo", | ||
420 | "-c", d->cfgfile, "-sq", | ||
421 | NULL); | ||
422 | } | ||
423 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, | ||
424 | GNUNET_DISK_PIPE_END_WRITE); | ||
425 | GNUNET_free (dst); | ||
426 | } | ||
427 | if (NULL == d->proc) | ||
428 | { | ||
429 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
430 | _("Could not start `%s' process to create hostkey.\n"), | ||
431 | (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh"); | ||
432 | cb = d->cb; | ||
433 | d->cb = NULL; | ||
434 | if (NULL != cb) | ||
435 | cb (d->cb_cls, | ||
436 | NULL, | ||
437 | d->cfg, | ||
438 | d, | ||
439 | (NULL == d->hostname) | ||
440 | ? _("Failed to start `gnunet-peerinfo' process.\n") | ||
441 | : _("Failed to start `ssh' process.\n")); | ||
442 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
443 | return; | ||
444 | } | ||
445 | #if DEBUG_TESTING | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
447 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); | ||
448 | #endif | ||
449 | d->phase = SP_HOSTKEY_CREATE; | ||
450 | d->task | ||
451 | = | ||
452 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | ||
453 | (d->max_timeout), | ||
454 | GNUNET_DISK_pipe_handle | ||
455 | (d->pipe_stdout, | ||
456 | GNUNET_DISK_PIPE_END_READ), | ||
457 | &start_fsm, d); | ||
458 | } | ||
459 | else /* Already have a hostkey! */ | ||
460 | { | ||
461 | if (d->hostkey_callback != NULL) | ||
462 | { | ||
463 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | ||
464 | d->hostkey_callback = NULL; | ||
465 | d->phase = SP_HOSTKEY_CREATED; | ||
466 | } | ||
467 | else | ||
468 | d->phase = SP_TOPOLOGY_SETUP; | ||
469 | |||
470 | /* wait some more */ | ||
471 | d->task | ||
472 | = GNUNET_SCHEDULER_add_now (&start_fsm, d); | ||
473 | } | ||
474 | break; | ||
475 | case SP_HOSTKEY_CREATE: | ||
476 | bytes_read = | ||
477 | GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle | 462 | GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle |
478 | (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), | 463 | (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), |
479 | &d->hostkeybuf[d->hostkeybufpos], | 464 | &d->hostkeybuf[d->hostkeybufpos], |
480 | sizeof (d->hostkeybuf) - d->hostkeybufpos); | 465 | sizeof (d->hostkeybuf) - d->hostkeybufpos); |
481 | if (bytes_read > 0) | 466 | if (bytes_read > 0) |
482 | d->hostkeybufpos += bytes_read; | 467 | d->hostkeybufpos += bytes_read; |
483 | 468 | ||
484 | if ((d->hostkeybufpos < 104) && (bytes_read > 0)) | 469 | if ((d->hostkeybufpos < 104) && (bytes_read > 0)) |
485 | { | 470 | { |
486 | /* keep reading */ | 471 | /* keep reading */ |
487 | d->task | 472 | d->task |
488 | = | 473 | = |
489 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | 474 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
490 | (d->max_timeout), | 475 | (d->max_timeout), |
491 | GNUNET_DISK_pipe_handle | 476 | GNUNET_DISK_pipe_handle |
492 | (d->pipe_stdout, | 477 | (d->pipe_stdout, |
493 | GNUNET_DISK_PIPE_END_READ), | 478 | GNUNET_DISK_PIPE_END_READ), |
494 | &start_fsm, d); | 479 | &start_fsm, d); |
495 | return; | 480 | return; |
496 | } | 481 | } |
497 | d->hostkeybuf[103] = '\0'; | 482 | d->hostkeybuf[103] = '\0'; |
498 | 483 | ||
499 | if ((bytes_read < 0) || | 484 | if ((bytes_read < 0) || |
500 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, | 485 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, |
501 | &d->id.hashPubKey))) | 486 | &d->id.hashPubKey))) |
502 | { | 487 | { |
503 | /* error */ | 488 | /* error */ |
504 | if (bytes_read < 0) | 489 | if (bytes_read < 0) |
505 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 490 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
506 | _("Error reading from gnunet-peerinfo: %s\n"), | 491 | _("Error reading from gnunet-peerinfo: %s\n"), |
507 | STRERROR (errno)); | 492 | STRERROR (errno)); |
508 | else | 493 | else |
509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 494 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
510 | _("Malformed output from gnunet-peerinfo!\n")); | 495 | _("Malformed output from gnunet-peerinfo!\n")); |
511 | cb = d->cb; | 496 | cb = d->cb; |
512 | d->cb = NULL; | 497 | d->cb = NULL; |
513 | GNUNET_DISK_pipe_close (d->pipe_stdout); | ||
514 | d->pipe_stdout = NULL; | ||
515 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); | ||
516 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | ||
517 | GNUNET_OS_process_close (d->proc); | ||
518 | d->proc = NULL; | ||
519 | if (NULL != cb) | ||
520 | cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n")); | ||
521 | return; | ||
522 | } | ||
523 | d->shortname = GNUNET_strdup(GNUNET_i2s(&d->id)); | ||
524 | GNUNET_DISK_pipe_close (d->pipe_stdout); | 498 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
525 | d->pipe_stdout = NULL; | 499 | d->pipe_stdout = NULL; |
526 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); | 500 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); |
527 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | 501 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
528 | GNUNET_OS_process_close (d->proc); | 502 | GNUNET_OS_process_close (d->proc); |
529 | d->proc = NULL; | 503 | d->proc = NULL; |
530 | d->have_hostkey = GNUNET_YES; | 504 | if (NULL != cb) |
531 | if (d->hostkey_callback != NULL) | 505 | cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n")); |
532 | { | 506 | return; |
533 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | 507 | } |
534 | d->hostkey_callback = NULL; | 508 | d->shortname = GNUNET_strdup (GNUNET_i2s (&d->id)); |
535 | d->phase = SP_HOSTKEY_CREATED; | 509 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
536 | } | 510 | d->pipe_stdout = NULL; |
537 | else | 511 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); |
538 | { | 512 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
539 | d->phase = SP_TOPOLOGY_SETUP; | 513 | GNUNET_OS_process_close (d->proc); |
540 | } | 514 | d->proc = NULL; |
515 | d->have_hostkey = GNUNET_YES; | ||
516 | if (d->hostkey_callback != NULL) | ||
517 | { | ||
518 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); | ||
519 | d->hostkey_callback = NULL; | ||
520 | d->phase = SP_HOSTKEY_CREATED; | ||
521 | } | ||
522 | else | ||
523 | { | ||
524 | d->phase = SP_TOPOLOGY_SETUP; | ||
525 | } | ||
541 | #if DEBUG_TESTING | 526 | #if DEBUG_TESTING |
542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); | 527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); |
543 | #endif | 528 | #endif |
544 | /* Fall through */ | 529 | /* Fall through */ |
545 | case SP_HOSTKEY_CREATED: | 530 | case SP_HOSTKEY_CREATED: |
546 | /* wait for topology finished */ | 531 | /* wait for topology finished */ |
547 | if ((GNUNET_YES == d->dead) | 532 | if ((GNUNET_YES == d->dead) |
548 | || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 533 | || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)) |
549 | 0)) | 534 | { |
550 | { | 535 | cb = d->cb; |
551 | cb = d->cb; | 536 | d->cb = NULL; |
552 | d->cb = NULL; | 537 | if (NULL != cb) |
553 | if (NULL != cb) | 538 | cb (d->cb_cls, |
554 | cb (d->cb_cls, | 539 | NULL, d->cfg, d, _("`Failed while waiting for topology setup!\n")); |
555 | NULL, | 540 | return; |
556 | d->cfg, d, _("`Failed while waiting for topology setup!\n")); | 541 | } |
557 | return; | ||
558 | } | ||
559 | 542 | ||
560 | d->task | 543 | d->task |
561 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 544 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
562 | &start_fsm, d); | 545 | &start_fsm, d); |
563 | break; | 546 | break; |
564 | case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */ | 547 | case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */ |
565 | /* start GNUnet on remote host */ | 548 | /* start GNUnet on remote host */ |
566 | if (NULL == d->hostname) | 549 | if (NULL == d->hostname) |
567 | { | 550 | { |
568 | #if DEBUG_TESTING | 551 | #if DEBUG_TESTING |
569 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 552 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
570 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | 553 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", |
571 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, | 554 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, |
572 | "-L", "DEBUG", "-s"); | 555 | "-L", "DEBUG", "-s"); |
573 | #endif | 556 | #endif |
574 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 557 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", |
575 | "gnunet-arm", "-c", d->cfgfile, | 558 | "gnunet-arm", "-c", d->cfgfile, |
576 | #if DEBUG_TESTING | 559 | #if DEBUG_TESTING |
577 | "-L", "DEBUG", | 560 | "-L", "DEBUG", |
578 | #endif | 561 | #endif |
579 | "-s", "-q", "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), NULL); | 562 | "-s", "-q", "-T", |
580 | } | 563 | GNUNET_TIME_relative_to_string |
564 | (GNUNET_TIME_absolute_get_remaining | ||
565 | (d->max_timeout)), NULL); | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | if (d->username != NULL) | ||
570 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
581 | else | 571 | else |
582 | { | 572 | dst = GNUNET_strdup (d->hostname); |
583 | if (d->username != NULL) | ||
584 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); | ||
585 | else | ||
586 | dst = GNUNET_strdup (d->hostname); | ||
587 | 573 | ||
588 | #if DEBUG_TESTING | 574 | #if DEBUG_TESTING |
589 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
590 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", | 576 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", |
591 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", | 577 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", |
592 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); | 578 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); |
593 | #endif | 579 | #endif |
594 | if (d->ssh_port_str == NULL) | 580 | if (d->ssh_port_str == NULL) |
595 | { | 581 | { |
596 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 582 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
597 | #if !DEBUG_TESTING | 583 | #if !DEBUG_TESTING |
598 | "-q", | 584 | "-q", |
599 | #endif | 585 | #endif |
600 | dst, "gnunet-arm", | 586 | dst, "gnunet-arm", |
601 | #if DEBUG_TESTING | 587 | #if DEBUG_TESTING |
602 | "-L", "DEBUG", | 588 | "-L", "DEBUG", |
603 | #endif | 589 | #endif |
604 | "-c", d->cfgfile, "-s", "-q", | 590 | "-c", d->cfgfile, "-s", "-q", |
605 | "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), | 591 | "-T", |
606 | NULL); | 592 | GNUNET_TIME_relative_to_string |
607 | } | 593 | (GNUNET_TIME_absolute_get_remaining |
608 | else | 594 | (d->max_timeout)), NULL); |
609 | { | 595 | } |
596 | else | ||
597 | { | ||
610 | 598 | ||
611 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | 599 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", |
612 | "ssh", "-p", d->ssh_port_str, | 600 | "ssh", "-p", d->ssh_port_str, |
613 | #if !DEBUG_TESTING | 601 | #if !DEBUG_TESTING |
614 | "-q", | 602 | "-q", |
615 | #endif | 603 | #endif |
616 | dst, "gnunet-arm", | 604 | dst, "gnunet-arm", |
617 | #if DEBUG_TESTING | 605 | #if DEBUG_TESTING |
618 | "-L", "DEBUG", | 606 | "-L", "DEBUG", |
619 | #endif | 607 | #endif |
620 | "-c", d->cfgfile, "-s", "-q", | 608 | "-c", d->cfgfile, "-s", "-q", |
621 | "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), | 609 | "-T", |
622 | NULL); | 610 | GNUNET_TIME_relative_to_string |
623 | } | 611 | (GNUNET_TIME_absolute_get_remaining |
624 | GNUNET_free (dst); | 612 | (d->max_timeout)), NULL); |
625 | } | 613 | } |
626 | if (NULL == d->proc) | 614 | GNUNET_free (dst); |
627 | { | 615 | } |
628 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 616 | if (NULL == d->proc) |
629 | _("Could not start `%s' process to start GNUnet.\n"), | 617 | { |
630 | (NULL == d->hostname) ? "gnunet-arm" : "ssh"); | 618 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
631 | cb = d->cb; | 619 | _("Could not start `%s' process to start GNUnet.\n"), |
632 | d->cb = NULL; | 620 | (NULL == d->hostname) ? "gnunet-arm" : "ssh"); |
633 | if (NULL != cb) | 621 | cb = d->cb; |
634 | cb (d->cb_cls, | 622 | d->cb = NULL; |
635 | NULL, | 623 | if (NULL != cb) |
636 | d->cfg, | 624 | cb (d->cb_cls, |
637 | d, | 625 | NULL, |
638 | (NULL == d->hostname) | 626 | d->cfg, |
639 | ? _("Failed to start `gnunet-arm' process.\n") | 627 | d, |
640 | : _("Failed to start `ssh' process.\n")); | 628 | (NULL == d->hostname) |
641 | return; | 629 | ? _("Failed to start `gnunet-arm' process.\n") |
642 | } | 630 | : _("Failed to start `ssh' process.\n")); |
631 | return; | ||
632 | } | ||
643 | #if DEBUG_TESTING | 633 | #if DEBUG_TESTING |
644 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 634 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
645 | "Started `%s', waiting for `%s' to be up.\n", | 635 | "Started `%s', waiting for `%s' to be up.\n", |
646 | "gnunet-arm", "gnunet-service-core"); | 636 | "gnunet-arm", "gnunet-service-core"); |
647 | #endif | 637 | #endif |
648 | d->phase = SP_START_ARMING; | 638 | d->phase = SP_START_ARMING; |
649 | d->task | 639 | d->task |
650 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 640 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
651 | &start_fsm, d); | 641 | &start_fsm, d); |
652 | break; | 642 | break; |
653 | case SP_START_ARMING: | 643 | case SP_START_ARMING: |
654 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 644 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
655 | { | 645 | { |
656 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 646 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
657 | 0) | 647 | { |
658 | { | 648 | cb = d->cb; |
659 | cb = d->cb; | 649 | d->cb = NULL; |
660 | d->cb = NULL; | 650 | if (NULL != cb) |
661 | if (NULL != cb) | 651 | cb (d->cb_cls, |
662 | cb (d->cb_cls, | 652 | NULL, |
663 | NULL, | 653 | d->cfg, |
664 | d->cfg, | 654 | d, |
665 | d, | 655 | (NULL == d->hostname) |
666 | (NULL == d->hostname) | 656 | ? _("`gnunet-arm' does not seem to terminate.\n") |
667 | ? _("`gnunet-arm' does not seem to terminate.\n") | 657 | : _("`ssh' does not seem to terminate.\n")); |
668 | : _("`ssh' does not seem to terminate.\n")); | 658 | GNUNET_CONFIGURATION_destroy (d->cfg); |
669 | GNUNET_CONFIGURATION_destroy (d->cfg); | 659 | GNUNET_free (d->cfgfile); |
670 | GNUNET_free (d->cfgfile); | 660 | GNUNET_free_non_null (d->hostname); |
671 | GNUNET_free_non_null (d->hostname); | 661 | GNUNET_free_non_null (d->username); |
672 | GNUNET_free_non_null (d->username); | 662 | GNUNET_free (d->proc); |
673 | GNUNET_free(d->proc); | 663 | GNUNET_free (d); |
674 | GNUNET_free(d); | 664 | return; |
675 | return; | 665 | } |
676 | } | 666 | /* wait some more */ |
677 | /* wait some more */ | 667 | d->task |
678 | d->task | 668 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
679 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 669 | &start_fsm, d); |
680 | &start_fsm, d); | 670 | return; |
681 | return; | 671 | } |
682 | } | ||
683 | #if DEBUG_TESTING | 672 | #if DEBUG_TESTING |
684 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 673 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
685 | "Successfully started `%s'.\n", "gnunet-arm"); | 674 | "Successfully started `%s'.\n", "gnunet-arm"); |
686 | #endif | 675 | #endif |
687 | GNUNET_free(d->proc); | 676 | GNUNET_free (d->proc); |
688 | d->phase = SP_START_CORE; | 677 | d->phase = SP_START_CORE; |
689 | #if DEBUG_TESTING | 678 | #if DEBUG_TESTING |
690 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 679 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Calling CORE_connect\n"); |
691 | "Calling CORE_connect\n"); | ||
692 | #endif | 680 | #endif |
693 | /* Fall through */ | 681 | /* Fall through */ |
694 | case SP_START_CORE: | 682 | case SP_START_CORE: |
695 | if (d->server != NULL) | 683 | if (d->server != NULL) |
696 | GNUNET_CORE_disconnect(d->server); | 684 | GNUNET_CORE_disconnect (d->server); |
697 | 685 | ||
698 | #if WAIT_FOR_HELLO | 686 | #if WAIT_FOR_HELLO |
699 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 687 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
700 | 0) | 688 | { |
701 | { | 689 | cb = d->cb; |
702 | cb = d->cb; | 690 | d->cb = NULL; |
703 | d->cb = NULL; | 691 | if (NULL != cb) |
704 | if (NULL != cb) | 692 | cb (d->cb_cls, |
705 | cb (d->cb_cls, | 693 | NULL, |
706 | NULL, | 694 | d->cfg, d, _("Unable to connect to CORE service for peer!\n")); |
707 | d->cfg, | 695 | GNUNET_CONFIGURATION_destroy (d->cfg); |
708 | d, | 696 | GNUNET_free (d->cfgfile); |
709 | _("Unable to connect to CORE service for peer!\n")); | 697 | GNUNET_free_non_null (d->hostname); |
710 | GNUNET_CONFIGURATION_destroy (d->cfg); | 698 | GNUNET_free_non_null (d->username); |
711 | GNUNET_free (d->cfgfile); | 699 | GNUNET_free (d); |
712 | GNUNET_free_non_null (d->hostname); | 700 | return; |
713 | GNUNET_free_non_null (d->username); | 701 | } |
714 | GNUNET_free (d); | 702 | d->server = GNUNET_CORE_connect (d->cfg, 1, |
715 | return; | 703 | d, |
716 | } | 704 | &testing_init, |
717 | d->server = GNUNET_CORE_connect (d->cfg, 1, | 705 | NULL, NULL, NULL, |
718 | d, | 706 | NULL, GNUNET_NO, |
719 | &testing_init, | 707 | NULL, GNUNET_NO, no_handlers); |
720 | NULL, NULL, NULL, | 708 | d->task |
721 | NULL, GNUNET_NO, | 709 | = |
722 | NULL, GNUNET_NO, no_handlers); | 710 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
723 | d->task | 711 | (GNUNET_CONSTANTS_SERVICE_RETRY, 2), |
724 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2), | 712 | &start_fsm, d); |
725 | &start_fsm, d); | ||
726 | #else | 713 | #else |
727 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | 714 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); |
728 | if (d->th == NULL) | 715 | if (d->th == NULL) |
729 | { | 716 | { |
730 | if (GNUNET_YES == d->dead) | 717 | if (GNUNET_YES == d->dead) |
731 | GNUNET_TESTING_daemon_stop (d, | 718 | GNUNET_TESTING_daemon_stop (d, |
732 | GNUNET_TIME_absolute_get_remaining | 719 | GNUNET_TIME_absolute_get_remaining |
733 | (d->max_timeout), d->dead_cb, | 720 | (d->max_timeout), d->dead_cb, |
734 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 721 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
735 | else if (NULL != d->cb) | 722 | else if (NULL != d->cb) |
736 | d->cb (d->cb_cls, &d->id, d->cfg, d, | 723 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
737 | _("Failed to connect to transport service!\n")); | 724 | _("Failed to connect to transport service!\n")); |
738 | return; | 725 | return; |
739 | } | 726 | } |
740 | #if DEBUG_TESTING | 727 | #if DEBUG_TESTING |
741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
742 | "Connected to transport service `%s', getting HELLO\n", | 729 | "Connected to transport service `%s', getting HELLO\n", |
743 | GNUNET_i2s (&d->id)); | 730 | GNUNET_i2s (&d->id)); |
744 | #endif | 731 | #endif |
745 | 732 | ||
746 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | 733 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); |
747 | GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); | 734 | GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); |
748 | /*cb = d->cb; | 735 | /*cb = d->cb; |
736 | * d->cb = NULL; | ||
737 | * if (NULL != cb) | ||
738 | * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */ | ||
739 | d->running = GNUNET_YES; | ||
740 | d->phase = SP_GET_HELLO; | ||
741 | #endif | ||
742 | break; | ||
743 | case SP_GET_HELLO: | ||
744 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
745 | { | ||
746 | if (d->server != NULL) | ||
747 | GNUNET_CORE_disconnect (d->server); | ||
748 | if (d->th != NULL) | ||
749 | GNUNET_TRANSPORT_disconnect (d->th); | ||
750 | cb = d->cb; | ||
749 | d->cb = NULL; | 751 | d->cb = NULL; |
750 | if (NULL != cb) | 752 | if (NULL != cb) |
751 | cb (d->cb_cls, &d->id, d->cfg, d, NULL);*/ | 753 | cb (d->cb_cls, NULL, d->cfg, d, _("Unable to get HELLO for peer!\n")); |
752 | d->running = GNUNET_YES; | 754 | GNUNET_CONFIGURATION_destroy (d->cfg); |
753 | d->phase = SP_GET_HELLO; | 755 | GNUNET_free (d->cfgfile); |
754 | #endif | 756 | GNUNET_free_non_null (d->hostname); |
755 | break; | 757 | GNUNET_free_non_null (d->username); |
756 | case SP_GET_HELLO: | 758 | GNUNET_free (d); |
757 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 759 | return; |
758 | 0) | 760 | } |
759 | { | 761 | if (d->hello != NULL) |
760 | if (d->server != NULL) | 762 | return; |
761 | GNUNET_CORE_disconnect(d->server); | 763 | GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK); |
762 | if (d->th != NULL) | 764 | d->task |
763 | GNUNET_TRANSPORT_disconnect(d->th); | 765 | = |
764 | cb = d->cb; | 766 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
765 | d->cb = NULL; | 767 | (GNUNET_CONSTANTS_SERVICE_RETRY, 2), |
766 | if (NULL != cb) | 768 | &start_fsm, d); |
767 | cb (d->cb_cls, | 769 | break; |
768 | NULL, | 770 | case SP_START_DONE: |
769 | d->cfg, | 771 | GNUNET_break (0); |
770 | d, | 772 | break; |
771 | _("Unable to get HELLO for peer!\n")); | 773 | case SP_SERVICE_START: |
772 | GNUNET_CONFIGURATION_destroy (d->cfg); | 774 | /* confirm gnunet-arm exited */ |
773 | GNUNET_free (d->cfgfile); | 775 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
774 | GNUNET_free_non_null (d->hostname); | 776 | { |
775 | GNUNET_free_non_null (d->username); | 777 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
776 | GNUNET_free (d); | 778 | { |
777 | return; | 779 | cb = d->cb; |
778 | } | 780 | d->cb = NULL; |
779 | if (d->hello != NULL) | 781 | if (NULL != cb) |
782 | cb (d->cb_cls, | ||
783 | NULL, | ||
784 | d->cfg, | ||
785 | d, | ||
786 | (NULL == d->hostname) | ||
787 | ? _("`gnunet-arm' does not seem to terminate.\n") | ||
788 | : _("`ssh' does not seem to terminate.\n")); | ||
780 | return; | 789 | return; |
781 | GNUNET_assert(d->task == GNUNET_SCHEDULER_NO_TASK); | 790 | } |
791 | /* wait some more */ | ||
782 | d->task | 792 | d->task |
783 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2), | 793 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
784 | &start_fsm, d); | 794 | &start_fsm, d); |
785 | break; | 795 | return; |
786 | case SP_START_DONE: | 796 | } |
787 | GNUNET_break (0); | ||
788 | break; | ||
789 | case SP_SERVICE_START: | ||
790 | /* confirm gnunet-arm exited */ | ||
791 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
792 | { | ||
793 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
794 | 0) | ||
795 | { | ||
796 | cb = d->cb; | ||
797 | d->cb = NULL; | ||
798 | if (NULL != cb) | ||
799 | cb (d->cb_cls, | ||
800 | NULL, | ||
801 | d->cfg, | ||
802 | d, | ||
803 | (NULL == d->hostname) | ||
804 | ? _("`gnunet-arm' does not seem to terminate.\n") | ||
805 | : _("`ssh' does not seem to terminate.\n")); | ||
806 | return; | ||
807 | } | ||
808 | /* wait some more */ | ||
809 | d->task | ||
810 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
811 | &start_fsm, d); | ||
812 | return; | ||
813 | } | ||
814 | #if EXTRA_CHECKS | 797 | #if EXTRA_CHECKS |
815 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | 798 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
816 | { | 799 | { |
817 | cb = d->cb; | ||
818 | d->cb = NULL; | ||
819 | if (NULL != cb) | ||
820 | cb (d->cb_cls, | ||
821 | NULL, | ||
822 | d->cfg, | ||
823 | d, | ||
824 | (NULL == d->hostname) | ||
825 | ? _("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n") | ||
826 | : _("`ssh' does not seem to terminate.\n")); | ||
827 | return; | ||
828 | } | ||
829 | #endif | ||
830 | #if DEBUG_TESTING | ||
831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n"); | ||
832 | #endif | ||
833 | cb = d->cb; | 800 | cb = d->cb; |
834 | d->cb = NULL; | 801 | d->cb = NULL; |
835 | d->phase = SP_START_DONE; | ||
836 | if (NULL != cb) | 802 | if (NULL != cb) |
837 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); | 803 | cb (d->cb_cls, |
838 | break; | 804 | NULL, |
839 | case SP_SERVICE_SHUTDOWN_START: | 805 | d->cfg, |
840 | /* confirm copying complete */ | 806 | d, |
841 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 807 | (NULL == d->hostname) |
842 | { | 808 | ? |
843 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | 809 | _ |
844 | 0) | 810 | ("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n") |
845 | { | 811 | : _("`ssh' does not seem to terminate.\n")); |
846 | if (NULL != d->dead_cb) | 812 | return; |
847 | d->dead_cb (d->dead_cb_cls, | 813 | } |
848 | _ | ||
849 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
850 | return; | ||
851 | } | ||
852 | /* wait some more */ | ||
853 | d->task | ||
854 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
855 | &start_fsm, d); | ||
856 | return; | ||
857 | } | ||
858 | #if EXTRA_CHECKS | ||
859 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
860 | { | ||
861 | if (NULL != d->dead_cb) | ||
862 | d->dead_cb (d->dead_cb_cls, | ||
863 | _ | ||
864 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | ||
865 | return; | ||
866 | } | ||
867 | #endif | 814 | #endif |
868 | #if DEBUG_TESTING | 815 | #if DEBUG_TESTING |
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n"); |
870 | #endif | 817 | #endif |
818 | cb = d->cb; | ||
819 | d->cb = NULL; | ||
820 | d->phase = SP_START_DONE; | ||
821 | if (NULL != cb) | ||
822 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); | ||
823 | break; | ||
824 | case SP_SERVICE_SHUTDOWN_START: | ||
825 | /* confirm copying complete */ | ||
826 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
827 | { | ||
828 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
829 | { | ||
830 | if (NULL != d->dead_cb) | ||
831 | d->dead_cb (d->dead_cb_cls, | ||
832 | _ | ||
833 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
834 | return; | ||
835 | } | ||
836 | /* wait some more */ | ||
837 | d->task | ||
838 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
839 | &start_fsm, d); | ||
840 | return; | ||
841 | } | ||
842 | #if EXTRA_CHECKS | ||
843 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
844 | { | ||
871 | if (NULL != d->dead_cb) | 845 | if (NULL != d->dead_cb) |
872 | d->dead_cb (d->dead_cb_cls, NULL); | 846 | d->dead_cb (d->dead_cb_cls, |
873 | break; | 847 | _ |
874 | case SP_SHUTDOWN_START: | 848 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); |
875 | /* confirm copying complete */ | 849 | return; |
876 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 850 | } |
877 | { | ||
878 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
879 | 0) | ||
880 | { | ||
881 | if (NULL != d->dead_cb) | ||
882 | d->dead_cb (d->dead_cb_cls, | ||
883 | _ | ||
884 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
885 | if (d->th != NULL) | ||
886 | { | ||
887 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, | ||
888 | d); | ||
889 | GNUNET_TRANSPORT_disconnect (d->th); | ||
890 | d->th = NULL; | ||
891 | } | ||
892 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
893 | GNUNET_free (d->cfgfile); | ||
894 | GNUNET_free_non_null (d->hello); | ||
895 | GNUNET_free_non_null (d->hostname); | ||
896 | GNUNET_free_non_null (d->username); | ||
897 | GNUNET_free_non_null (d->shortname); | ||
898 | GNUNET_free_non_null (d->proc); | ||
899 | d->proc = NULL; | ||
900 | GNUNET_free (d); | ||
901 | return; | ||
902 | } | ||
903 | /* wait some more */ | ||
904 | d->task | ||
905 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
906 | &start_fsm, d); | ||
907 | return; | ||
908 | } | ||
909 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
910 | { | ||
911 | if (NULL != d->dead_cb) | ||
912 | d->dead_cb (d->dead_cb_cls, | ||
913 | _ | ||
914 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | ||
915 | if (d->th != NULL) | ||
916 | { | ||
917 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | ||
918 | GNUNET_TRANSPORT_disconnect (d->th); | ||
919 | d->th = NULL; | ||
920 | } | ||
921 | if (d->server != NULL) | ||
922 | { | ||
923 | GNUNET_CORE_disconnect (d->server); | ||
924 | d->server = NULL; | ||
925 | } | ||
926 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
927 | GNUNET_free (d->cfgfile); | ||
928 | GNUNET_free_non_null (d->hello); | ||
929 | GNUNET_free_non_null (d->hostname); | ||
930 | GNUNET_free_non_null (d->username); | ||
931 | GNUNET_free_non_null (d->shortname); | ||
932 | GNUNET_free_non_null (d->proc); | ||
933 | d->proc = NULL; | ||
934 | GNUNET_free (d); | ||
935 | return; | ||
936 | } | ||
937 | #if DEBUG_TESTING | ||
938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); | ||
939 | #endif | 851 | #endif |
940 | if (d->server != NULL) | 852 | #if DEBUG_TESTING |
941 | { | 853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); |
942 | GNUNET_CORE_disconnect (d->server); | 854 | #endif |
943 | d->server = NULL; | 855 | if (NULL != d->dead_cb) |
944 | } | 856 | d->dead_cb (d->dead_cb_cls, NULL); |
945 | 857 | break; | |
946 | if (d->th != NULL) | 858 | case SP_SHUTDOWN_START: |
859 | /* confirm copying complete */ | ||
860 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
861 | { | ||
862 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
863 | { | ||
864 | if (NULL != d->dead_cb) | ||
865 | d->dead_cb (d->dead_cb_cls, | ||
866 | _ | ||
867 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
868 | if (d->th != NULL) | ||
947 | { | 869 | { |
948 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | 870 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
949 | GNUNET_TRANSPORT_disconnect (d->th); | 871 | GNUNET_TRANSPORT_disconnect (d->th); |
950 | d->th = NULL; | 872 | d->th = NULL; |
951 | } | 873 | } |
952 | 874 | GNUNET_CONFIGURATION_destroy (d->cfg); | |
875 | GNUNET_free (d->cfgfile); | ||
876 | GNUNET_free_non_null (d->hello); | ||
877 | GNUNET_free_non_null (d->hostname); | ||
878 | GNUNET_free_non_null (d->username); | ||
879 | GNUNET_free_non_null (d->shortname); | ||
880 | GNUNET_free_non_null (d->proc); | ||
881 | d->proc = NULL; | ||
882 | GNUNET_free (d); | ||
883 | return; | ||
884 | } | ||
885 | /* wait some more */ | ||
886 | d->task | ||
887 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
888 | &start_fsm, d); | ||
889 | return; | ||
890 | } | ||
891 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
892 | { | ||
953 | if (NULL != d->dead_cb) | 893 | if (NULL != d->dead_cb) |
954 | d->dead_cb (d->dead_cb_cls, NULL); | 894 | d->dead_cb (d->dead_cb_cls, |
955 | 895 | _ | |
956 | /* state clean up and notifications */ | 896 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); |
957 | if (d->churn == GNUNET_NO) | 897 | if (d->th != NULL) |
958 | { | 898 | { |
959 | GNUNET_CONFIGURATION_destroy (d->cfg); | 899 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
960 | GNUNET_free (d->cfgfile); | 900 | GNUNET_TRANSPORT_disconnect (d->th); |
961 | GNUNET_free_non_null (d->hostname); | 901 | d->th = NULL; |
962 | GNUNET_free_non_null (d->username); | 902 | } |
963 | } | 903 | if (d->server != NULL) |
964 | 904 | { | |
905 | GNUNET_CORE_disconnect (d->server); | ||
906 | d->server = NULL; | ||
907 | } | ||
908 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
909 | GNUNET_free (d->cfgfile); | ||
965 | GNUNET_free_non_null (d->hello); | 910 | GNUNET_free_non_null (d->hello); |
966 | d->hello = NULL; | 911 | GNUNET_free_non_null (d->hostname); |
912 | GNUNET_free_non_null (d->username); | ||
967 | GNUNET_free_non_null (d->shortname); | 913 | GNUNET_free_non_null (d->shortname); |
968 | GNUNET_free_non_null (d->proc); | 914 | GNUNET_free_non_null (d->proc); |
969 | d->proc = NULL; | 915 | d->proc = NULL; |
970 | d->shortname = NULL; | 916 | GNUNET_free (d); |
971 | if (d->churn == GNUNET_NO) | 917 | return; |
972 | GNUNET_free (d); | 918 | } |
973 | |||
974 | break; | ||
975 | case SP_CONFIG_UPDATE: | ||
976 | /* confirm copying complete */ | ||
977 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
978 | { | ||
979 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ | ||
980 | { | ||
981 | cb = d->cb; | ||
982 | d->cb = NULL; | ||
983 | if (NULL != cb) | ||
984 | cb (d->cb_cls, | ||
985 | NULL, | ||
986 | d->cfg, d, _("`scp' does not seem to terminate.\n")); | ||
987 | return; | ||
988 | } | ||
989 | /* wait some more */ | ||
990 | d->task | ||
991 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
992 | &start_fsm, d); | ||
993 | return; | ||
994 | } | ||
995 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
996 | { | ||
997 | if (NULL != d->update_cb) | ||
998 | d->update_cb (d->update_cb_cls, | ||
999 | _("`scp' did not complete cleanly.\n")); | ||
1000 | return; | ||
1001 | } | ||
1002 | #if DEBUG_TESTING | 919 | #if DEBUG_TESTING |
1003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 920 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); |
1004 | "Successfully copied configuration file.\n"); | ||
1005 | #endif | 921 | #endif |
922 | if (d->server != NULL) | ||
923 | { | ||
924 | GNUNET_CORE_disconnect (d->server); | ||
925 | d->server = NULL; | ||
926 | } | ||
927 | |||
928 | if (d->th != NULL) | ||
929 | { | ||
930 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | ||
931 | GNUNET_TRANSPORT_disconnect (d->th); | ||
932 | d->th = NULL; | ||
933 | } | ||
934 | |||
935 | if (NULL != d->dead_cb) | ||
936 | d->dead_cb (d->dead_cb_cls, NULL); | ||
937 | |||
938 | /* state clean up and notifications */ | ||
939 | if (d->churn == GNUNET_NO) | ||
940 | { | ||
941 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
942 | GNUNET_free (d->cfgfile); | ||
943 | GNUNET_free_non_null (d->hostname); | ||
944 | GNUNET_free_non_null (d->username); | ||
945 | } | ||
946 | |||
947 | GNUNET_free_non_null (d->hello); | ||
948 | d->hello = NULL; | ||
949 | GNUNET_free_non_null (d->shortname); | ||
950 | GNUNET_free_non_null (d->proc); | ||
951 | d->proc = NULL; | ||
952 | d->shortname = NULL; | ||
953 | if (d->churn == GNUNET_NO) | ||
954 | GNUNET_free (d); | ||
955 | |||
956 | break; | ||
957 | case SP_CONFIG_UPDATE: | ||
958 | /* confirm copying complete */ | ||
959 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
960 | { | ||
961 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ | ||
962 | { | ||
963 | cb = d->cb; | ||
964 | d->cb = NULL; | ||
965 | if (NULL != cb) | ||
966 | cb (d->cb_cls, | ||
967 | NULL, d->cfg, d, _("`scp' does not seem to terminate.\n")); | ||
968 | return; | ||
969 | } | ||
970 | /* wait some more */ | ||
971 | d->task | ||
972 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
973 | &start_fsm, d); | ||
974 | return; | ||
975 | } | ||
976 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
977 | { | ||
1006 | if (NULL != d->update_cb) | 978 | if (NULL != d->update_cb) |
1007 | d->update_cb (d->update_cb_cls, NULL); | 979 | d->update_cb (d->update_cb_cls, _("`scp' did not complete cleanly.\n")); |
1008 | d->phase = SP_START_DONE; | 980 | return; |
1009 | break; | ||
1010 | } | 981 | } |
982 | #if DEBUG_TESTING | ||
983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
984 | "Successfully copied configuration file.\n"); | ||
985 | #endif | ||
986 | if (NULL != d->update_cb) | ||
987 | d->update_cb (d->update_cb_cls, NULL); | ||
988 | d->phase = SP_START_DONE; | ||
989 | break; | ||
990 | } | ||
1011 | } | 991 | } |
1012 | 992 | ||
1013 | /** | 993 | /** |
@@ -1055,77 +1035,81 @@ GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon) | |||
1055 | */ | 1035 | */ |
1056 | void | 1036 | void |
1057 | GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, | 1037 | GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, |
1058 | char *service, | 1038 | char *service, |
1059 | struct GNUNET_TIME_Relative timeout, | 1039 | struct GNUNET_TIME_Relative |
1060 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) | 1040 | timeout, |
1041 | GNUNET_TESTING_NotifyDaemonRunning | ||
1042 | cb, void *cb_cls) | ||
1061 | { | 1043 | { |
1062 | char *arg; | 1044 | char *arg; |
1045 | |||
1063 | d->cb = cb; | 1046 | d->cb = cb; |
1064 | d->cb_cls = cb_cls; | 1047 | d->cb_cls = cb_cls; |
1065 | 1048 | ||
1066 | GNUNET_assert(d->running == GNUNET_YES); | 1049 | GNUNET_assert (d->running == GNUNET_YES); |
1067 | 1050 | ||
1068 | if (d->phase == SP_CONFIG_UPDATE) | 1051 | if (d->phase == SP_CONFIG_UPDATE) |
1069 | { | 1052 | { |
1070 | GNUNET_SCHEDULER_cancel (d->task); | 1053 | GNUNET_SCHEDULER_cancel (d->task); |
1071 | d->phase = SP_START_DONE; | 1054 | d->phase = SP_START_DONE; |
1072 | } | 1055 | } |
1073 | 1056 | ||
1074 | if (d->churned_services == NULL) | 1057 | if (d->churned_services == NULL) |
1075 | { | 1058 | { |
1076 | d->cb(d->cb_cls, &d->id, d->cfg, d, "No service has been churned off yet!!"); | 1059 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
1077 | return; | 1060 | "No service has been churned off yet!!"); |
1078 | } | 1061 | return; |
1062 | } | ||
1079 | d->phase = SP_SERVICE_START; | 1063 | d->phase = SP_SERVICE_START; |
1080 | GNUNET_free(d->churned_services); | 1064 | GNUNET_free (d->churned_services); |
1081 | d->churned_services = NULL; | 1065 | d->churned_services = NULL; |
1082 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1066 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1083 | /* Check if this is a local or remote process */ | 1067 | /* Check if this is a local or remote process */ |
1084 | if (NULL != d->hostname) | 1068 | if (NULL != d->hostname) |
1085 | { | 1069 | { |
1086 | #if DEBUG_TESTING | 1070 | #if DEBUG_TESTING |
1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1088 | "Starting gnunet-arm with config `%s' on host `%s'.\n", | 1072 | "Starting gnunet-arm with config `%s' on host `%s'.\n", |
1089 | d->cfgfile, d->hostname); | 1073 | d->cfgfile, d->hostname); |
1090 | #endif | 1074 | #endif |
1091 | 1075 | ||
1092 | if (d->username != NULL) | 1076 | if (d->username != NULL) |
1093 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1077 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1094 | else | 1078 | else |
1095 | arg = GNUNET_strdup (d->hostname); | 1079 | arg = GNUNET_strdup (d->hostname); |
1096 | 1080 | ||
1097 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1081 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1098 | #if !DEBUG_TESTING | 1082 | #if !DEBUG_TESTING |
1099 | "-q", | 1083 | "-q", |
1100 | #endif | 1084 | #endif |
1101 | arg, "gnunet-arm", | 1085 | arg, "gnunet-arm", |
1102 | #if DEBUG_TESTING | 1086 | #if DEBUG_TESTING |
1103 | "-L", "DEBUG", | 1087 | "-L", "DEBUG", |
1104 | #endif | 1088 | #endif |
1105 | "-c", d->cfgfile, "-i", service, "-q", | 1089 | "-c", d->cfgfile, "-i", service, "-q", |
1106 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1090 | "-T", |
1107 | NULL); | 1091 | GNUNET_TIME_relative_to_string (timeout), |
1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1092 | NULL); |
1109 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n", | 1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1110 | arg, "gnunet-arm", d->cfgfile, service); | 1094 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n", |
1111 | GNUNET_free (arg); | 1095 | arg, "gnunet-arm", d->cfgfile, service); |
1112 | } | 1096 | GNUNET_free (arg); |
1097 | } | ||
1113 | else | 1098 | else |
1114 | { | 1099 | { |
1115 | #if DEBUG_TESTING | 1100 | #if DEBUG_TESTING |
1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1117 | "Starting gnunet-arm with config `%s' locally.\n", | 1102 | "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1118 | d->cfgfile); | ||
1119 | #endif | 1103 | #endif |
1120 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1104 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1121 | "gnunet-arm", | ||
1122 | #if DEBUG_TESTING | 1105 | #if DEBUG_TESTING |
1123 | "-L", "DEBUG", | 1106 | "-L", "DEBUG", |
1124 | #endif | 1107 | #endif |
1125 | "-c", d->cfgfile, "-i", service, "-q", | 1108 | "-c", d->cfgfile, "-i", service, "-q", |
1126 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1109 | "-T", |
1127 | NULL); | 1110 | GNUNET_TIME_relative_to_string (timeout), |
1128 | } | 1111 | NULL); |
1112 | } | ||
1129 | 1113 | ||
1130 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1114 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1131 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | 1115 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
@@ -1144,72 +1128,77 @@ void | |||
1144 | GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, | 1128 | GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, |
1145 | char *service, | 1129 | char *service, |
1146 | struct GNUNET_TIME_Relative timeout, | 1130 | struct GNUNET_TIME_Relative timeout, |
1147 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) | 1131 | GNUNET_TESTING_NotifyDaemonRunning cb, |
1132 | void *cb_cls) | ||
1148 | { | 1133 | { |
1149 | char *arg; | 1134 | char *arg; |
1135 | |||
1150 | d->cb = cb; | 1136 | d->cb = cb; |
1151 | d->cb_cls = cb_cls; | 1137 | d->cb_cls = cb_cls; |
1152 | 1138 | ||
1153 | GNUNET_assert(service != NULL); | 1139 | GNUNET_assert (service != NULL); |
1154 | GNUNET_assert(d->running == GNUNET_YES); | 1140 | GNUNET_assert (d->running == GNUNET_YES); |
1155 | GNUNET_assert(d->phase == SP_START_DONE); | 1141 | GNUNET_assert (d->phase == SP_START_DONE); |
1156 | 1142 | ||
1157 | #if DEBUG_TESTING | 1143 | #if DEBUG_TESTING |
1158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1159 | _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s (&d->id)); | 1145 | _("Starting service %s for peer `%4s'\n"), service, |
1146 | GNUNET_i2s (&d->id)); | ||
1160 | #endif | 1147 | #endif |
1161 | 1148 | ||
1162 | d->phase = SP_SERVICE_START; | 1149 | d->phase = SP_SERVICE_START; |
1163 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1150 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1164 | /* Check if this is a local or remote process */ | 1151 | /* Check if this is a local or remote process */ |
1165 | if (NULL != d->hostname) | 1152 | if (NULL != d->hostname) |
1166 | { | 1153 | { |
1167 | #if DEBUG_TESTING | 1154 | #if DEBUG_TESTING |
1168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1169 | "Starting gnunet-arm with config `%s' on host `%s'.\n", | 1156 | "Starting gnunet-arm with config `%s' on host `%s'.\n", |
1170 | d->cfgfile, d->hostname); | 1157 | d->cfgfile, d->hostname); |
1171 | #endif | 1158 | #endif |
1172 | 1159 | ||
1173 | if (d->username != NULL) | 1160 | if (d->username != NULL) |
1174 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1161 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1175 | else | 1162 | else |
1176 | arg = GNUNET_strdup (d->hostname); | 1163 | arg = GNUNET_strdup (d->hostname); |
1177 | 1164 | ||
1178 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1165 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1179 | #if !DEBUG_TESTING | 1166 | #if !DEBUG_TESTING |
1180 | "-q", | 1167 | "-q", |
1181 | #endif | 1168 | #endif |
1182 | arg, "gnunet-arm", | 1169 | arg, "gnunet-arm", |
1183 | #if DEBUG_TESTING | 1170 | #if DEBUG_TESTING |
1184 | "-L", "DEBUG", | 1171 | "-L", "DEBUG", |
1185 | #endif | 1172 | #endif |
1186 | "-c", d->cfgfile, "-i", service, "-q", | 1173 | "-c", d->cfgfile, "-i", service, "-q", |
1187 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1174 | "-T", |
1188 | NULL); | 1175 | GNUNET_TIME_relative_to_string (timeout), |
1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1176 | NULL); |
1190 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q -T %s\n", | 1177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1191 | arg, "gnunet-arm", d->cfgfile, service, GNUNET_TIME_relative_to_string(timeout)); | 1178 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q -T %s\n", |
1192 | GNUNET_free (arg); | 1179 | arg, "gnunet-arm", d->cfgfile, service, |
1193 | } | 1180 | GNUNET_TIME_relative_to_string (timeout)); |
1181 | GNUNET_free (arg); | ||
1182 | } | ||
1194 | else | 1183 | else |
1195 | { | 1184 | { |
1196 | #if DEBUG_TESTING | 1185 | #if DEBUG_TESTING |
1197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1198 | "Starting gnunet-arm with config `%s' locally.\n", | 1187 | "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1199 | d->cfgfile); | ||
1200 | #endif | 1188 | #endif |
1201 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1189 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1202 | "gnunet-arm", | ||
1203 | #if DEBUG_TESTING | 1190 | #if DEBUG_TESTING |
1204 | "-L", "DEBUG", | 1191 | "-L", "DEBUG", |
1205 | #endif | 1192 | #endif |
1206 | "-c", d->cfgfile, "-i", service, "-q", | 1193 | "-c", d->cfgfile, "-i", service, "-q", |
1207 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1194 | "-T", |
1208 | NULL); | 1195 | GNUNET_TIME_relative_to_string (timeout), |
1209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1196 | NULL); |
1210 | "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n", | 1197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1211 | "gnunet-arm", d->cfgfile, service, GNUNET_TIME_relative_to_string(timeout)); | 1198 | "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n", |
1212 | } | 1199 | "gnunet-arm", d->cfgfile, service, |
1200 | GNUNET_TIME_relative_to_string (timeout)); | ||
1201 | } | ||
1213 | 1202 | ||
1214 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1203 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1215 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | 1204 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
@@ -1231,11 +1220,11 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, | |||
1231 | void *cb_cls) | 1220 | void *cb_cls) |
1232 | { | 1221 | { |
1233 | if (daemon->running == GNUNET_YES) | 1222 | if (daemon->running == GNUNET_YES) |
1234 | { | 1223 | { |
1235 | cb (cb_cls, &daemon->id, daemon->cfg, daemon, | 1224 | cb (cb_cls, &daemon->id, daemon->cfg, daemon, |
1236 | "Daemon already running, can't restart!"); | 1225 | "Daemon already running, can't restart!"); |
1237 | return; | 1226 | return; |
1238 | } | 1227 | } |
1239 | 1228 | ||
1240 | daemon->cb = cb; | 1229 | daemon->cb = cb; |
1241 | daemon->cb_cls = cb_cls; | 1230 | daemon->cb_cls = cb_cls; |
@@ -1298,35 +1287,34 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1298 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); | 1287 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); |
1299 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); | 1288 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); |
1300 | if (sshport != 0) | 1289 | if (sshport != 0) |
1301 | { | 1290 | { |
1302 | GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport); | 1291 | GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport); |
1303 | } | 1292 | } |
1304 | else | 1293 | else |
1305 | ret->ssh_port_str = NULL; | 1294 | ret->ssh_port_str = NULL; |
1306 | 1295 | ||
1307 | /* Find service home and base service home directories, create it if it doesn't exist */ | 1296 | /* Find service home and base service home directories, create it if it doesn't exist */ |
1308 | GNUNET_assert(GNUNET_OK == | 1297 | GNUNET_assert (GNUNET_OK == |
1309 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1298 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1310 | "PATHS", | 1299 | "PATHS", |
1311 | "SERVICEHOME", | 1300 | "SERVICEHOME", |
1312 | &servicehome)); | 1301 | &servicehome)); |
1313 | 1302 | ||
1314 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome)); | 1303 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome)); |
1315 | GNUNET_asprintf(&temp_file_name, "%s/gnunet-testing-config", servicehome); | 1304 | GNUNET_asprintf (&temp_file_name, "%s/gnunet-testing-config", servicehome); |
1316 | ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name); | 1305 | ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name); |
1317 | GNUNET_free(temp_file_name); | 1306 | GNUNET_free (temp_file_name); |
1318 | #if DEBUG_TESTING | 1307 | #if DEBUG_TESTING |
1319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1320 | "Setting up peer with configuration file `%s'.\n", | 1309 | "Setting up peer with configuration file `%s'.\n", ret->cfgfile); |
1321 | ret->cfgfile); | ||
1322 | #endif | 1310 | #endif |
1323 | if (NULL == ret->cfgfile) | 1311 | if (NULL == ret->cfgfile) |
1324 | { | 1312 | { |
1325 | GNUNET_free_non_null (ret->ssh_port_str); | 1313 | GNUNET_free_non_null (ret->ssh_port_str); |
1326 | GNUNET_free_non_null (ret->hostname); | 1314 | GNUNET_free_non_null (ret->hostname); |
1327 | GNUNET_free (ret); | 1315 | GNUNET_free (ret); |
1328 | return NULL; | 1316 | return NULL; |
1329 | } | 1317 | } |
1330 | ret->hostkey_callback = hostkey_callback; | 1318 | ret->hostkey_callback = hostkey_callback; |
1331 | ret->hostkey_cls = hostkey_cls; | 1319 | ret->hostkey_cls = hostkey_cls; |
1332 | ret->cb = cb; | 1320 | ret->cb = cb; |
@@ -1337,46 +1325,47 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1337 | "PATHS", | 1325 | "PATHS", |
1338 | "DEFAULTCONFIG", ret->cfgfile); | 1326 | "DEFAULTCONFIG", ret->cfgfile); |
1339 | 1327 | ||
1340 | if (hostkey != NULL) /* Get the peer identity from the hostkey */ | 1328 | if (hostkey != NULL) /* Get the peer identity from the hostkey */ |
1341 | { | 1329 | { |
1342 | private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE); | 1330 | private_key = GNUNET_CRYPTO_rsa_decode_key (hostkey, HOSTKEYFILESIZE); |
1343 | GNUNET_assert(private_key != NULL); | 1331 | GNUNET_assert (private_key != NULL); |
1344 | GNUNET_CRYPTO_rsa_key_get_public (private_key, | 1332 | GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key); |
1345 | &public_key); | 1333 | GNUNET_CRYPTO_hash (&public_key, |
1346 | GNUNET_CRYPTO_hash(&public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey); | 1334 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1347 | ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id)); | 1335 | &ret->id.hashPubKey); |
1348 | ret->have_hostkey = GNUNET_YES; | 1336 | ret->shortname = GNUNET_strdup (GNUNET_i2s (&ret->id)); |
1349 | GNUNET_CRYPTO_rsa_key_free(private_key); | 1337 | ret->have_hostkey = GNUNET_YES; |
1350 | } | 1338 | GNUNET_CRYPTO_rsa_key_free (private_key); |
1339 | } | ||
1351 | 1340 | ||
1352 | /* Write hostkey to file, if we were given one */ | 1341 | /* Write hostkey to file, if we were given one */ |
1353 | hostkeyfile = NULL; | 1342 | hostkeyfile = NULL; |
1354 | if (hostkey != NULL) | 1343 | if (hostkey != NULL) |
1355 | { | 1344 | { |
1356 | GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome); | 1345 | GNUNET_asprintf (&hostkeyfile, "%s/.hostkey", servicehome); |
1357 | fn = | 1346 | fn = GNUNET_DISK_file_open (hostkeyfile, |
1358 | GNUNET_DISK_file_open (hostkeyfile, | 1347 | GNUNET_DISK_OPEN_READWRITE |
1359 | GNUNET_DISK_OPEN_READWRITE | 1348 | | GNUNET_DISK_OPEN_CREATE, |
1360 | | GNUNET_DISK_OPEN_CREATE, | 1349 | GNUNET_DISK_PERM_USER_READ | |
1361 | GNUNET_DISK_PERM_USER_READ | | 1350 | GNUNET_DISK_PERM_USER_WRITE); |
1362 | GNUNET_DISK_PERM_USER_WRITE); | 1351 | GNUNET_assert (fn != NULL); |
1363 | GNUNET_assert(fn != NULL); | 1352 | GNUNET_assert (HOSTKEYFILESIZE == |
1364 | GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE)); | 1353 | GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE)); |
1365 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn)); | 1354 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); |
1366 | } | 1355 | } |
1367 | 1356 | ||
1368 | /* write configuration to temporary file */ | 1357 | /* write configuration to temporary file */ |
1369 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) | 1358 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) |
1370 | { | 1359 | { |
1371 | if (0 != UNLINK (ret->cfgfile)) | 1360 | if (0 != UNLINK (ret->cfgfile)) |
1372 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 1361 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1373 | "unlink", ret->cfgfile); | 1362 | "unlink", ret->cfgfile); |
1374 | GNUNET_CONFIGURATION_destroy (ret->cfg); | 1363 | GNUNET_CONFIGURATION_destroy (ret->cfg); |
1375 | GNUNET_free_non_null (ret->hostname); | 1364 | GNUNET_free_non_null (ret->hostname); |
1376 | GNUNET_free (ret->cfgfile); | 1365 | GNUNET_free (ret->cfgfile); |
1377 | GNUNET_free (ret); | 1366 | GNUNET_free (ret); |
1378 | return NULL; | 1367 | return NULL; |
1379 | } | 1368 | } |
1380 | if (ssh_username != NULL) | 1369 | if (ssh_username != NULL) |
1381 | username = GNUNET_strdup (ssh_username); | 1370 | username = GNUNET_strdup (ssh_username); |
1382 | if ((ssh_username == NULL) && (GNUNET_OK != | 1371 | if ((ssh_username == NULL) && (GNUNET_OK != |
@@ -1384,103 +1373,103 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1384 | "TESTING", | 1373 | "TESTING", |
1385 | "USERNAME", | 1374 | "USERNAME", |
1386 | &username))) | 1375 | &username))) |
1387 | { | 1376 | { |
1388 | if (NULL != getenv ("USER")) | 1377 | if (NULL != getenv ("USER")) |
1389 | username = GNUNET_strdup (getenv ("USER")); | 1378 | username = GNUNET_strdup (getenv ("USER")); |
1390 | else | 1379 | else |
1391 | username = NULL; | 1380 | username = NULL; |
1392 | } | 1381 | } |
1393 | ret->username = username; | 1382 | ret->username = username; |
1394 | 1383 | ||
1395 | if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */ | 1384 | if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */ |
1385 | { | ||
1386 | /* copy directory to remote host */ | ||
1387 | if (NULL != hostname) | ||
1396 | { | 1388 | { |
1397 | /* copy directory to remote host */ | ||
1398 | if (NULL != hostname) | ||
1399 | { | ||
1400 | #if DEBUG_TESTING | 1389 | #if DEBUG_TESTING |
1401 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1402 | "Copying configuration directory to host `%s'.\n", hostname); | 1391 | "Copying configuration directory to host `%s'.\n", hostname); |
1403 | #endif | 1392 | #endif |
1404 | baseservicehome = GNUNET_strdup(servicehome); | 1393 | baseservicehome = GNUNET_strdup (servicehome); |
1405 | /* Remove trailing /'s */ | 1394 | /* Remove trailing /'s */ |
1406 | while (baseservicehome[strlen(baseservicehome) - 1] == '/') | 1395 | while (baseservicehome[strlen (baseservicehome) - 1] == '/') |
1407 | baseservicehome[strlen(baseservicehome) - 1] = '\0'; | 1396 | baseservicehome[strlen (baseservicehome) - 1] = '\0'; |
1408 | /* Find next directory /, jump one ahead */ | 1397 | /* Find next directory /, jump one ahead */ |
1409 | slash = strrchr(baseservicehome, '/'); | 1398 | slash = strrchr (baseservicehome, '/'); |
1410 | if (slash != NULL) | 1399 | if (slash != NULL) |
1411 | *(++slash) = '\0'; | 1400 | *(++slash) = '\0'; |
1412 | 1401 | ||
1413 | ret->phase = SP_COPYING; | 1402 | ret->phase = SP_COPYING; |
1414 | if (NULL != username) | 1403 | if (NULL != username) |
1415 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome); | 1404 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome); |
1416 | else | 1405 | else |
1417 | GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); | 1406 | GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); |
1418 | GNUNET_free(baseservicehome); | 1407 | GNUNET_free (baseservicehome); |
1419 | if (ret->ssh_port_str == NULL) | 1408 | if (ret->ssh_port_str == NULL) |
1420 | { | 1409 | { |
1421 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", | 1410 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", |
1422 | #if !DEBUG_TESTING | 1411 | #if !DEBUG_TESTING |
1423 | "-q", | 1412 | "-q", |
1424 | #endif | 1413 | #endif |
1425 | servicehome, arg, NULL); | 1414 | servicehome, arg, NULL); |
1426 | #if DEBUG_TESTING | 1415 | #if DEBUG_TESTING |
1427 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1428 | "copying directory with command scp -r %s %s\n", | 1417 | "copying directory with command scp -r %s %s\n", |
1429 | servicehome, | 1418 | servicehome, arg); |
1430 | arg); | ||
1431 | #endif | ||
1432 | } | ||
1433 | else | ||
1434 | { | ||
1435 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", | ||
1436 | "scp", "-r", "-P", ret->ssh_port_str, | ||
1437 | #if !DEBUG_TESTING | ||
1438 | "-q", | ||
1439 | #endif | ||
1440 | servicehome, arg, NULL); | ||
1441 | } | ||
1442 | GNUNET_free (arg); | ||
1443 | if (NULL == ret->proc) | ||
1444 | { | ||
1445 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1446 | _ | ||
1447 | ("Could not start `%s' process to copy configuration directory.\n"), | ||
1448 | "scp"); | ||
1449 | if (0 != UNLINK (ret->cfgfile)) | ||
1450 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1451 | "unlink", ret->cfgfile); | ||
1452 | GNUNET_CONFIGURATION_destroy (ret->cfg); | ||
1453 | GNUNET_free_non_null (ret->hostname); | ||
1454 | GNUNET_free_non_null (ret->username); | ||
1455 | GNUNET_free (ret->cfgfile); | ||
1456 | GNUNET_free (ret); | ||
1457 | if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile))) | ||
1458 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1459 | "unlink", hostkeyfile); | ||
1460 | GNUNET_free_non_null(hostkeyfile); | ||
1461 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); | ||
1462 | GNUNET_free(servicehome); | ||
1463 | return NULL; | ||
1464 | } | ||
1465 | |||
1466 | ret->task | ||
1467 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
1468 | &start_fsm, ret); | ||
1469 | GNUNET_free_non_null(hostkeyfile); | ||
1470 | GNUNET_free(servicehome); | ||
1471 | return ret; | ||
1472 | } | ||
1473 | #if DEBUG_TESTING | ||
1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1475 | "No need to copy configuration file since we are running locally.\n"); | ||
1476 | #endif | 1419 | #endif |
1477 | ret->phase = SP_COPIED; | 1420 | } |
1478 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | 1421 | else |
1479 | ret, | 1422 | { |
1480 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1423 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", |
1424 | "scp", "-r", "-P", | ||
1425 | ret->ssh_port_str, | ||
1426 | #if !DEBUG_TESTING | ||
1427 | "-q", | ||
1428 | #endif | ||
1429 | servicehome, arg, NULL); | ||
1430 | } | ||
1431 | GNUNET_free (arg); | ||
1432 | if (NULL == ret->proc) | ||
1433 | { | ||
1434 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1435 | _ | ||
1436 | ("Could not start `%s' process to copy configuration directory.\n"), | ||
1437 | "scp"); | ||
1438 | if (0 != UNLINK (ret->cfgfile)) | ||
1439 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1440 | "unlink", ret->cfgfile); | ||
1441 | GNUNET_CONFIGURATION_destroy (ret->cfg); | ||
1442 | GNUNET_free_non_null (ret->hostname); | ||
1443 | GNUNET_free_non_null (ret->username); | ||
1444 | GNUNET_free (ret->cfgfile); | ||
1445 | GNUNET_free (ret); | ||
1446 | if ((hostkey != NULL) && (0 != UNLINK (hostkeyfile))) | ||
1447 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1448 | "unlink", hostkeyfile); | ||
1449 | GNUNET_free_non_null (hostkeyfile); | ||
1450 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); | ||
1451 | GNUNET_free (servicehome); | ||
1452 | return NULL; | ||
1453 | } | ||
1454 | |||
1455 | ret->task | ||
1456 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
1457 | &start_fsm, ret); | ||
1458 | GNUNET_free_non_null (hostkeyfile); | ||
1459 | GNUNET_free (servicehome); | ||
1460 | return ret; | ||
1481 | } | 1461 | } |
1482 | GNUNET_free_non_null(hostkeyfile); | 1462 | #if DEBUG_TESTING |
1483 | GNUNET_free(servicehome); | 1463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1464 | "No need to copy configuration file since we are running locally.\n"); | ||
1465 | #endif | ||
1466 | ret->phase = SP_COPIED; | ||
1467 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | ||
1468 | ret, | ||
1469 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
1470 | } | ||
1471 | GNUNET_free_non_null (hostkeyfile); | ||
1472 | GNUNET_free (servicehome); | ||
1484 | return ret; | 1473 | return ret; |
1485 | } | 1474 | } |
1486 | 1475 | ||
@@ -1502,31 +1491,31 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
1502 | 1491 | ||
1503 | del_arg = NULL; | 1492 | del_arg = NULL; |
1504 | if (NULL != d->cb) | 1493 | if (NULL != d->cb) |
1505 | { | 1494 | { |
1506 | d->dead = GNUNET_YES; | 1495 | d->dead = GNUNET_YES; |
1507 | return; | 1496 | return; |
1508 | } | 1497 | } |
1509 | 1498 | ||
1510 | d->cb = cb; | 1499 | d->cb = cb; |
1511 | d->cb_cls = cb_cls; | 1500 | d->cb_cls = cb_cls; |
1512 | 1501 | ||
1513 | if (d->phase == SP_CONFIG_UPDATE) | 1502 | if (d->phase == SP_CONFIG_UPDATE) |
1514 | { | 1503 | { |
1515 | GNUNET_SCHEDULER_cancel (d->task); | 1504 | GNUNET_SCHEDULER_cancel (d->task); |
1516 | d->phase = SP_START_DONE; | 1505 | d->phase = SP_START_DONE; |
1517 | } | 1506 | } |
1518 | if (d->server != NULL) | 1507 | if (d->server != NULL) |
1519 | { | 1508 | { |
1520 | GNUNET_CORE_disconnect (d->server); | 1509 | GNUNET_CORE_disconnect (d->server); |
1521 | d->server = NULL; | 1510 | d->server = NULL; |
1522 | } | 1511 | } |
1523 | 1512 | ||
1524 | if (d->th != NULL) | 1513 | if (d->th != NULL) |
1525 | { | 1514 | { |
1526 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | 1515 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
1527 | GNUNET_TRANSPORT_disconnect (d->th); | 1516 | GNUNET_TRANSPORT_disconnect (d->th); |
1528 | d->th = NULL; | 1517 | d->th = NULL; |
1529 | } | 1518 | } |
1530 | /* state clean up and notifications */ | 1519 | /* state clean up and notifications */ |
1531 | GNUNET_free_non_null (d->hello); | 1520 | GNUNET_free_non_null (d->hello); |
1532 | 1521 | ||
@@ -1539,50 +1528,48 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
1539 | 1528 | ||
1540 | /* Check if this is a local or remote process */ | 1529 | /* Check if this is a local or remote process */ |
1541 | if (NULL != d->hostname) | 1530 | if (NULL != d->hostname) |
1542 | { | 1531 | { |
1543 | #if DEBUG_TESTING | 1532 | #if DEBUG_TESTING |
1544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1545 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | 1534 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1546 | d->cfgfile, d->hostname); | 1535 | d->cfgfile, d->hostname); |
1547 | #endif | 1536 | #endif |
1548 | 1537 | ||
1549 | if (d->username != NULL) | 1538 | if (d->username != NULL) |
1550 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1539 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1551 | else | 1540 | else |
1552 | arg = GNUNET_strdup (d->hostname); | 1541 | arg = GNUNET_strdup (d->hostname); |
1553 | 1542 | ||
1554 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1543 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1555 | #if !DEBUG_TESTING | 1544 | #if !DEBUG_TESTING |
1556 | "-q", | 1545 | "-q", |
1557 | #endif | 1546 | #endif |
1558 | arg, "gnunet-arm", | 1547 | arg, "gnunet-arm", |
1559 | #if DEBUG_TESTING | 1548 | #if DEBUG_TESTING |
1560 | "-L", "DEBUG", | 1549 | "-L", "DEBUG", |
1561 | #endif | 1550 | #endif |
1562 | "-c", d->cfgfile, "-e", "-r", NULL); | 1551 | "-c", d->cfgfile, "-e", "-r", NULL); |
1563 | /* Use -r to restart arm and all services */ | 1552 | /* Use -r to restart arm and all services */ |
1564 | 1553 | ||
1565 | GNUNET_free (arg); | 1554 | GNUNET_free (arg); |
1566 | } | 1555 | } |
1567 | else | 1556 | else |
1568 | { | 1557 | { |
1569 | #if DEBUG_TESTING | 1558 | #if DEBUG_TESTING |
1570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1571 | "Stopping gnunet-arm with config `%s' locally.\n", | 1560 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1572 | d->cfgfile); | ||
1573 | #endif | 1561 | #endif |
1574 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1562 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1575 | "gnunet-arm", | ||
1576 | #if DEBUG_TESTING | 1563 | #if DEBUG_TESTING |
1577 | "-L", "DEBUG", | 1564 | "-L", "DEBUG", |
1578 | #endif | 1565 | #endif |
1579 | "-c", d->cfgfile, "-e", "-r", NULL); | 1566 | "-c", d->cfgfile, "-e", "-r", NULL); |
1580 | } | 1567 | } |
1581 | 1568 | ||
1582 | GNUNET_free_non_null (del_arg); | 1569 | GNUNET_free_non_null (del_arg); |
1583 | d->task | 1570 | d->task |
1584 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 1571 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
1585 | &start_fsm, d); | 1572 | &start_fsm, d); |
1586 | 1573 | ||
1587 | } | 1574 | } |
1588 | 1575 | ||
@@ -1604,78 +1591,80 @@ void | |||
1604 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, | 1591 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, |
1605 | char *service, | 1592 | char *service, |
1606 | struct GNUNET_TIME_Relative timeout, | 1593 | struct GNUNET_TIME_Relative timeout, |
1607 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 1594 | GNUNET_TESTING_NotifyCompletion cb, |
1595 | void *cb_cls) | ||
1608 | { | 1596 | { |
1609 | char *arg; | 1597 | char *arg; |
1598 | |||
1610 | d->dead_cb = cb; | 1599 | d->dead_cb = cb; |
1611 | d->dead_cb_cls = cb_cls; | 1600 | d->dead_cb_cls = cb_cls; |
1612 | 1601 | ||
1613 | GNUNET_assert(d->running == GNUNET_YES); | 1602 | GNUNET_assert (d->running == GNUNET_YES); |
1614 | 1603 | ||
1615 | if (d->phase == SP_CONFIG_UPDATE) | 1604 | if (d->phase == SP_CONFIG_UPDATE) |
1616 | { | 1605 | { |
1617 | GNUNET_SCHEDULER_cancel (d->task); | 1606 | GNUNET_SCHEDULER_cancel (d->task); |
1618 | d->phase = SP_START_DONE; | 1607 | d->phase = SP_START_DONE; |
1619 | } | 1608 | } |
1620 | 1609 | ||
1621 | #if DEBUG_TESTING | 1610 | #if DEBUG_TESTING |
1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1623 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); | 1612 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); |
1624 | #endif | 1613 | #endif |
1625 | if (d->churned_services != NULL) | 1614 | if (d->churned_services != NULL) |
1626 | { | 1615 | { |
1627 | d->dead_cb(d->dead_cb_cls, "A service has already been turned off!!"); | 1616 | d->dead_cb (d->dead_cb_cls, "A service has already been turned off!!"); |
1628 | return; | 1617 | return; |
1629 | } | 1618 | } |
1630 | d->phase = SP_SERVICE_SHUTDOWN_START; | 1619 | d->phase = SP_SERVICE_SHUTDOWN_START; |
1631 | d->churned_services = GNUNET_strdup(service); | 1620 | d->churned_services = GNUNET_strdup (service); |
1632 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1621 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1633 | /* Check if this is a local or remote process */ | 1622 | /* Check if this is a local or remote process */ |
1634 | if (NULL != d->hostname) | 1623 | if (NULL != d->hostname) |
1635 | { | 1624 | { |
1636 | #if DEBUG_TESTING | 1625 | #if DEBUG_TESTING |
1637 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1638 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | 1627 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1639 | d->cfgfile, d->hostname); | 1628 | d->cfgfile, d->hostname); |
1640 | #endif | 1629 | #endif |
1641 | 1630 | ||
1642 | if (d->username != NULL) | 1631 | if (d->username != NULL) |
1643 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1632 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1644 | else | 1633 | else |
1645 | arg = GNUNET_strdup (d->hostname); | 1634 | arg = GNUNET_strdup (d->hostname); |
1646 | 1635 | ||
1647 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1636 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1648 | #if !DEBUG_TESTING | 1637 | #if !DEBUG_TESTING |
1649 | "-q", | 1638 | "-q", |
1650 | #endif | 1639 | #endif |
1651 | arg, "gnunet-arm", | 1640 | arg, "gnunet-arm", |
1652 | #if DEBUG_TESTING | 1641 | #if DEBUG_TESTING |
1653 | "-L", "DEBUG", | 1642 | "-L", "DEBUG", |
1654 | #endif | 1643 | #endif |
1655 | "-c", d->cfgfile, "-k", service, "-q", | 1644 | "-c", d->cfgfile, "-k", service, "-q", |
1656 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1645 | "-T", |
1657 | NULL); | 1646 | GNUNET_TIME_relative_to_string (timeout), |
1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1647 | NULL); |
1659 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n", | 1648 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1660 | arg, "gnunet-arm", d->cfgfile, service); | 1649 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n", |
1661 | GNUNET_free (arg); | 1650 | arg, "gnunet-arm", d->cfgfile, service); |
1662 | } | 1651 | GNUNET_free (arg); |
1652 | } | ||
1663 | else | 1653 | else |
1664 | { | 1654 | { |
1665 | #if DEBUG_TESTING | 1655 | #if DEBUG_TESTING |
1666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1667 | "Stopping gnunet-arm with config `%s' locally.\n", | 1657 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1668 | d->cfgfile); | ||
1669 | #endif | 1658 | #endif |
1670 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1659 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1671 | "gnunet-arm", | ||
1672 | #if DEBUG_TESTING | 1660 | #if DEBUG_TESTING |
1673 | "-L", "DEBUG", | 1661 | "-L", "DEBUG", |
1674 | #endif | 1662 | #endif |
1675 | "-c", d->cfgfile, "-k", service, "-q", | 1663 | "-c", d->cfgfile, "-k", service, "-q", |
1676 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1664 | "-T", |
1677 | NULL); | 1665 | GNUNET_TIME_relative_to_string (timeout), |
1678 | } | 1666 | NULL); |
1667 | } | ||
1679 | 1668 | ||
1680 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1669 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1681 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | 1670 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
@@ -1702,51 +1691,52 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1702 | { | 1691 | { |
1703 | char *arg; | 1692 | char *arg; |
1704 | char *del_arg; | 1693 | char *del_arg; |
1694 | |||
1705 | d->dead_cb = cb; | 1695 | d->dead_cb = cb; |
1706 | d->dead_cb_cls = cb_cls; | 1696 | d->dead_cb_cls = cb_cls; |
1707 | 1697 | ||
1708 | if (NULL != d->cb) | 1698 | if (NULL != d->cb) |
1709 | { | 1699 | { |
1710 | #if DEBUG_TESTING | 1700 | #if DEBUG_TESTING |
1711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1712 | _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); | 1702 | _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); |
1713 | #endif | 1703 | #endif |
1714 | d->dead = GNUNET_YES; | 1704 | d->dead = GNUNET_YES; |
1715 | return; | 1705 | return; |
1716 | } | 1706 | } |
1717 | 1707 | ||
1718 | if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */ | 1708 | if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */ |
1719 | { | 1709 | { |
1720 | /* Free what was left from churning! */ | 1710 | /* Free what was left from churning! */ |
1721 | GNUNET_assert (d->cfg != NULL); | 1711 | GNUNET_assert (d->cfg != NULL); |
1722 | GNUNET_CONFIGURATION_destroy (d->cfg); | 1712 | GNUNET_CONFIGURATION_destroy (d->cfg); |
1723 | if (delete_files == GNUNET_YES) | 1713 | if (delete_files == GNUNET_YES) |
1724 | { | 1714 | { |
1725 | if (0 != UNLINK (d->cfgfile)) | 1715 | if (0 != UNLINK (d->cfgfile)) |
1726 | { | 1716 | { |
1727 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink"); | 1717 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink"); |
1728 | } | 1718 | } |
1729 | } | 1719 | } |
1730 | GNUNET_free (d->cfgfile); | 1720 | GNUNET_free (d->cfgfile); |
1731 | GNUNET_free_non_null (d->hostname); | 1721 | GNUNET_free_non_null (d->hostname); |
1732 | GNUNET_free_non_null (d->username); | 1722 | GNUNET_free_non_null (d->username); |
1733 | if (NULL != d->dead_cb) | 1723 | if (NULL != d->dead_cb) |
1734 | d->dead_cb (d->dead_cb_cls, NULL); | 1724 | d->dead_cb (d->dead_cb_cls, NULL); |
1735 | GNUNET_free (d); | 1725 | GNUNET_free (d); |
1736 | return; | 1726 | return; |
1737 | } | 1727 | } |
1738 | 1728 | ||
1739 | del_arg = NULL; | 1729 | del_arg = NULL; |
1740 | if (delete_files == GNUNET_YES) | 1730 | if (delete_files == GNUNET_YES) |
1741 | { | 1731 | { |
1742 | GNUNET_asprintf (&del_arg, "-d"); | 1732 | GNUNET_asprintf (&del_arg, "-d"); |
1743 | } | 1733 | } |
1744 | 1734 | ||
1745 | if (d->phase == SP_CONFIG_UPDATE) | 1735 | if (d->phase == SP_CONFIG_UPDATE) |
1746 | { | 1736 | { |
1747 | GNUNET_SCHEDULER_cancel (d->task); | 1737 | GNUNET_SCHEDULER_cancel (d->task); |
1748 | d->phase = SP_START_DONE; | 1738 | d->phase = SP_START_DONE; |
1749 | } | 1739 | } |
1750 | /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop? | 1740 | /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop? |
1751 | if (d->server != NULL) | 1741 | if (d->server != NULL) |
1752 | { | 1742 | { |
@@ -1764,58 +1754,58 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1764 | if (allow_restart == GNUNET_YES) | 1754 | if (allow_restart == GNUNET_YES) |
1765 | d->churn = GNUNET_YES; | 1755 | d->churn = GNUNET_YES; |
1766 | if (d->th != NULL) | 1756 | if (d->th != NULL) |
1767 | { | 1757 | { |
1768 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); | 1758 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
1769 | GNUNET_TRANSPORT_disconnect (d->th); | 1759 | GNUNET_TRANSPORT_disconnect (d->th); |
1770 | d->th = NULL; | 1760 | d->th = NULL; |
1771 | } | 1761 | } |
1772 | /* Check if this is a local or remote process */ | 1762 | /* Check if this is a local or remote process */ |
1773 | if (NULL != d->hostname) | 1763 | if (NULL != d->hostname) |
1774 | { | 1764 | { |
1775 | #if DEBUG_TESTING | 1765 | #if DEBUG_TESTING |
1776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1777 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | 1767 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1778 | d->cfgfile, d->hostname); | 1768 | d->cfgfile, d->hostname); |
1779 | #endif | 1769 | #endif |
1780 | 1770 | ||
1781 | if (d->username != NULL) | 1771 | if (d->username != NULL) |
1782 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | 1772 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); |
1783 | else | 1773 | else |
1784 | arg = GNUNET_strdup (d->hostname); | 1774 | arg = GNUNET_strdup (d->hostname); |
1785 | 1775 | ||
1786 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1776 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1787 | #if !DEBUG_TESTING | 1777 | #if !DEBUG_TESTING |
1788 | "-q", | 1778 | "-q", |
1789 | #endif | 1779 | #endif |
1790 | arg, "gnunet-arm", | 1780 | arg, "gnunet-arm", |
1791 | #if DEBUG_TESTING | 1781 | #if DEBUG_TESTING |
1792 | "-L", "DEBUG", | 1782 | "-L", "DEBUG", |
1793 | #endif | 1783 | #endif |
1794 | "-c", d->cfgfile, "-e", "-q", | 1784 | "-c", d->cfgfile, "-e", "-q", |
1795 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1785 | "-T", |
1796 | del_arg, NULL); | 1786 | GNUNET_TIME_relative_to_string (timeout), |
1797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1787 | del_arg, NULL); |
1798 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n", | 1788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1799 | arg, "gnunet-arm", d->cfgfile, del_arg); | 1789 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n", |
1800 | /* Use -e to end arm, and -d to remove temp files */ | 1790 | arg, "gnunet-arm", d->cfgfile, del_arg); |
1801 | GNUNET_free (arg); | 1791 | /* Use -e to end arm, and -d to remove temp files */ |
1802 | } | 1792 | GNUNET_free (arg); |
1793 | } | ||
1803 | else | 1794 | else |
1804 | { | 1795 | { |
1805 | #if DEBUG_TESTING | 1796 | #if DEBUG_TESTING |
1806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1807 | "Stopping gnunet-arm with config `%s' locally.\n", | 1798 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); |
1808 | d->cfgfile); | ||
1809 | #endif | 1799 | #endif |
1810 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1800 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", |
1811 | "gnunet-arm", | ||
1812 | #if DEBUG_TESTING | 1801 | #if DEBUG_TESTING |
1813 | "-L", "DEBUG", | 1802 | "-L", "DEBUG", |
1814 | #endif | 1803 | #endif |
1815 | "-c", d->cfgfile, "-e", "-q", | 1804 | "-c", d->cfgfile, "-e", "-q", |
1816 | "-T", GNUNET_TIME_relative_to_string(timeout), | 1805 | "-T", |
1817 | del_arg, NULL); | 1806 | GNUNET_TIME_relative_to_string (timeout), |
1818 | } | 1807 | del_arg, NULL); |
1808 | } | ||
1819 | 1809 | ||
1820 | GNUNET_free_non_null (del_arg); | 1810 | GNUNET_free_non_null (del_arg); |
1821 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1811 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -1840,30 +1830,30 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | |||
1840 | char *arg; | 1830 | char *arg; |
1841 | 1831 | ||
1842 | if (d->phase != SP_START_DONE) | 1832 | if (d->phase != SP_START_DONE) |
1843 | { | 1833 | { |
1844 | if (NULL != cb) | 1834 | if (NULL != cb) |
1845 | cb (cb_cls, | 1835 | cb (cb_cls, |
1846 | _ | 1836 | _ |
1847 | ("Peer not yet running, can not change configuration at this point.")); | 1837 | ("Peer not yet running, can not change configuration at this point.")); |
1848 | return; | 1838 | return; |
1849 | } | 1839 | } |
1850 | 1840 | ||
1851 | /* 1) write configuration to temporary file */ | 1841 | /* 1) write configuration to temporary file */ |
1852 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile)) | 1842 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile)) |
1853 | { | 1843 | { |
1854 | if (NULL != cb) | 1844 | if (NULL != cb) |
1855 | cb (cb_cls, _("Failed to write new configuration to disk.")); | 1845 | cb (cb_cls, _("Failed to write new configuration to disk.")); |
1856 | return; | 1846 | return; |
1857 | } | 1847 | } |
1858 | 1848 | ||
1859 | /* 2) copy file to remote host (if necessary) */ | 1849 | /* 2) copy file to remote host (if necessary) */ |
1860 | if (NULL == d->hostname) | 1850 | if (NULL == d->hostname) |
1861 | { | 1851 | { |
1862 | /* signal success */ | 1852 | /* signal success */ |
1863 | if (NULL != cb) | 1853 | if (NULL != cb) |
1864 | cb (cb_cls, NULL); | 1854 | cb (cb_cls, NULL); |
1865 | return; | 1855 | return; |
1866 | } | 1856 | } |
1867 | #if DEBUG_TESTING | 1857 | #if DEBUG_TESTING |
1868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1869 | "Copying updated configuration file to remote host `%s'.\n", | 1859 | "Copying updated configuration file to remote host `%s'.\n", |
@@ -1881,21 +1871,21 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | |||
1881 | d->cfgfile, arg, NULL); | 1871 | d->cfgfile, arg, NULL); |
1882 | GNUNET_free (arg); | 1872 | GNUNET_free (arg); |
1883 | if (NULL == d->proc) | 1873 | if (NULL == d->proc) |
1884 | { | 1874 | { |
1885 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1875 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1886 | _ | 1876 | _ |
1887 | ("Could not start `%s' process to copy configuration file.\n"), | 1877 | ("Could not start `%s' process to copy configuration file.\n"), |
1888 | "scp"); | 1878 | "scp"); |
1889 | if (NULL != cb) | 1879 | if (NULL != cb) |
1890 | cb (cb_cls, _("Failed to copy new configuration to remote machine.")); | 1880 | cb (cb_cls, _("Failed to copy new configuration to remote machine.")); |
1891 | d->phase = SP_START_DONE; | 1881 | d->phase = SP_START_DONE; |
1892 | return; | 1882 | return; |
1893 | } | 1883 | } |
1894 | d->update_cb = cb; | 1884 | d->update_cb = cb; |
1895 | d->update_cb_cls = cb_cls; | 1885 | d->update_cb_cls = cb_cls; |
1896 | d->task | 1886 | d->task |
1897 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 1887 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
1898 | &start_fsm, d); | 1888 | &start_fsm, d); |
1899 | } | 1889 | } |
1900 | 1890 | ||
1901 | 1891 | ||
@@ -2004,39 +1994,39 @@ reattempt_daemons_connect (void *cls, | |||
2004 | * @param tc reason tells us if we succeeded or failed | 1994 | * @param tc reason tells us if we succeeded or failed |
2005 | */ | 1995 | */ |
2006 | static void | 1996 | static void |
2007 | notify_connect_result (void *cls, | 1997 | notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2008 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2009 | { | 1998 | { |
2010 | struct ConnectContext *ctx = cls; | 1999 | struct ConnectContext *ctx = cls; |
2000 | |||
2011 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 2001 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
2012 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | 2002 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
2013 | { | 2003 | { |
2014 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); | 2004 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); |
2015 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 2005 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2016 | } | 2006 | } |
2017 | 2007 | ||
2018 | if (ctx->connect_request_handle != NULL) | 2008 | if (ctx->connect_request_handle != NULL) |
2019 | { | 2009 | { |
2020 | GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle); | 2010 | GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle); |
2021 | ctx->connect_request_handle = NULL; | 2011 | ctx->connect_request_handle = NULL; |
2022 | } | 2012 | } |
2023 | 2013 | ||
2024 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2014 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2025 | { | 2015 | { |
2026 | if (ctx->d1th != NULL) | 2016 | if (ctx->d1th != NULL) |
2027 | GNUNET_TRANSPORT_disconnect (ctx->d1th); | 2017 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
2028 | ctx->d1th = NULL; | 2018 | ctx->d1th = NULL; |
2029 | if (ctx->d1core != NULL) | 2019 | if (ctx->d1core != NULL) |
2030 | GNUNET_CORE_disconnect (ctx->d1core); | 2020 | GNUNET_CORE_disconnect (ctx->d1core); |
2031 | #if CONNECT_CORE2 | 2021 | #if CONNECT_CORE2 |
2032 | if (ctx->d2core != NULL) | 2022 | if (ctx->d2core != NULL) |
2033 | GNUNET_CORE_disconnect (ctx->d2core); | 2023 | GNUNET_CORE_disconnect (ctx->d2core); |
2034 | ctx->d2core = NULL; | 2024 | ctx->d2core = NULL; |
2035 | #endif | 2025 | #endif |
2036 | ctx->d1core = NULL; | 2026 | ctx->d1core = NULL; |
2037 | GNUNET_free (ctx); | 2027 | GNUNET_free (ctx); |
2038 | return; | 2028 | return; |
2039 | } | 2029 | } |
2040 | 2030 | ||
2041 | if (ctx->d1th != NULL) | 2031 | if (ctx->d1th != NULL) |
2042 | GNUNET_TRANSPORT_disconnect (ctx->d1th); | 2032 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
@@ -2046,38 +2036,37 @@ notify_connect_result (void *cls, | |||
2046 | ctx->d1core = NULL; | 2036 | ctx->d1core = NULL; |
2047 | 2037 | ||
2048 | if (ctx->connected == GNUNET_YES) | 2038 | if (ctx->connected == GNUNET_YES) |
2039 | { | ||
2040 | if (ctx->cb != NULL) | ||
2049 | { | 2041 | { |
2050 | if (ctx->cb != NULL) | 2042 | ctx->cb (ctx->cb_cls, |
2051 | { | 2043 | &ctx->d1->id, |
2052 | ctx->cb (ctx->cb_cls, | 2044 | &ctx->d2->id, |
2053 | &ctx->d1->id, | 2045 | ctx->distance, |
2054 | &ctx->d2->id, | 2046 | ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); |
2055 | ctx->distance, | ||
2056 | ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); | ||
2057 | } | ||
2058 | } | 2047 | } |
2048 | } | ||
2059 | else if (ctx->connect_attempts > 0) | 2049 | else if (ctx->connect_attempts > 0) |
2060 | { | 2050 | { |
2061 | ctx->d1core_ready = GNUNET_NO; | 2051 | ctx->d1core_ready = GNUNET_NO; |
2062 | #if CONNECT_CORE2 | 2052 | #if CONNECT_CORE2 |
2063 | if (ctx->d2core != NULL) | 2053 | if (ctx->d2core != NULL) |
2064 | { | 2054 | { |
2065 | GNUNET_CORE_disconnect (ctx->d2core); | 2055 | GNUNET_CORE_disconnect (ctx->d2core); |
2066 | ctx->d2core = NULL; | 2056 | ctx->d2core = NULL; |
2067 | } | ||
2068 | #endif | ||
2069 | GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); | ||
2070 | return; | ||
2071 | } | 2057 | } |
2058 | #endif | ||
2059 | GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); | ||
2060 | return; | ||
2061 | } | ||
2072 | else | 2062 | else |
2063 | { | ||
2064 | if (ctx->cb != NULL) | ||
2073 | { | 2065 | { |
2074 | if (ctx->cb != NULL) | 2066 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2075 | { | 2067 | ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect")); |
2076 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | ||
2077 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2078 | _("Peers failed to connect")); | ||
2079 | } | ||
2080 | } | 2068 | } |
2069 | } | ||
2081 | 2070 | ||
2082 | GNUNET_free (ctx); | 2071 | GNUNET_free (ctx); |
2083 | } | 2072 | } |
@@ -2100,24 +2089,23 @@ connect_notify (void *cls, | |||
2100 | 2089 | ||
2101 | #if DEBUG_TESTING | 2090 | #if DEBUG_TESTING |
2102 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2091 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2103 | "Connected peer %s to peer %s\n", | 2092 | "Connected peer %s to peer %s\n", |
2104 | ctx->d1->shortname, GNUNET_i2s(peer)); | 2093 | ctx->d1->shortname, GNUNET_i2s (peer)); |
2105 | #endif | 2094 | #endif |
2106 | 2095 | ||
2107 | if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 2096 | if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
2108 | { | 2097 | { |
2109 | 2098 | ||
2110 | ctx->connected = GNUNET_YES; | 2099 | ctx->connected = GNUNET_YES; |
2111 | ctx->distance = 0; /* FIXME: distance */ | 2100 | ctx->distance = 0; /* FIXME: distance */ |
2112 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | 2101 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
2113 | { | 2102 | { |
2114 | GNUNET_SCHEDULER_cancel(ctx->hello_send_task); | 2103 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); |
2115 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 2104 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2116 | } | ||
2117 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | ||
2118 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | ||
2119 | ctx); | ||
2120 | } | 2105 | } |
2106 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | ||
2107 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); | ||
2108 | } | ||
2121 | } | 2109 | } |
2122 | 2110 | ||
2123 | #if CONNECT_CORE2 | 2111 | #if CONNECT_CORE2 |
@@ -2137,13 +2125,12 @@ connect_notify_core2 (void *cls, | |||
2137 | struct ConnectContext *ctx = cls; | 2125 | struct ConnectContext *ctx = cls; |
2138 | 2126 | ||
2139 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) | 2127 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) |
2140 | { | 2128 | { |
2141 | ctx->connected = GNUNET_YES; | 2129 | ctx->connected = GNUNET_YES; |
2142 | ctx->distance = 0; /* FIXME: distance */ | 2130 | ctx->distance = 0; /* FIXME: distance */ |
2143 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | 2131 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); |
2144 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | 2132 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); |
2145 | ctx); | 2133 | } |
2146 | } | ||
2147 | 2134 | ||
2148 | } | 2135 | } |
2149 | #endif | 2136 | #endif |
@@ -2155,8 +2142,7 @@ connect_notify_core2 (void *cls, | |||
2155 | * @param success was the request successful? | 2142 | * @param success was the request successful? |
2156 | */ | 2143 | */ |
2157 | void | 2144 | void |
2158 | core_connect_request_cont (void *cls, | 2145 | core_connect_request_cont (void *cls, int success) |
2159 | int success) | ||
2160 | { | 2146 | { |
2161 | struct ConnectContext *ctx = cls; | 2147 | struct ConnectContext *ctx = cls; |
2162 | 2148 | ||
@@ -2168,37 +2154,38 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2168 | { | 2154 | { |
2169 | struct ConnectContext *ctx = cls; | 2155 | struct ConnectContext *ctx = cls; |
2170 | struct GNUNET_MessageHeader *hello; | 2156 | struct GNUNET_MessageHeader *hello; |
2157 | |||
2171 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 2158 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2172 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2159 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2173 | return; | 2160 | return; |
2174 | if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL) | 2161 | if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL) |
2175 | && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)) | 2162 | && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)) |
2176 | && (ctx->d1->phase == SP_START_DONE) | 2163 | && (ctx->d1->phase == SP_START_DONE) && (ctx->d2->phase == SP_START_DONE)) |
2177 | && (ctx->d2->phase == SP_START_DONE)) | 2164 | { |
2178 | { | 2165 | hello = GNUNET_HELLO_get_header (ctx->d2->hello); |
2179 | hello = GNUNET_HELLO_get_header (ctx->d2->hello); | 2166 | GNUNET_assert (hello != NULL); |
2180 | GNUNET_assert (hello != NULL); | ||
2181 | #if DEBUG_TESTING | 2167 | #if DEBUG_TESTING |
2182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n", ctx->d2->shortname, ctx->d1->shortname); | 2168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n", |
2169 | ctx->d2->shortname, ctx->d1->shortname); | ||
2183 | #endif | 2170 | #endif |
2184 | GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL); | 2171 | GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL); |
2185 | GNUNET_assert (ctx->d1core != NULL); | 2172 | GNUNET_assert (ctx->d1core != NULL); |
2186 | ctx->connect_request_handle = | 2173 | ctx->connect_request_handle = |
2187 | GNUNET_CORE_peer_request_connect (ctx->d1core, | 2174 | GNUNET_CORE_peer_request_connect (ctx->d1core, |
2188 | &ctx->d2->id, | 2175 | &ctx->d2->id, |
2189 | &core_connect_request_cont, ctx); | 2176 | &core_connect_request_cont, ctx); |
2190 | 2177 | ||
2191 | #if DEBUG_TESTING | 2178 | #if DEBUG_TESTING |
2192 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2179 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2193 | "Sending connect request to CORE of %s for peer %s\n", | 2180 | "Sending connect request to CORE of %s for peer %s\n", |
2194 | GNUNET_i2s (&ctx->d1->id), | 2181 | GNUNET_i2s (&ctx->d1->id), |
2195 | GNUNET_h2s (&ctx->d2->id.hashPubKey)); | 2182 | GNUNET_h2s (&ctx->d2->id.hashPubKey)); |
2196 | #endif | 2183 | #endif |
2197 | ctx->timeout_hello = | 2184 | ctx->timeout_hello = |
2198 | GNUNET_TIME_relative_add (ctx->timeout_hello, | 2185 | GNUNET_TIME_relative_add (ctx->timeout_hello, |
2199 | GNUNET_TIME_relative_multiply | 2186 | GNUNET_TIME_relative_multiply |
2200 | (GNUNET_TIME_UNIT_MILLISECONDS, 500)); | 2187 | (GNUNET_TIME_UNIT_MILLISECONDS, 500)); |
2201 | } | 2188 | } |
2202 | ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, | 2189 | ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, |
2203 | &send_hello, ctx); | 2190 | &send_hello, ctx); |
2204 | } | 2191 | } |
@@ -2213,30 +2200,29 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2213 | */ | 2200 | */ |
2214 | void | 2201 | void |
2215 | core_init_notify (void *cls, | 2202 | core_init_notify (void *cls, |
2216 | struct GNUNET_CORE_Handle * server, | 2203 | struct GNUNET_CORE_Handle *server, |
2217 | const struct GNUNET_PeerIdentity * | 2204 | const struct GNUNET_PeerIdentity *my_identity, |
2218 | my_identity, | ||
2219 | const struct | 2205 | const struct |
2220 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | 2206 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
2221 | publicKey) | ||
2222 | { | 2207 | { |
2223 | struct ConnectContext *connect_ctx = cls; | 2208 | struct ConnectContext *connect_ctx = cls; |
2209 | |||
2224 | connect_ctx->d1core_ready = GNUNET_YES; | 2210 | connect_ctx->d1core_ready = GNUNET_YES; |
2225 | 2211 | ||
2226 | if (connect_ctx->send_hello == GNUNET_NO) | 2212 | if (connect_ctx->send_hello == GNUNET_NO) |
2227 | { | 2213 | { |
2228 | connect_ctx->connect_request_handle = | 2214 | connect_ctx->connect_request_handle = |
2229 | GNUNET_CORE_peer_request_connect (connect_ctx->d1core, | 2215 | GNUNET_CORE_peer_request_connect (connect_ctx->d1core, |
2230 | &connect_ctx->d2->id, | 2216 | &connect_ctx->d2->id, |
2231 | &core_connect_request_cont, connect_ctx); | 2217 | &core_connect_request_cont, |
2232 | GNUNET_assert(connect_ctx->connect_request_handle != NULL); | 2218 | connect_ctx); |
2219 | GNUNET_assert (connect_ctx->connect_request_handle != NULL); | ||
2233 | #if DEBUG_TESTING | 2220 | #if DEBUG_TESTING |
2234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2235 | "Sending connect request to CORE of %s for peer %s\n", | 2222 | "Sending connect request to CORE of %s for peer %s\n", |
2236 | connect_ctx->d1->shortname, | 2223 | connect_ctx->d1->shortname, connect_ctx->d2->shortname); |
2237 | connect_ctx->d2->shortname); | ||
2238 | #endif | 2224 | #endif |
2239 | } | 2225 | } |
2240 | 2226 | ||
2241 | } | 2227 | } |
2242 | 2228 | ||
@@ -2246,11 +2232,12 @@ reattempt_daemons_connect (void *cls, | |||
2246 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2232 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2247 | { | 2233 | { |
2248 | struct ConnectContext *ctx = cls; | 2234 | struct ConnectContext *ctx = cls; |
2249 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2235 | |
2250 | { | 2236 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2251 | GNUNET_free(ctx); | 2237 | { |
2252 | return; | 2238 | GNUNET_free (ctx); |
2253 | } | 2239 | return; |
2240 | } | ||
2254 | #if DEBUG_TESTING_RECONNECT | 2241 | #if DEBUG_TESTING_RECONNECT |
2255 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2242 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2256 | "re-attempting connect of peer %s to peer %s\n", | 2243 | "re-attempting connect of peer %s to peer %s\n", |
@@ -2266,72 +2253,77 @@ reattempt_daemons_connect (void *cls, | |||
2266 | NULL, GNUNET_NO, | 2253 | NULL, GNUNET_NO, |
2267 | NULL, GNUNET_NO, no_handlers); | 2254 | NULL, GNUNET_NO, no_handlers); |
2268 | if (ctx->d1core == NULL) | 2255 | if (ctx->d1core == NULL) |
2269 | { | 2256 | { |
2270 | if (NULL != ctx->cb) | 2257 | if (NULL != ctx->cb) |
2271 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | 2258 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2272 | ctx->d2->cfg, ctx->d1, ctx->d2, | 2259 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2273 | _("Failed to connect to core service of first peer!\n")); | 2260 | _("Failed to connect to core service of first peer!\n")); |
2274 | GNUNET_free (ctx); | 2261 | GNUNET_free (ctx); |
2275 | return; | 2262 | return; |
2276 | } | 2263 | } |
2277 | 2264 | ||
2278 | /* Don't know reason for initial connect failure, update the HELLO for the second peer */ | 2265 | /* Don't know reason for initial connect failure, update the HELLO for the second peer */ |
2279 | if (NULL != ctx->d2->hello) | 2266 | if (NULL != ctx->d2->hello) |
2267 | { | ||
2268 | GNUNET_free (ctx->d2->hello); | ||
2269 | ctx->d2->hello = NULL; | ||
2270 | if (NULL != ctx->d2->th) | ||
2280 | { | 2271 | { |
2281 | GNUNET_free(ctx->d2->hello); | 2272 | GNUNET_TRANSPORT_get_hello_cancel (ctx->d2->th, &process_hello, ctx->d2); |
2282 | ctx->d2->hello = NULL; | 2273 | GNUNET_TRANSPORT_disconnect (ctx->d2->th); |
2283 | if (NULL != ctx->d2->th) | ||
2284 | { | ||
2285 | GNUNET_TRANSPORT_get_hello_cancel(ctx->d2->th, &process_hello, ctx->d2); | ||
2286 | GNUNET_TRANSPORT_disconnect(ctx->d2->th); | ||
2287 | } | ||
2288 | ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); | ||
2289 | GNUNET_assert(ctx->d2->th != NULL); | ||
2290 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2291 | } | 2274 | } |
2275 | ctx->d2->th = | ||
2276 | GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, | ||
2277 | NULL); | ||
2278 | GNUNET_assert (ctx->d2->th != NULL); | ||
2279 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2280 | } | ||
2292 | 2281 | ||
2293 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) | 2282 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) |
2283 | { | ||
2284 | ctx->d2->th = | ||
2285 | GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, | ||
2286 | NULL); | ||
2287 | if (ctx->d2->th == NULL) | ||
2294 | { | 2288 | { |
2295 | ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); | 2289 | GNUNET_CORE_disconnect (ctx->d1core); |
2296 | if (ctx->d2->th == NULL) | 2290 | GNUNET_free (ctx); |
2297 | { | 2291 | if (NULL != ctx->cb) |
2298 | GNUNET_CORE_disconnect (ctx->d1core); | 2292 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2299 | GNUNET_free (ctx); | 2293 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2300 | if (NULL != ctx->cb) | 2294 | _("Failed to connect to transport service!\n")); |
2301 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2295 | return; |
2302 | _("Failed to connect to transport service!\n")); | ||
2303 | return; | ||
2304 | } | ||
2305 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2306 | } | 2296 | } |
2297 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2298 | } | ||
2307 | 2299 | ||
2308 | if (ctx->send_hello == GNUNET_YES) | 2300 | if (ctx->send_hello == GNUNET_YES) |
2301 | { | ||
2302 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | ||
2303 | &ctx->d1->id, | ||
2304 | ctx->d1, NULL, NULL, NULL); | ||
2305 | if (ctx->d1th == NULL) | ||
2309 | { | 2306 | { |
2310 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | 2307 | GNUNET_CORE_disconnect (ctx->d1core); |
2311 | &ctx->d1->id, | 2308 | GNUNET_free (ctx); |
2312 | ctx->d1, NULL, NULL, NULL); | 2309 | if (NULL != ctx->cb) |
2313 | if (ctx->d1th == NULL) | 2310 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2314 | { | 2311 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2315 | GNUNET_CORE_disconnect (ctx->d1core); | 2312 | _("Failed to connect to transport service!\n")); |
2316 | GNUNET_free (ctx); | 2313 | return; |
2317 | if (NULL != ctx->cb) | ||
2318 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | ||
2319 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2320 | _("Failed to connect to transport service!\n")); | ||
2321 | return; | ||
2322 | } | ||
2323 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
2324 | } | 2314 | } |
2315 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
2316 | } | ||
2325 | else | 2317 | else |
2326 | { | 2318 | { |
2327 | ctx->connect_request_handle = | 2319 | ctx->connect_request_handle = |
2328 | GNUNET_CORE_peer_request_connect (ctx->d1core, | 2320 | GNUNET_CORE_peer_request_connect (ctx->d1core, |
2329 | &ctx->d2->id, | 2321 | &ctx->d2->id, |
2330 | &core_connect_request_cont, ctx); | 2322 | &core_connect_request_cont, ctx); |
2331 | } | 2323 | } |
2332 | ctx->timeout_task = | 2324 | ctx->timeout_task = |
2333 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, | 2325 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, |
2334 | ¬ify_connect_result, ctx); | 2326 | ¬ify_connect_result, ctx); |
2335 | } | 2327 | } |
2336 | 2328 | ||
2337 | /** | 2329 | /** |
@@ -2354,79 +2346,85 @@ core_initial_iteration (void *cls, | |||
2354 | 2346 | ||
2355 | if ((peer != NULL) && | 2347 | if ((peer != NULL) && |
2356 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) | 2348 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) |
2349 | { | ||
2350 | ctx->connected = GNUNET_YES; | ||
2351 | ctx->distance = 0; /* FIXME: distance */ | ||
2352 | return; | ||
2353 | } | ||
2354 | else if (peer == NULL) /* End of iteration over peers */ | ||
2355 | { | ||
2356 | if (ctx->connected == GNUNET_YES) | ||
2357 | { | 2357 | { |
2358 | ctx->connected = GNUNET_YES; | 2358 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, |
2359 | ctx->distance = 0; /* FIXME: distance */ | 2359 | ctx); |
2360 | return; | 2360 | return; |
2361 | } | 2361 | } |
2362 | else if (peer == NULL) /* End of iteration over peers */ | ||
2363 | { | ||
2364 | if (ctx->connected == GNUNET_YES) | ||
2365 | { | ||
2366 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | ||
2367 | ctx); | ||
2368 | return; | ||
2369 | } | ||
2370 | 2362 | ||
2371 | /* Peer not already connected, need to schedule connect request! */ | 2363 | /* Peer not already connected, need to schedule connect request! */ |
2372 | if (ctx->d1core == NULL) | 2364 | if (ctx->d1core == NULL) |
2373 | { | 2365 | { |
2374 | #if DEBUG_TESTING | 2366 | #if DEBUG_TESTING |
2375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2376 | "Peers are NOT connected, connecting to core!\n"); | 2368 | "Peers are NOT connected, connecting to core!\n"); |
2377 | #endif | 2369 | #endif |
2378 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, | 2370 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, |
2379 | ctx, | 2371 | ctx, |
2380 | &core_init_notify, | 2372 | &core_init_notify, |
2381 | &connect_notify, NULL, NULL, | 2373 | &connect_notify, NULL, NULL, |
2382 | NULL, GNUNET_NO, | 2374 | NULL, GNUNET_NO, |
2383 | NULL, GNUNET_NO, no_handlers); | 2375 | NULL, GNUNET_NO, no_handlers); |
2384 | } | 2376 | } |
2385 | 2377 | ||
2386 | if (ctx->d1core == NULL) | 2378 | if (ctx->d1core == NULL) |
2387 | { | 2379 | { |
2388 | GNUNET_free (ctx); | 2380 | GNUNET_free (ctx); |
2389 | if (NULL != ctx->cb) | 2381 | if (NULL != ctx->cb) |
2390 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2382 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2391 | _("Failed to connect to core service of first peer!\n")); | 2383 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2392 | return; | 2384 | _("Failed to connect to core service of first peer!\n")); |
2393 | } | 2385 | return; |
2386 | } | ||
2394 | 2387 | ||
2395 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ | 2388 | if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ |
2396 | { | 2389 | { |
2397 | ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); | 2390 | ctx->d2->th = |
2398 | if (ctx->d2->th == NULL) | 2391 | GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, |
2399 | { | 2392 | NULL, NULL); |
2400 | GNUNET_CORE_disconnect (ctx->d1core); | 2393 | if (ctx->d2->th == NULL) |
2401 | GNUNET_free (ctx); | 2394 | { |
2402 | if (NULL != ctx->cb) | 2395 | GNUNET_CORE_disconnect (ctx->d1core); |
2403 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2396 | GNUNET_free (ctx); |
2404 | _("Failed to connect to transport service!\n")); | 2397 | if (NULL != ctx->cb) |
2405 | return; | 2398 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2406 | } | 2399 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2407 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | 2400 | _("Failed to connect to transport service!\n")); |
2408 | } | 2401 | return; |
2402 | } | ||
2403 | GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); | ||
2404 | } | ||
2409 | 2405 | ||
2410 | if (ctx->send_hello == GNUNET_YES) | 2406 | if (ctx->send_hello == GNUNET_YES) |
2411 | { | 2407 | { |
2412 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | 2408 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, |
2413 | &ctx->d1->id, ctx->d1, NULL, NULL, NULL); | 2409 | &ctx->d1->id, ctx->d1, NULL, NULL, |
2414 | if (ctx->d1th == NULL) | 2410 | NULL); |
2415 | { | 2411 | if (ctx->d1th == NULL) |
2416 | GNUNET_CORE_disconnect (ctx->d1core); | 2412 | { |
2417 | GNUNET_free (ctx); | 2413 | GNUNET_CORE_disconnect (ctx->d1core); |
2418 | if (NULL != ctx->cb) | 2414 | GNUNET_free (ctx); |
2419 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 2415 | if (NULL != ctx->cb) |
2420 | _("Failed to connect to transport service!\n")); | 2416 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
2421 | return; | 2417 | ctx->d2->cfg, ctx->d1, ctx->d2, |
2422 | } | 2418 | _("Failed to connect to transport service!\n")); |
2423 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | 2419 | return; |
2424 | } | 2420 | } |
2421 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
2422 | } | ||
2425 | 2423 | ||
2426 | ctx->timeout_task = | 2424 | ctx->timeout_task = |
2427 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, | 2425 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, |
2428 | ¬ify_connect_result, ctx); | 2426 | ¬ify_connect_result, ctx); |
2429 | } | 2427 | } |
2430 | } | 2428 | } |
2431 | 2429 | ||
2432 | 2430 | ||
@@ -2456,20 +2454,21 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2456 | struct ConnectContext *ctx; | 2454 | struct ConnectContext *ctx; |
2457 | 2455 | ||
2458 | if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) | 2456 | if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) |
2459 | { | 2457 | { |
2460 | if (NULL != cb) | 2458 | if (NULL != cb) |
2461 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | 2459 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, |
2462 | _("Peers are not fully running yet, can not connect!\n")); | 2460 | _("Peers are not fully running yet, can not connect!\n")); |
2463 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n"); | 2461 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n"); |
2464 | return; | 2462 | return; |
2465 | } | 2463 | } |
2466 | 2464 | ||
2467 | ctx = GNUNET_malloc (sizeof (struct ConnectContext)); | 2465 | ctx = GNUNET_malloc (sizeof (struct ConnectContext)); |
2468 | ctx->d1 = d1; | 2466 | ctx->d1 = d1; |
2469 | ctx->d2 = d2; | 2467 | ctx->d2 = d2; |
2470 | ctx->timeout_hello = | 2468 | ctx->timeout_hello = |
2471 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); | 2469 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); |
2472 | ctx->relative_timeout = GNUNET_TIME_relative_divide(timeout, max_connect_attempts); | 2470 | ctx->relative_timeout = |
2471 | GNUNET_TIME_relative_divide (timeout, max_connect_attempts); | ||
2473 | ctx->cb = cb; | 2472 | ctx->cb = cb; |
2474 | ctx->cb_cls = cb_cls; | 2473 | ctx->cb_cls = cb_cls; |
2475 | ctx->connect_attempts = max_connect_attempts; | 2474 | ctx->connect_attempts = max_connect_attempts; |
@@ -2482,8 +2481,10 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2482 | #endif | 2481 | #endif |
2483 | 2482 | ||
2484 | /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ | 2483 | /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ |
2485 | GNUNET_assert(GNUNET_OK == GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, &core_initial_iteration, ctx)); | 2484 | GNUNET_assert (GNUNET_OK == |
2486 | /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx));*/ | 2485 | GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, |
2486 | &core_initial_iteration, ctx)); | ||
2487 | /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx)); */ | ||
2487 | } | 2488 | } |
2488 | 2489 | ||
2489 | /* end of testing.c */ | 2490 | /* end of testing.c */ |