diff options
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed.h | 4 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 49 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 54 |
3 files changed, 91 insertions, 16 deletions
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index 6d71f6c51..70c921a9f 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -24,8 +24,8 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #ifndef NEW_TESTING_H | 27 | #ifndef TESTBED_H |
28 | #define NEW_TESTING_H | 28 | #define TESTBED_H |
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | 31 | ||
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index c0967dca3..159b43daf 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -389,9 +389,9 @@ transmit_ready_notify (void *cls, size_t size, void *buf) | |||
389 | * @param controller the handle to the controller | 389 | * @param controller the handle to the controller |
390 | * @param msg the message to queue | 390 | * @param msg the message to queue |
391 | */ | 391 | */ |
392 | static void | 392 | void |
393 | queue_message (struct GNUNET_TESTBED_Controller *controller, | 393 | GNUNET_TESTBED_queue_message (struct GNUNET_TESTBED_Controller *controller, |
394 | struct GNUNET_MessageHeader *msg) | 394 | struct GNUNET_MessageHeader *msg) |
395 | { | 395 | { |
396 | struct MessageQueue *mq_entry; | 396 | struct MessageQueue *mq_entry; |
397 | uint16_t type; | 397 | uint16_t type; |
@@ -530,7 +530,7 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg | |||
530 | msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); | 530 | msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); |
531 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | 531 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); |
532 | msg->event_mask = GNUNET_htonll (controller->event_mask); | 532 | msg->event_mask = GNUNET_htonll (controller->event_mask); |
533 | queue_message (controller, (struct GNUNET_MessageHeader *) msg); | 533 | GNUNET_TESTBED_queue_message (controller, (struct GNUNET_MessageHeader *) msg); |
534 | return controller; | 534 | return controller; |
535 | } | 535 | } |
536 | 536 | ||
@@ -566,7 +566,7 @@ GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *c | |||
566 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host)); | 566 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host)); |
567 | msg->num_peers = htonl (num_peers); | 567 | msg->num_peers = htonl (num_peers); |
568 | memcpy (&msg[1], service_name, service_name_size); | 568 | memcpy (&msg[1], service_name, service_name_size); |
569 | queue_message (controller, (struct GNUNET_MessageHeader *) msg); | 569 | GNUNET_TESTBED_queue_message (controller, (struct GNUNET_MessageHeader *) msg); |
570 | } | 570 | } |
571 | 571 | ||
572 | 572 | ||
@@ -662,7 +662,7 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, | |||
662 | if (NULL != username) | 662 | if (NULL != username) |
663 | memcpy (&msg[1], username, user_name_length); | 663 | memcpy (&msg[1], username, user_name_length); |
664 | strcpy (((void *) &msg[1]) + user_name_length, hostname); | 664 | strcpy (((void *) &msg[1]) + user_name_length, hostname); |
665 | queue_message (controller, (struct GNUNET_MessageHeader *) msg); | 665 | GNUNET_TESTBED_queue_message (controller, (struct GNUNET_MessageHeader *) msg); |
666 | return rh; | 666 | return rh; |
667 | } | 667 | } |
668 | 668 | ||
@@ -730,11 +730,36 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master, | |||
730 | msg->config_size = htons ((uint16_t) scfg_size); | 730 | msg->config_size = htons ((uint16_t) scfg_size); |
731 | msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; | 731 | msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; |
732 | memcpy (&msg[1], sxcfg, sxcfg_size); | 732 | memcpy (&msg[1], sxcfg, sxcfg_size); |
733 | queue_message (master, (struct GNUNET_MessageHeader *) msg); | 733 | GNUNET_TESTBED_queue_message (master, (struct GNUNET_MessageHeader *) msg); |
734 | } | 734 | } |
735 | 735 | ||
736 | 736 | ||
737 | /** | 737 | /** |
738 | * Compresses given configuration using zlib compress | ||
739 | * | ||
740 | * @param config the serialized configuration | ||
741 | * @param size the size of config | ||
742 | * @param xconfig will be set to the compressed configuration (memory is fresly | ||
743 | * allocated) | ||
744 | * @return the size of the xconfig | ||
745 | */ | ||
746 | size_t | ||
747 | GNUNET_TESTBED_compress_config (const char *config, size_t size, | ||
748 | char **xconfig) | ||
749 | { | ||
750 | size_t xsize; | ||
751 | |||
752 | xsize = compressBound ((uLong) size); | ||
753 | *xconfig = GNUNET_malloc (xsize); | ||
754 | GNUNET_assert (Z_OK == | ||
755 | compress2 ((Bytef *)* xconfig, (uLongf *) &xsize, | ||
756 | (const Bytef *) config, (uLongf) size, | ||
757 | Z_BEST_SPEED)); | ||
758 | return xsize; | ||
759 | } | ||
760 | |||
761 | |||
762 | /** | ||
738 | * Create a link from slave controller to delegated controller. Whenever the | 763 | * Create a link from slave controller to delegated controller. Whenever the |
739 | * master controller is asked to start a peer at the delegated controller the | 764 | * master controller is asked to start a peer at the delegated controller the |
740 | * request will be routed towards slave controller (if a route exists). The | 765 | * request will be routed towards slave controller (if a route exists). The |
@@ -762,8 +787,8 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, | |||
762 | int is_subordinate) | 787 | int is_subordinate) |
763 | { | 788 | { |
764 | char *config; | 789 | char *config; |
765 | Bytef *cconfig; | 790 | char *cconfig; |
766 | uLongf cc_size; | 791 | size_t cc_size; |
767 | size_t config_size; | 792 | size_t config_size; |
768 | 793 | ||
769 | GNUNET_assert (GNUNET_YES == | 794 | GNUNET_assert (GNUNET_YES == |
@@ -772,11 +797,7 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, | |||
772 | GNUNET_assert (GNUNET_YES == | 797 | GNUNET_assert (GNUNET_YES == |
773 | GNUNET_TESTBED_is_host_registered_ (slave_host, master)); | 798 | GNUNET_TESTBED_is_host_registered_ (slave_host, master)); |
774 | config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size); | 799 | config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size); |
775 | cc_size = compressBound ((uLong) config_size); | 800 | cc_size = GNUNET_TESTBED_compress_config (config, config_size, &cconfig); |
776 | cconfig = GNUNET_malloc (cc_size); | ||
777 | GNUNET_assert (Z_OK == | ||
778 | compress2 (cconfig, &cc_size, | ||
779 | (Bytef *) config, config_size, Z_BEST_SPEED)); | ||
780 | GNUNET_free (config); | 801 | GNUNET_free (config); |
781 | GNUNET_assert ((UINT16_MAX - | 802 | GNUNET_assert ((UINT16_MAX - |
782 | sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) | 803 | sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h new file mode 100644 index 000000000..aee284c40 --- /dev/null +++ b/src/testbed/testbed_api.h | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/testbed_api.h | ||
23 | * @brief Interface for functions internally exported from testbed_api.c | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #ifndef TESTBED_API_H | ||
28 | #define TESTBED_API_H | ||
29 | |||
30 | /** | ||
31 | * Queues a message in send queue for sending to the service | ||
32 | * | ||
33 | * @param controller the handle to the controller | ||
34 | * @param msg the message to queue | ||
35 | */ | ||
36 | void | ||
37 | GNUNET_TESTBED_queue_message (struct GNUNET_TESTBED_Controller *controller, | ||
38 | struct GNUNET_MessageHeader *msg); | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Compresses given configuration using zlib compress | ||
43 | * | ||
44 | * @param config the serialized configuration | ||
45 | * @param size the size of config | ||
46 | * @param xconfig will be set to the compressed configuration (memory is fresly | ||
47 | * allocated) | ||
48 | * @return the size of the xconfig | ||
49 | */ | ||
50 | size_t | ||
51 | GNUNET_TESTBED_compress_config (const char *config, size_t size, | ||
52 | char **xconfig); | ||
53 | |||
54 | #endif | ||