aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-25 15:02:53 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-25 15:02:53 +0000
commit7effc1a7a43dd4962c5777538e26a09a67914ecd (patch)
tree538f20918d221094761554e46891166ab0ca98bb /src/testbed
parent883f76092343cb682016415142245b83c912f816 (diff)
downloadgnunet-7effc1a7a43dd4962c5777538e26a09a67914ecd.tar.gz
gnunet-7effc1a7a43dd4962c5777538e26a09a67914ecd.zip
-helper service shutdown fixes; overlay connect message
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am1
-rw-r--r--src/testbed/gnunet-service-testbed.c145
-rw-r--r--src/testbed/gnunet-testbed-helper.c84
-rw-r--r--src/testbed/testbed_api.c6
-rw-r--r--src/testbed/testbed_api.h1
-rw-r--r--src/testbed/testbed_api_peers.c29
-rw-r--r--src/testbed/testbed_api_peers.h58
7 files changed, 239 insertions, 85 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index fd667b8d1..d3ca76c17 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -22,6 +22,7 @@ gnunet_service_testbed_SOURCES = \
22 gnunet-service-testbed.c 22 gnunet-service-testbed.c
23gnunet_service_testbed_LDADD = $(XLIB) \ 23gnunet_service_testbed_LDADD = $(XLIB) \
24 $(top_builddir)/src/util/libgnunetutil.la \ 24 $(top_builddir)/src/util/libgnunetutil.la \
25 $(top_builddir)/src/transport/libgnunettransport.la \
25 $(top_builddir)/src/testing/libgnunettesting.la \ 26 $(top_builddir)/src/testing/libgnunettesting.la \
26 $(top_builddir)/src/testbed/libgnunettestbed.la \ 27 $(top_builddir)/src/testbed/libgnunettestbed.la \
27 $(LTLIBINTL) -lz 28 $(LTLIBINTL) -lz
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index f2bb16488..0b19d6e5c 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_service_lib.h" 28#include "gnunet_service_lib.h"
29#include "gnunet_server_lib.h" 29#include "gnunet_server_lib.h"
30#include "gnunet_transport_service.h"
30#include <zlib.h> 31#include <zlib.h>
31 32
32#include "gnunet_testbed_service.h" 33#include "gnunet_testbed_service.h"
@@ -303,6 +304,53 @@ struct Peer
303 304
304 305
305/** 306/**
307 * Context information for connecting 2 peers in overlay
308 */
309struct OverlayConnectContext
310{
311 /**
312 * peer 1
313 */
314 struct Peer *peer1;
315
316 /**
317 * peer 2
318 */
319 struct Peer *peer2;
320
321 /**
322 * Transport handle of peer1
323 */
324 struct GNUNET_TRANSPORT_Handle *peer1_transport;
325
326 /**
327 * Transport handle of peer2
328 */
329 struct GNUNET_TRANSPORT_Handle *peer2_transport;
330
331 /**
332 * HELLO of peer1
333 */
334 struct GNUNET_MessageHeader *peer1_hello;
335
336 /**
337 * HELLO of peer2
338 */
339 struct GNUNET_MessageHeader *peer2_hello;
340
341 /**
342 * Get hello handle for peer1
343 */
344 struct GNUNET_TRANSPORT_GetHelloHandle *peer1_ghh;
345
346 /**
347 * Get hello handle for peer2
348 */
349 struct GNUNET_TRANSPORT_GetHelloHandle *peer2_ghh;
350};
351
352
353/**
306 * The master context; generated with the first INIT message 354 * The master context; generated with the first INIT message
307 */ 355 */
308static struct Context *master_context; 356static struct Context *master_context;
@@ -312,11 +360,6 @@ static struct Context *master_context;
312/***********/ 360/***********/
313 361
314/** 362/**
315 * Wrapped stdin.
316 */
317static struct GNUNET_DISK_FileHandle *fh;
318
319/**
320 * Current Transmit Handle; NULL if no notify transmit exists currently 363 * Current Transmit Handle; NULL if no notify transmit exists currently
321 */ 364 */
322static struct GNUNET_SERVER_TransmitHandle *transmit_handle; 365static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
@@ -1436,6 +1479,58 @@ handle_peer_get_config (void *cls,
1436} 1479}
1437 1480
1438 1481
1482
1483/**
1484 * Function called whenever there is an update to the
1485 * HELLO of this peer.
1486 *
1487 * @param cls closure
1488 * @param hello our updated HELLO
1489 */
1490static void
1491hello_update_cb (void *cls,
1492 const struct GNUNET_MessageHeader *hello)
1493{
1494 GNUNET_break(0);
1495}
1496
1497
1498/**
1499 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
1500 *
1501 * @param cls NULL
1502 * @param client identification of the client
1503 * @param message the actual message
1504 */
1505static void
1506handle_overlay_connect (void *cls,
1507 struct GNUNET_SERVER_Client *client,
1508 const struct GNUNET_MessageHeader *message)
1509{
1510 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
1511 struct OverlayConnectContext *occ;
1512 uint32_t p1;
1513 uint32_t p2;
1514
1515 msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
1516 p1 = ntohl (msg->peer1);
1517 p2 = ntohl (msg->peer2);
1518 GNUNET_assert (p1 < peer_list_size);
1519 GNUNET_assert (NULL != peer_list[p1]);
1520 GNUNET_assert (p2 < peer_list_size);
1521 GNUNET_assert (NULL != peer_list[p2]);
1522 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
1523 occ->peer1 = peer_list[p1];
1524 occ->peer2 = peer_list[p2];
1525 occ->peer1_transport = GNUNET_TRANSPORT_connect (occ->peer1->cfg, NULL, occ,
1526 NULL, NULL, NULL);
1527 occ->peer2_transport = GNUNET_TRANSPORT_connect (occ->peer2->cfg, NULL, occ,
1528 NULL, NULL, NULL);
1529 occ->peer1_ghh = GNUNET_TRANSPORT_get_hello (occ->peer1_transport, &hello_update_cb, occ);
1530 occ->peer2_ghh = GNUNET_TRANSPORT_get_hello (occ->peer2_transport, &hello_update_cb, occ);
1531}
1532
1533
1439/** 1534/**
1440 * Iterator over hash map entries. 1535 * Iterator over hash map entries.
1441 * 1536 *
@@ -1478,11 +1573,6 @@ shutdown_task (void *cls,
1478 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator, 1573 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
1479 NULL); 1574 NULL);
1480 GNUNET_CONTAINER_multihashmap_destroy (ss_map); 1575 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
1481 if (NULL != fh)
1482 {
1483 GNUNET_DISK_file_close (fh);
1484 fh = NULL;
1485 }
1486 if (NULL != lcfq_head) 1576 if (NULL != lcfq_head)
1487 { 1577 {
1488 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id) 1578 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
@@ -1541,21 +1631,6 @@ shutdown_task (void *cls,
1541 1631
1542 1632
1543/** 1633/**
1544 * Debug shutdown task in case of stdin getting closed
1545 *
1546 * @param cls NULL
1547 * @param tc the TaskContext from scheduler
1548 */
1549static void
1550shutdown_task_ (void *cls,
1551 const struct GNUNET_SCHEDULER_TaskContext *tc)
1552{
1553 LOG (GNUNET_ERROR_TYPE_DEBUG, "STDIN closed ...\n");
1554 shutdown_task (cls, tc);
1555}
1556
1557
1558/**
1559 * Callback for client disconnect 1634 * Callback for client disconnect
1560 * 1635 *
1561 * @param cls NULL 1636 * @param cls NULL
@@ -1575,7 +1650,7 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
1575 hurt for now --- might need to revise this later if we ever 1650 hurt for now --- might need to revise this later if we ever
1576 decide that master connections might be temporarily down 1651 decide that master connections might be temporarily down
1577 for some reason */ 1652 for some reason */
1578 GNUNET_SCHEDULER_shutdown (); 1653 //GNUNET_SCHEDULER_shutdown ();
1579 } 1654 }
1580} 1655}
1581 1656
@@ -1610,6 +1685,8 @@ testbed_run (void *cls,
1610 sizeof (struct GNUNET_TESTBED_PeerStopMessage)}, 1685 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
1611 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG, 1686 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
1612 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)}, 1687 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
1688 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
1689 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
1613 {NULL} 1690 {NULL}
1614 }; 1691 };
1615 1692
@@ -1619,18 +1696,10 @@ testbed_run (void *cls,
1619 &client_disconnect_cb, 1696 &client_disconnect_cb,
1620 NULL); 1697 NULL);
1621 ss_map = GNUNET_CONTAINER_multihashmap_create (5); 1698 ss_map = GNUNET_CONTAINER_multihashmap_create (5);
1622 fh = GNUNET_DISK_get_handle_from_native (stdin); 1699 shutdown_task_id =
1623 if (NULL == fh) 1700 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1624 shutdown_task_id = 1701 &shutdown_task,
1625 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1702 NULL);
1626 &shutdown_task,
1627 NULL);
1628 else
1629 shutdown_task_id =
1630 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1631 fh,
1632 &shutdown_task_,
1633 NULL);
1634 LOG_DEBUG ("Testbed startup complete\n"); 1703 LOG_DEBUG ("Testbed startup complete\n");
1635} 1704}
1636 1705
diff --git a/src/testbed/gnunet-testbed-helper.c b/src/testbed/gnunet-testbed-helper.c
index 36eb3e931..942a9e549 100644
--- a/src/testbed/gnunet-testbed-helper.c
+++ b/src/testbed/gnunet-testbed-helper.c
@@ -99,16 +99,6 @@ static struct GNUNET_DISK_FileHandle *stdout_fd;
99static struct GNUNET_OS_Process *testbed; 99static struct GNUNET_OS_Process *testbed;
100 100
101/** 101/**
102 * Pipe handle to child's stdin
103 */
104static struct GNUNET_DISK_PipeHandle *pipe_in;
105
106/**
107 * Pipe handle to child's stdout
108 */
109static struct GNUNET_DISK_PipeHandle *pipe_out;
110
111/**
112 * Task identifier for the read task 102 * Task identifier for the read task
113 */ 103 */
114static GNUNET_SCHEDULER_TaskIdentifier read_task_id; 104static GNUNET_SCHEDULER_TaskIdentifier read_task_id;
@@ -126,7 +116,13 @@ static int done_reading;
126/** 116/**
127 * Result to return in case we fail 117 * Result to return in case we fail
128 */ 118 */
129static int ret; 119static int status;
120
121
122/**
123 * Are we shutting down
124 */
125static int in_shutdown;
130 126
131 127
132/** 128/**
@@ -139,6 +135,7 @@ static void
139shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 135shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
140{ 136{
141 LOG_DEBUG ("Shutting down\n"); 137 LOG_DEBUG ("Shutting down\n");
138 in_shutdown = GNUNET_YES;
142 if (GNUNET_SCHEDULER_NO_TASK != read_task_id) 139 if (GNUNET_SCHEDULER_NO_TASK != read_task_id)
143 { 140 {
144 GNUNET_SCHEDULER_cancel (read_task_id); 141 GNUNET_SCHEDULER_cancel (read_task_id);
@@ -157,21 +154,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
157 tokenizer = NULL; 154 tokenizer = NULL;
158 if (NULL != testbed) 155 if (NULL != testbed)
159 { 156 {
160 (void) GNUNET_OS_process_kill (testbed, SIGTERM); 157 GNUNET_break (0 == GNUNET_OS_process_kill (testbed, SIGTERM));
161 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (testbed)); 158 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (testbed));
162 GNUNET_OS_process_destroy (testbed); 159 GNUNET_OS_process_destroy (testbed);
163 testbed = NULL; 160 testbed = NULL;
164 } 161 }
165 if (NULL != pipe_in)
166 {
167 (void) GNUNET_DISK_pipe_close (pipe_in);
168 pipe_in = NULL;
169 }
170 if (NULL != pipe_out)
171 {
172 (void) GNUNET_DISK_pipe_close (pipe_out);
173 pipe_out = NULL;
174 }
175 if (NULL != test_system) 162 if (NULL != test_system)
176 { 163 {
177 GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); 164 GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
@@ -288,14 +275,6 @@ tokenizer_cb (void *cls, void *client,
288 (test_system, cfg)); 275 (test_system, cfg));
289 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string 276 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
290 (cfg, "PATHS", "DEFAULTCONFIG", &config)); 277 (cfg, "PATHS", "DEFAULTCONFIG", &config));
291 pipe_in = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
292 pipe_out = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_YES);
293 if ((NULL == pipe_in) || (NULL == pipe_out))
294 {
295 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
296 GNUNET_free (config);
297 goto error;
298 }
299 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config)) 278 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config))
300 { 279 {
301 LOG (GNUNET_ERROR_TYPE_WARNING, 280 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -306,7 +285,7 @@ tokenizer_cb (void *cls, void *client,
306 } 285 }
307 LOG_DEBUG ("Staring testbed with config: %s\n", config); 286 LOG_DEBUG ("Staring testbed with config: %s\n", config);
308 testbed = GNUNET_OS_start_process 287 testbed = GNUNET_OS_start_process
309 (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR /*verbose? */, pipe_in, pipe_out, 288 (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR /*verbose? */, NULL, NULL,
310 "gnunet-service-testbed", "gnunet-service-testbed", "-c", config, NULL); 289 "gnunet-service-testbed", "gnunet-service-testbed", "-c", config, NULL);
311 GNUNET_free (config); 290 GNUNET_free (config);
312 if (NULL == testbed) 291 if (NULL == testbed)
@@ -316,8 +295,6 @@ tokenizer_cb (void *cls, void *client,
316 GNUNET_CONFIGURATION_destroy (cfg); 295 GNUNET_CONFIGURATION_destroy (cfg);
317 goto error; 296 goto error;
318 } 297 }
319 GNUNET_DISK_pipe_close_end (pipe_out, GNUNET_DISK_PIPE_END_WRITE);
320 GNUNET_DISK_pipe_close_end (pipe_in, GNUNET_DISK_PIPE_END_READ);
321 done_reading = GNUNET_YES; 298 done_reading = GNUNET_YES;
322 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); 299 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
323 GNUNET_CONFIGURATION_destroy (cfg); 300 GNUNET_CONFIGURATION_destroy (cfg);
@@ -338,7 +315,7 @@ tokenizer_cb (void *cls, void *client,
338 return GNUNET_OK; 315 return GNUNET_OK;
339 316
340 error: 317 error:
341 ret = GNUNET_SYSERR; 318 status = GNUNET_SYSERR;
342 GNUNET_SCHEDULER_shutdown (); 319 GNUNET_SCHEDULER_shutdown ();
343 return GNUNET_SYSERR; 320 return GNUNET_SYSERR;
344} 321}
@@ -362,14 +339,12 @@ read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
362 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); 339 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf));
363 if (GNUNET_SYSERR == sread) 340 if (GNUNET_SYSERR == sread)
364 { 341 {
365 GNUNET_break (0); /* FIXME: stdin closed - kill child */
366 GNUNET_SCHEDULER_shutdown (); 342 GNUNET_SCHEDULER_shutdown ();
367 return; 343 return;
368 } 344 }
369 if (GNUNET_YES == done_reading) 345 if (GNUNET_YES == done_reading)
370 { 346 {
371 /* didn't expect any more data! */ 347 /* didn't expect any more data! */
372 GNUNET_break (0);
373 GNUNET_SCHEDULER_shutdown (); 348 GNUNET_SCHEDULER_shutdown ();
374 return; 349 return;
375 } 350 }
@@ -413,6 +388,24 @@ run (void *cls, char *const *args, const char *cfgfile,
413 388
414 389
415/** 390/**
391 * Signal handler called for SIGCHLD. Triggers the
392 * respective handler by writing to the trigger pipe.
393 */
394static void
395sighandler_child_death ()
396{
397 if ((NULL != testbed) && (GNUNET_NO == in_shutdown))
398 {
399 LOG_DEBUG ("Child died\n");
400 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (testbed));
401 GNUNET_OS_process_destroy (testbed);
402 testbed = NULL;
403 GNUNET_SCHEDULER_shutdown (); /* We are done too! */
404 }
405}
406
407
408/**
416 * Main function 409 * Main function
417 * 410 *
418 * @param argc the number of command line arguments 411 * @param argc the number of command line arguments
@@ -421,18 +414,25 @@ run (void *cls, char *const *args, const char *cfgfile,
421 */ 414 */
422int main (int argc, char **argv) 415int main (int argc, char **argv)
423{ 416{
417 struct GNUNET_SIGNAL_Context *shc_chld;
424 struct GNUNET_GETOPT_CommandLineOption options[] = { 418 struct GNUNET_GETOPT_CommandLineOption options[] = {
425 GNUNET_GETOPT_OPTION_END 419 GNUNET_GETOPT_OPTION_END
426 }; 420 };
421 int ret;
427 422
428 ret = GNUNET_OK; 423 status = GNUNET_OK;
424 in_shutdown = GNUNET_NO;
429 //sleep (60); 425 //sleep (60);
430 if (GNUNET_OK != 426 shc_chld =
431 GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-helper", 427 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
432 "Helper for starting gnunet-service-testbed", 428 ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-helper",
433 options, &run, NULL)) 429 "Helper for starting gnunet-service-testbed",
430 options, &run, NULL);
431 GNUNET_SIGNAL_handler_uninstall (shc_chld);
432 shc_chld = NULL;
433 if (GNUNET_OK != ret)
434 return 1; 434 return 1;
435 return (GNUNET_OK == ret) ? 0 : 1; 435 return (GNUNET_OK == status) ? 0 : 1;
436} 436}
437 437
438/* end of gnunet-testbed-helper.c */ 438/* end of gnunet-testbed-helper.c */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 708fc1d04..365a8cdee 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -325,6 +325,7 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
325 GNUNET_assert (NULL != data->peer); 325 GNUNET_assert (NULL != data->peer);
326 peer = data->peer; 326 peer = data->peer;
327 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id)); 327 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
328 peer->state = PS_CREATED;
328 cb = data->cb; 329 cb = data->cb;
329 cls = data->cls; 330 cls = data->cls;
330 GNUNET_free (data); 331 GNUNET_free (data);
@@ -374,10 +375,12 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
374 switch (event.type) 375 switch (event.type)
375 { 376 {
376 case GNUNET_TESTBED_ET_PEER_START: 377 case GNUNET_TESTBED_ET_PEER_START:
378 peer->state = PS_STARTED;
377 event.details.peer_start.host = peer->host; 379 event.details.peer_start.host = peer->host;
378 event.details.peer_start.peer = peer; 380 event.details.peer_start.peer = peer;
379 break; 381 break;
380 case GNUNET_TESTBED_ET_PEER_STOP: 382 case GNUNET_TESTBED_ET_PEER_STOP:
383 peer->state = PS_STOPPED;
381 event.details.peer_stop.peer = peer; 384 event.details.peer_stop.peer = peer;
382 break; 385 break;
383 default: 386 default:
@@ -1363,6 +1366,9 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
1363 } 1366 }
1364 GNUNET_free_non_null (operation->data); 1367 GNUNET_free_non_null (operation->data);
1365 break; 1368 break;
1369 case OP_OVERLAY_CONNECT:
1370 GNUNET_free_non_null (operation->data);
1371 break;
1366 } 1372 }
1367 GNUNET_free (operation); 1373 GNUNET_free (operation);
1368} 1374}
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 4a5adfa17..642fc4ccb 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -62,6 +62,7 @@ enum OperationType
62 * Overlay connection operation 62 * Overlay connection operation
63 */ 63 */
64 OP_OVERLAY_CONNECT, 64 OP_OVERLAY_CONNECT,
65
65 }; 66 };
66 67
67 68
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 4711aba7d..4571b78df 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -98,6 +98,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
98 peer->controller = controller; 98 peer->controller = controller;
99 peer->host = host; 99 peer->host = host;
100 peer->unique_id = unique_id; 100 peer->unique_id = unique_id;
101 peer->state = PS_INVALID;
101 data = GNUNET_malloc (sizeof (struct PeerCreateData)); 102 data = GNUNET_malloc (sizeof (struct PeerCreateData));
102 data->cb = cb; 103 data->cb = cb;
103 data->cls = cls; 104 data->cls = cls;
@@ -184,6 +185,7 @@ GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
184 struct GNUNET_TESTBED_Operation *op; 185 struct GNUNET_TESTBED_Operation *op;
185 struct GNUNET_TESTBED_PeerStartMessage *msg; 186 struct GNUNET_TESTBED_PeerStartMessage *msg;
186 187
188 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
187 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 189 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
188 op->operation_id = peer->controller->operation_counter++; 190 op->operation_id = peer->controller->operation_counter++;
189 op->controller = peer->controller; 191 op->controller = peer->controller;
@@ -215,6 +217,7 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
215 struct GNUNET_TESTBED_Operation *op; 217 struct GNUNET_TESTBED_Operation *op;
216 struct GNUNET_TESTBED_PeerStopMessage *msg; 218 struct GNUNET_TESTBED_PeerStopMessage *msg;
217 219
220 GNUNET_assert (PS_STARTED == peer->state);
218 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 221 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
219 op->operation_id = peer->controller->operation_counter++; 222 op->operation_id = peer->controller->operation_counter++;
220 op->controller = peer->controller; 223 op->controller = peer->controller;
@@ -365,7 +368,31 @@ GNUNET_TESTBED_overlay_connect (void *op_cls,
365 struct GNUNET_TESTBED_Peer *p1, 368 struct GNUNET_TESTBED_Peer *p1,
366 struct GNUNET_TESTBED_Peer *p2) 369 struct GNUNET_TESTBED_Peer *p2)
367{ 370{
368 GNUNET_break (0); 371 struct GNUNET_TESTBED_Operation *op;
372 struct OverlayConnectData *data;
373 struct GNUNET_TESTBED_OverlayConnectMessage *msg;
374
375 GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state));
376 GNUNET_assert (p1->controller == p2->controller);
377 data = GNUNET_malloc (sizeof (struct OverlayConnectData));
378 data->p1 = p1;
379 data->p2 = p2;
380 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
381 op->controller = p1->controller;
382 op->operation_id = op->controller->operation_counter++;
383 op->type = OP_OVERLAY_CONNECT;
384 op->data = data;
385 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage));
386 msg->header.size = htons (sizeof (struct
387 GNUNET_TESTBED_OverlayConnectMessage));
388 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT);
389 msg->peer1 = htonl (p1->unique_id);
390 msg->peer2 = htonl (p2->unique_id);
391 msg->operation_id = GNUNET_htonll (op->operation_id);
392 GNUNET_CONTAINER_DLL_insert_tail (op->controller->op_head,
393 op->controller->op_tail, op);
394 GNUNET_TESTBED_queue_message_ (op->controller,
395 (struct GNUNET_MessageHeader *) msg);
369 return NULL; 396 return NULL;
370} 397}
371 398
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index b3a74eef7..9c1305c79 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -48,6 +48,33 @@ struct PeerDetails
48 48
49 49
50/** 50/**
51 * Enumeration of possible states a peer could be in
52 */
53enum PeerState
54 {
55 /**
56 * State to signify that this peer is invalid
57 */
58 PS_INVALID,
59
60 /**
61 * The peer has been created
62 */
63 PS_CREATED,
64
65 /**
66 * The peer is running
67 */
68 PS_STARTED,
69
70 /**
71 * The peer is stopped
72 */
73 PS_STOPPED,
74 };
75
76
77/**
51 * A peer controlled by the testing framework. A peer runs 78 * A peer controlled by the testing framework. A peer runs
52 * at a particular host. 79 * at a particular host.
53 */ 80 */
@@ -65,16 +92,20 @@ struct GNUNET_TESTBED_Peer
65 struct GNUNET_TESTBED_Host *host; 92 struct GNUNET_TESTBED_Host *host;
66 93
67 /** 94 /**
95 * Internals of the peer for the controlling process; NULL if
96 * this process is not controlling this peer.
97 */
98 struct PeerDetails *details;
99
100 /**
68 * Globally unique ID of the peer. 101 * Globally unique ID of the peer.
69 */ 102 */
70 uint32_t unique_id; 103 uint32_t unique_id;
71 104
72 /** 105 /**
73 * Internals of the peer for the controlling process; NULL if 106 * Peer's state
74 * this process is not controlling this peer.
75 */ 107 */
76 struct PeerDetails *details; 108 enum PeerState state;
77
78}; 109};
79 110
80 111
@@ -161,6 +192,25 @@ struct PeerInfoData2
161 192
162 193
163/** 194/**
195 * Data structure for OperationType OP_OVERLAY_CONNECT
196 */
197struct OverlayConnectData
198{
199 /**
200 * Peer A to connect to peer B
201 */
202 struct GNUNET_TESTBED_Peer *p1;
203
204 /**
205 * Peer B
206 */
207 struct GNUNET_TESTBED_Peer *p2;
208
209};
210
211
212
213/**
164 * Create the given peer at the specified host using the given 214 * Create the given peer at the specified host using the given
165 * controller. If the given controller is not running on the target 215 * controller. If the given controller is not running on the target
166 * host, it should find or create a controller at the target host and 216 * host, it should find or create a controller at the target host and