diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-21 20:01:34 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-21 20:01:34 +0000 |
commit | da683835112d7510461269a81363dcaf23af4b9b (patch) | |
tree | 5c4e530a304c315f132a18e0f9d938d04b9e94de | |
parent | e823f8b9a57844dc90afed91076117eea7cb85ea (diff) | |
download | gnunet-da683835112d7510461269a81363dcaf23af4b9b.tar.gz gnunet-da683835112d7510461269a81363dcaf23af4b9b.zip |
fix #2666: Implement service sharing among peers
-rw-r--r-- | src/include/gnunet_protocols.h | 49 | ||||
-rw-r--r-- | src/include/gnunet_testbed_service.h | 19 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 209 | ||||
-rw-r--r-- | src/testbed/testbed.conf.in | 17 | ||||
-rw-r--r-- | src/testbed/testbed.h | 28 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 40 |
6 files changed, 114 insertions, 248 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index b49590390..ae28da7b1 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1524,122 +1524,117 @@ extern "C" | |||
1524 | #define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS 462 | 1524 | #define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS 462 |
1525 | 1525 | ||
1526 | /** | 1526 | /** |
1527 | * Message to configure a service to be shared among peers | ||
1528 | */ | ||
1529 | #define GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE 463 | ||
1530 | |||
1531 | /** | ||
1532 | * Message to link delegated controller to slave controller | 1527 | * Message to link delegated controller to slave controller |
1533 | */ | 1528 | */ |
1534 | #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS 464 | 1529 | #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS 463 |
1535 | 1530 | ||
1536 | /** | 1531 | /** |
1537 | * Message to create a peer at a host | 1532 | * Message to create a peer at a host |
1538 | */ | 1533 | */ |
1539 | #define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER 465 | 1534 | #define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER 464 |
1540 | 1535 | ||
1541 | /** | 1536 | /** |
1542 | * Message to reconfigure a peer | 1537 | * Message to reconfigure a peer |
1543 | */ | 1538 | */ |
1544 | #define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER 466 | 1539 | #define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER 465 |
1545 | 1540 | ||
1546 | /** | 1541 | /** |
1547 | * Message to start a peer at a host | 1542 | * Message to start a peer at a host |
1548 | */ | 1543 | */ |
1549 | #define GNUNET_MESSAGE_TYPE_TESTBED_START_PEER 467 | 1544 | #define GNUNET_MESSAGE_TYPE_TESTBED_START_PEER 466 |
1550 | 1545 | ||
1551 | /** | 1546 | /** |
1552 | * Message to stop a peer at a host | 1547 | * Message to stop a peer at a host |
1553 | */ | 1548 | */ |
1554 | #define GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER 468 | 1549 | #define GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER 467 |
1555 | 1550 | ||
1556 | /** | 1551 | /** |
1557 | * Message to destroy a peer | 1552 | * Message to destroy a peer |
1558 | */ | 1553 | */ |
1559 | #define GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER 469 | 1554 | #define GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER 468 |
1560 | 1555 | ||
1561 | /** | 1556 | /** |
1562 | * Configure underlay link message | 1557 | * Configure underlay link message |
1563 | */ | 1558 | */ |
1564 | #define GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK 470 | 1559 | #define GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK 469 |
1565 | 1560 | ||
1566 | /** | 1561 | /** |
1567 | * Message to connect peers in a overlay | 1562 | * Message to connect peers in a overlay |
1568 | */ | 1563 | */ |
1569 | #define GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT 471 | 1564 | #define GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT 470 |
1570 | 1565 | ||
1571 | /** | 1566 | /** |
1572 | * Message for peer events | 1567 | * Message for peer events |
1573 | */ | 1568 | */ |
1574 | #define GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT 472 | 1569 | #define GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT 471 |
1575 | 1570 | ||
1576 | /** | 1571 | /** |
1577 | * Message for peer connect events | 1572 | * Message for peer connect events |
1578 | */ | 1573 | */ |
1579 | #define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT 473 | 1574 | #define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT 472 |
1580 | 1575 | ||
1581 | /** | 1576 | /** |
1582 | * Message for operation events | 1577 | * Message for operation events |
1583 | */ | 1578 | */ |
1584 | #define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT 474 | 1579 | #define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT 473 |
1585 | 1580 | ||
1586 | /** | 1581 | /** |
1587 | * Message to signal successful peer creation | 1582 | * Message to signal successful peer creation |
1588 | */ | 1583 | */ |
1589 | #define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS 475 | 1584 | #define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS 474 |
1590 | 1585 | ||
1591 | /** | 1586 | /** |
1592 | * Message to signal a generic operation has been successful | 1587 | * Message to signal a generic operation has been successful |
1593 | */ | 1588 | */ |
1594 | #define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS 476 | 1589 | #define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS 475 |
1595 | 1590 | ||
1596 | /** | 1591 | /** |
1597 | * Message to get the configuration of a peer | 1592 | * Message to get the configuration of a peer |
1598 | */ | 1593 | */ |
1599 | #define GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION 477 | 1594 | #define GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION 476 |
1600 | 1595 | ||
1601 | /** | 1596 | /** |
1602 | * Message containing the peer configuration | 1597 | * Message containing the peer configuration |
1603 | */ | 1598 | */ |
1604 | #define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION 478 | 1599 | #define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION 477 |
1605 | 1600 | ||
1606 | /** | 1601 | /** |
1607 | * Message to request a controller to make one of its peer to connect to another | 1602 | * Message to request a controller to make one of its peer to connect to another |
1608 | * peer using the contained HELLO | 1603 | * peer using the contained HELLO |
1609 | */ | 1604 | */ |
1610 | #define GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT 479 | 1605 | #define GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT 478 |
1611 | 1606 | ||
1612 | /** | 1607 | /** |
1613 | * Message to request configuration of a slave controller | 1608 | * Message to request configuration of a slave controller |
1614 | */ | 1609 | */ |
1615 | #define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION 480 | 1610 | #define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION 479 |
1616 | 1611 | ||
1617 | /** | 1612 | /** |
1618 | * Message which contains the configuration of slave controller | 1613 | * Message which contains the configuration of slave controller |
1619 | */ | 1614 | */ |
1620 | #define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION 481 | 1615 | #define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION 480 |
1621 | 1616 | ||
1622 | /** | 1617 | /** |
1623 | * Message to signal the result of GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS request | 1618 | * Message to signal the result of GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS request |
1624 | */ | 1619 | */ |
1625 | #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 482 | 1620 | #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 481 |
1626 | 1621 | ||
1627 | /** | 1622 | /** |
1628 | * A controller receiving this message floods it to its directly-connected | 1623 | * A controller receiving this message floods it to its directly-connected |
1629 | * sub-controllers and then stops and destroys all peers | 1624 | * sub-controllers and then stops and destroys all peers |
1630 | */ | 1625 | */ |
1631 | #define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 483 | 1626 | #define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 482 |
1632 | 1627 | ||
1633 | /** | 1628 | /** |
1634 | * Message to start/stop a service of a peer | 1629 | * Message to start/stop a service of a peer |
1635 | */ | 1630 | */ |
1636 | #define GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE 484 | 1631 | #define GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE 483 |
1637 | 1632 | ||
1638 | /** | 1633 | /** |
1639 | * Not really a message, but for careful checks on the testbed messages; Should | 1634 | * Not really a message, but for careful checks on the testbed messages; Should |
1640 | * always be the maximum and never be used to send messages with this type | 1635 | * always be the maximum and never be used to send messages with this type |
1641 | */ | 1636 | */ |
1642 | #define GNUNET_MESSAGE_TYPE_TESTBED_MAX 485 | 1637 | #define GNUNET_MESSAGE_TYPE_TESTBED_MAX 484 |
1643 | 1638 | ||
1644 | /** | 1639 | /** |
1645 | * The initialization message towards gnunet-testbed-helper | 1640 | * The initialization message towards gnunet-testbed-helper |
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 9b92d4856..f19122978 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h | |||
@@ -501,25 +501,6 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
501 | 501 | ||
502 | 502 | ||
503 | /** | 503 | /** |
504 | * Configure shared services at a controller. Using this function, | ||
505 | * you can specify that certain services (such as "resolver") | ||
506 | * should not be run for each peer but instead be shared | ||
507 | * across N peers on the specified host. This function | ||
508 | * must be called before any peers are created at the host. | ||
509 | * | ||
510 | * @param controller controller to configure | ||
511 | * @param service_name name of the service to share | ||
512 | * @param num_peers number of peers that should share one instance | ||
513 | * of the specified service (1 for no sharing is the default), | ||
514 | * use 0 to disable the service | ||
515 | */ | ||
516 | void | ||
517 | GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller, | ||
518 | const char *service_name, | ||
519 | uint32_t num_peers); | ||
520 | |||
521 | |||
522 | /** | ||
523 | * Stop the given controller (also will terminate all peers and | 504 | * Stop the given controller (also will terminate all peers and |
524 | * controllers dependent on this controller). This function | 505 | * controllers dependent on this controller). This function |
525 | * blocks until the testbed has been fully terminated (!). | 506 | * blocks until the testbed has been fully terminated (!). |
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index d9a2a6c13..6bca3d9cd 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -127,10 +127,6 @@ static struct MessageQueue *mq_head; | |||
127 | */ | 127 | */ |
128 | static struct MessageQueue *mq_tail; | 128 | static struct MessageQueue *mq_tail; |
129 | 129 | ||
130 | /** | ||
131 | * The hashmap of shared services | ||
132 | */ | ||
133 | static struct GNUNET_CONTAINER_MultiHashMap *ss_map; | ||
134 | 130 | ||
135 | /** | 131 | /** |
136 | * The shutdown task handle | 132 | * The shutdown task handle |
@@ -235,19 +231,6 @@ host_list_add (struct GNUNET_TESTBED_Host *host) | |||
235 | 231 | ||
236 | 232 | ||
237 | /** | 233 | /** |
238 | * Routes message to a host given its host_id | ||
239 | * | ||
240 | * @param host_id the id of the destination host | ||
241 | * @param msg the message to be routed | ||
242 | */ | ||
243 | static void | ||
244 | route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg) | ||
245 | { | ||
246 | GNUNET_break (0); | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Send operation failure message to client | 234 | * Send operation failure message to client |
252 | * | 235 | * |
253 | * @param client the client to which the failure message has to be sent to | 236 | * @param client the client to which the failure message has to be sent to |
@@ -440,6 +423,57 @@ GST_forwarded_operation_timeout (void *cls, | |||
440 | 423 | ||
441 | 424 | ||
442 | /** | 425 | /** |
426 | * Parse service sharing specification line. | ||
427 | * Format is "[<service:share>] [<service:share>] ..." | ||
428 | * | ||
429 | * @param ss_str the spec string to be parsed | ||
430 | * @param cfg the configuration to use for shared services | ||
431 | * @return an array suitable to pass to GNUNET_TESTING_system_create(). NULL | ||
432 | * upon empty service sharing specification. | ||
433 | */ | ||
434 | static struct GNUNET_TESTING_SharedService * | ||
435 | parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg) | ||
436 | { | ||
437 | struct GNUNET_TESTING_SharedService ss; | ||
438 | struct GNUNET_TESTING_SharedService *slist; | ||
439 | char service[256]; | ||
440 | char *arg; | ||
441 | unsigned int n; | ||
442 | #define GROW_SS \ | ||
443 | do { \ | ||
444 | GNUNET_array_grow (slist, n, n+1); \ | ||
445 | (void) memcpy (&slist[n - 1], &ss, \ | ||
446 | sizeof (struct GNUNET_TESTING_SharedService)); \ | ||
447 | } while (0) | ||
448 | |||
449 | slist = NULL; | ||
450 | n = 0; | ||
451 | ss.cfg = cfg; | ||
452 | for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL) | ||
453 | { | ||
454 | ss.service = NULL; | ||
455 | ss.share = 0; | ||
456 | if (2 != sscanf (arg, "%255s:%u", service, &ss.share)) | ||
457 | { | ||
458 | LOG (GNUNET_ERROR_TYPE_WARNING, "Ignoring shared service spec: %s", arg); | ||
459 | continue; | ||
460 | } | ||
461 | LOG_DEBUG ("Will be sharing %s service among %u peers\n", service, ss.share); | ||
462 | ss.service = GNUNET_strdup (service); | ||
463 | GROW_SS; | ||
464 | } | ||
465 | if (NULL != slist) | ||
466 | { | ||
467 | /* Add trailing NULL block */ | ||
468 | (void) memset (&ss, 0, sizeof (struct GNUNET_TESTING_SharedService)); | ||
469 | GROW_SS; | ||
470 | } | ||
471 | return slist; | ||
472 | #undef GROW_SS | ||
473 | } | ||
474 | |||
475 | |||
476 | /** | ||
443 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages | 477 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages |
444 | * | 478 | * |
445 | * @param cls NULL | 479 | * @param cls NULL |
@@ -453,6 +487,9 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
453 | const struct GNUNET_TESTBED_InitMessage *msg; | 487 | const struct GNUNET_TESTBED_InitMessage *msg; |
454 | struct GNUNET_TESTBED_Host *host; | 488 | struct GNUNET_TESTBED_Host *host; |
455 | const char *controller_hostname; | 489 | const char *controller_hostname; |
490 | char *ss_str; | ||
491 | struct GNUNET_TESTING_SharedService *ss; | ||
492 | unsigned int cnt; | ||
456 | uint16_t msize; | 493 | uint16_t msize; |
457 | 494 | ||
458 | if (NULL != GST_context) | 495 | if (NULL != GST_context) |
@@ -477,6 +514,16 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
477 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 514 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
478 | return; | 515 | return; |
479 | } | 516 | } |
517 | ss_str = NULL; | ||
518 | ss = NULL; | ||
519 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (our_config, "TESTBED", | ||
520 | "SHARED_SERVICES", | ||
521 | &ss_str)) | ||
522 | { | ||
523 | ss = parse_shared_services (ss_str, our_config); | ||
524 | GNUNET_free (ss_str); | ||
525 | ss_str = NULL; | ||
526 | } | ||
480 | GST_context = GNUNET_malloc (sizeof (struct Context)); | 527 | GST_context = GNUNET_malloc (sizeof (struct Context)); |
481 | GNUNET_SERVER_client_keep (client); | 528 | GNUNET_SERVER_client_keep (client); |
482 | GST_context->client = client; | 529 | GST_context->client = client; |
@@ -485,7 +532,17 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
485 | LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); | 532 | LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); |
486 | GST_context->system = | 533 | GST_context->system = |
487 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, | 534 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, |
488 | hostname, NULL); | 535 | hostname, ss); |
536 | if (NULL != ss) | ||
537 | { | ||
538 | for (cnt = 0; NULL != ss[cnt].service; cnt++) | ||
539 | { | ||
540 | ss_str = (char *) ss[cnt].service; | ||
541 | GNUNET_free (ss_str); | ||
542 | } | ||
543 | GNUNET_free (ss); | ||
544 | ss = NULL; | ||
545 | } | ||
489 | host = | 546 | host = |
490 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, | 547 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, |
491 | GST_context->master_ip, NULL, | 548 | GST_context->master_ip, NULL, |
@@ -614,93 +671,6 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client, | |||
614 | 671 | ||
615 | 672 | ||
616 | /** | 673 | /** |
617 | * Iterator over hash map entries. | ||
618 | * | ||
619 | * @param cls closure | ||
620 | * @param key current key code | ||
621 | * @param value value in the hash map | ||
622 | * @return GNUNET_YES if we should continue to | ||
623 | * iterate, | ||
624 | * GNUNET_NO if not. | ||
625 | */ | ||
626 | int | ||
627 | ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
628 | { | ||
629 | struct SharedService *queried_ss = cls; | ||
630 | struct SharedService *ss = value; | ||
631 | |||
632 | if (0 == strcmp (ss->name, queried_ss->name)) | ||
633 | return GNUNET_NO; | ||
634 | else | ||
635 | return GNUNET_YES; | ||
636 | } | ||
637 | |||
638 | |||
639 | /** | ||
640 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages | ||
641 | * | ||
642 | * @param cls NULL | ||
643 | * @param client identification of the client | ||
644 | * @param message the actual message | ||
645 | */ | ||
646 | static void | ||
647 | handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client, | ||
648 | const struct GNUNET_MessageHeader *message) | ||
649 | { | ||
650 | const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg; | ||
651 | struct SharedService *ss; | ||
652 | char *service_name; | ||
653 | struct GNUNET_HashCode hash; | ||
654 | uint16_t msg_size; | ||
655 | uint16_t service_name_size; | ||
656 | |||
657 | msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message; | ||
658 | msg_size = ntohs (message->size); | ||
659 | if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage)) | ||
660 | { | ||
661 | GNUNET_break (0); | ||
662 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
663 | return; | ||
664 | } | ||
665 | service_name_size = | ||
666 | msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage); | ||
667 | service_name = (char *) &msg[1]; | ||
668 | if ('\0' != service_name[service_name_size - 1]) | ||
669 | { | ||
670 | GNUNET_break (0); | ||
671 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
672 | return; | ||
673 | } | ||
674 | LOG_DEBUG ("Received service sharing request for %s, with %d peers\n", | ||
675 | service_name, ntohl (msg->num_peers)); | ||
676 | if (ntohl (msg->host_id) != GST_context->host_id) | ||
677 | { | ||
678 | route_message (ntohl (msg->host_id), message); | ||
679 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
680 | return; | ||
681 | } | ||
682 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
683 | ss = GNUNET_malloc (sizeof (struct SharedService)); | ||
684 | ss->name = strdup (service_name); | ||
685 | ss->num_shared = ntohl (msg->num_peers); | ||
686 | GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash); | ||
687 | if (GNUNET_SYSERR == | ||
688 | GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash, | ||
689 | &ss_exists_iterator, ss)) | ||
690 | { | ||
691 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
692 | "Service %s already configured as a shared service. " | ||
693 | "Ignoring service sharing request \n", ss->name); | ||
694 | GNUNET_free (ss->name); | ||
695 | GNUNET_free (ss); | ||
696 | return; | ||
697 | } | ||
698 | GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss, | ||
699 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
700 | } | ||
701 | |||
702 | |||
703 | /** | ||
704 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages | 674 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages |
705 | * | 675 | * |
706 | * @param cls NULL | 676 | * @param cls NULL |
@@ -802,29 +772,6 @@ GST_clear_fopcq () | |||
802 | 772 | ||
803 | 773 | ||
804 | /** | 774 | /** |
805 | * Iterator over hash map entries. | ||
806 | * | ||
807 | * @param cls closure | ||
808 | * @param key current key code | ||
809 | * @param value value in the hash map | ||
810 | * @return GNUNET_YES if we should continue to | ||
811 | * iterate, | ||
812 | * GNUNET_NO if not. | ||
813 | */ | ||
814 | static int | ||
815 | ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
816 | { | ||
817 | struct SharedService *ss = value; | ||
818 | |||
819 | GNUNET_assert (GNUNET_YES == | ||
820 | GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value)); | ||
821 | GNUNET_free (ss->name); | ||
822 | GNUNET_free (ss); | ||
823 | return GNUNET_YES; | ||
824 | } | ||
825 | |||
826 | |||
827 | /** | ||
828 | * Task to clean up and shutdown nicely | 775 | * Task to clean up and shutdown nicely |
829 | * | 776 | * |
830 | * @param cls NULL | 777 | * @param cls NULL |
@@ -838,9 +785,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
838 | 785 | ||
839 | shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; | 786 | shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; |
840 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n"); | 787 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n"); |
841 | (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator, | ||
842 | NULL); | ||
843 | GNUNET_CONTAINER_multihashmap_destroy (ss_map); | ||
844 | /* cleanup any remaining forwarded operations */ | 788 | /* cleanup any remaining forwarded operations */ |
845 | GST_clear_fopcq (); | 789 | GST_clear_fopcq (); |
846 | GST_free_lcfq (); | 790 | GST_free_lcfq (); |
@@ -926,8 +870,6 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
926 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | 870 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { |
927 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, | 871 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, |
928 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, | 872 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, |
929 | {&handle_configure_shared_service, NULL, | ||
930 | GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE, 0}, | ||
931 | {&GST_handle_link_controllers, NULL, | 873 | {&GST_handle_link_controllers, NULL, |
932 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | 874 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, |
933 | sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)}, | 875 | sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)}, |
@@ -985,7 +927,6 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
985 | our_config = GNUNET_CONFIGURATION_dup (cfg); | 927 | our_config = GNUNET_CONFIGURATION_dup (cfg); |
986 | GNUNET_SERVER_add_handlers (server, message_handlers); | 928 | GNUNET_SERVER_add_handlers (server, message_handlers); |
987 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); | 929 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); |
988 | ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); | ||
989 | shutdown_task_id = | 930 | shutdown_task_id = |
990 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, | 931 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, |
991 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 932 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in index b5687aa5b..5dbb86d9d 100644 --- a/src/testbed/testbed.conf.in +++ b/src/testbed/testbed.conf.in | |||
@@ -49,6 +49,23 @@ SETUP_TIMEOUT = 5 m | |||
49 | # Where should testbed write load statistics data | 49 | # Where should testbed write load statistics data |
50 | # STATS_DIR = /tmp/load | 50 | # STATS_DIR = /tmp/load |
51 | 51 | ||
52 | # What services should be shared among peers. | ||
53 | # Format is "[<service:share>] [<service:share>] ...". The shared services are | ||
54 | # started standalone without any other peer services or a hostkey. For this | ||
55 | # reason, only services which doesn't depend on other services can only be | ||
56 | # shared. Example: To share peerinfo among every 10 peers. The following spec | ||
57 | # will start 5 peerinfo services when 50 peers are started: | ||
58 | # | ||
59 | # SHARED_SERVICES = peerinfo:10 | ||
60 | # | ||
61 | # To share multiple services | ||
62 | # | ||
63 | # SHARED_SERVICES = service1:n_share1 service2:n_share2 ... | ||
64 | # | ||
65 | # Default is to share no services | ||
66 | SHARED_SERVICES = | ||
67 | |||
68 | |||
52 | [testbed-logger] | 69 | [testbed-logger] |
53 | AUTOSTART = NO | 70 | AUTOSTART = NO |
54 | @UNIXONLY@ PORT = 2102 | 71 | @UNIXONLY@ PORT = 2102 |
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index 933e1b8ee..ed4e27dc6 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -134,34 +134,6 @@ struct GNUNET_TESTBED_HostConfirmedMessage | |||
134 | 134 | ||
135 | 135 | ||
136 | /** | 136 | /** |
137 | * Message to testing service: configure service sharing | ||
138 | * at a host. | ||
139 | */ | ||
140 | struct GNUNET_TESTBED_ConfigureSharedServiceMessage | ||
141 | { | ||
142 | |||
143 | /** | ||
144 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE | ||
145 | */ | ||
146 | struct GNUNET_MessageHeader header; | ||
147 | |||
148 | /** | ||
149 | * Host that is being configured. | ||
150 | */ | ||
151 | uint32_t host_id GNUNET_PACKED; | ||
152 | |||
153 | /** | ||
154 | * Number of peers that should share a service instance; | ||
155 | * 1 for no sharing, 0 to forcefully disable the service. | ||
156 | */ | ||
157 | uint32_t num_peers GNUNET_PACKED; | ||
158 | |||
159 | /* followed by 0-terminated name of the service */ | ||
160 | |||
161 | }; | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Client notifies controller that it should delegate | 137 | * Client notifies controller that it should delegate |
166 | * requests for a particular client to a particular | 138 | * requests for a particular client to a particular |
167 | * sub-controller. | 139 | * sub-controller. |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index fda47e5f8..2df164a02 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -1508,46 +1508,6 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1508 | 1508 | ||
1509 | 1509 | ||
1510 | /** | 1510 | /** |
1511 | * Configure shared services at a controller. Using this function, | ||
1512 | * you can specify that certain services (such as "resolver") | ||
1513 | * should not be run for each peer but instead be shared | ||
1514 | * across N peers on the specified host. This function | ||
1515 | * must be called before any peers are created at the host. | ||
1516 | * | ||
1517 | * @param controller controller to configure | ||
1518 | * @param service_name name of the service to share | ||
1519 | * @param num_peers number of peers that should share one instance | ||
1520 | * of the specified service (1 for no sharing is the default), | ||
1521 | * use 0 to disable the service | ||
1522 | */ | ||
1523 | void | ||
1524 | GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller | ||
1525 | *controller, | ||
1526 | const char *service_name, | ||
1527 | uint32_t num_peers) | ||
1528 | { | ||
1529 | struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg; | ||
1530 | uint16_t service_name_size; | ||
1531 | uint16_t msg_size; | ||
1532 | |||
1533 | service_name_size = strlen (service_name) + 1; | ||
1534 | msg_size = | ||
1535 | sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage) + | ||
1536 | service_name_size; | ||
1537 | msg = GNUNET_malloc (msg_size); | ||
1538 | msg->header.size = htons (msg_size); | ||
1539 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE); | ||
1540 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host)); | ||
1541 | msg->num_peers = htonl (num_peers); | ||
1542 | memcpy (&msg[1], service_name, service_name_size); | ||
1543 | GNUNET_TESTBED_queue_message_ (controller, | ||
1544 | (struct GNUNET_MessageHeader *) msg); | ||
1545 | GNUNET_break (0); /* This function is not yet implemented on the | ||
1546 | * testbed service */ | ||
1547 | } | ||
1548 | |||
1549 | |||
1550 | /** | ||
1551 | * Iterator to free opc map entries | 1511 | * Iterator to free opc map entries |
1552 | * | 1512 | * |
1553 | * @param cls closure | 1513 | * @param cls closure |