aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-07 16:12:09 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-07 16:12:09 +0000
commit9279bfb981fff618746e93a2c5d1c1672f5d464a (patch)
treed3f90e8496e43fa21976f752092ea640da3c5166 /src/testbed
parent8e43ea79aeddfa0cf8b55d1d4a6610ce80e042b8 (diff)
downloadgnunet-9279bfb981fff618746e93a2c5d1c1672f5d464a.tar.gz
gnunet-9279bfb981fff618746e93a2c5d1c1672f5d464a.zip
-peer create message handler
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am1
-rw-r--r--src/testbed/gnunet-service-testbed.c216
-rw-r--r--src/testbed/testbed.h5
-rw-r--r--src/testbed/testbed_api_peers.c1
4 files changed, 199 insertions, 24 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 8a3912f5b..012f35e20 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -21,6 +21,7 @@ gnunet_service_testbed_SOURCES = \
21 gnunet-service-testbed.c 21 gnunet-service-testbed.c
22gnunet_service_testbed_LDADD = $(XLIB) \ 22gnunet_service_testbed_LDADD = $(XLIB) \
23 $(top_builddir)/src/util/libgnunetutil.la \ 23 $(top_builddir)/src/util/libgnunetutil.la \
24 $(top_builddir)/src/testing/libgnunettesting.la \
24 $(top_builddir)/src/testbed/libgnunettestbed.la \ 25 $(top_builddir)/src/testbed/libgnunettestbed.la \
25 $(LTLIBINTL) -lz 26 $(LTLIBINTL) -lz
26gnunet_service_testbed_DEPENDENCIES = \ 27gnunet_service_testbed_DEPENDENCIES = \
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index a89ae405c..d9eb9d617 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -32,6 +32,7 @@
32#include "testbed.h" 32#include "testbed.h"
33#include "gnunet_testbed_service.h" 33#include "gnunet_testbed_service.h"
34#include "testbed_api_hosts.h" 34#include "testbed_api_hosts.h"
35#include "gnunet_testing_lib-new.h"
35 36
36/** 37/**
37 * Generic logging 38 * Generic logging
@@ -250,6 +251,30 @@ struct LCFContextQueue
250 251
251 252
252/** 253/**
254 * A locally started peer
255 */
256struct Peer
257{
258 /**
259 * The peer handle from testing API
260 */
261 struct GNUNET_TESTING_Peer *peer;
262
263 /**
264 * The modified (by GNUNET_TESTING_peer_configure) configuration this peer is
265 * configured with
266 */
267 struct GNUNET_CONFIGURATION_Handle *cfg;
268
269 /**
270 * Our local reference id for this peer
271 */
272 uint32_t id;
273
274};
275
276
277/**
253 * The master context; generated with the first INIT message 278 * The master context; generated with the first INIT message
254 */ 279 */
255static struct Context *master_context; 280static struct Context *master_context;
@@ -308,6 +333,11 @@ static struct Route **route_list;
308static struct Slave **slave_list; 333static struct Slave **slave_list;
309 334
310/** 335/**
336 * A list of peers we own locally
337 */
338static struct Peer **peer_list;
339
340/**
311 * The hashmap of shared services 341 * The hashmap of shared services
312 */ 342 */
313static struct GNUNET_CONTAINER_MultiHashMap *ss_map; 343static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
@@ -327,6 +357,11 @@ static uint32_t route_list_size;
327 */ 357 */
328static uint32_t slave_list_size; 358static uint32_t slave_list_size;
329 359
360/**
361 * The size of the peer list
362 */
363static uint32_t peer_list_size;
364
330/*********/ 365/*********/
331/* Tasks */ 366/* Tasks */
332/*********/ 367/*********/
@@ -341,6 +376,15 @@ static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
341 */ 376 */
342static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; 377static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
343 378
379/******************/
380/* Testing System */
381/******************/
382
383/**
384 * Handle to the local testing system - for starting peers locally
385 */
386static struct GNUNET_TESTING_System *test_system;
387
344 388
345/** 389/**
346 * Function called to notify a client about the connection begin ready to queue 390 * Function called to notify a client about the connection begin ready to queue
@@ -412,6 +456,24 @@ queue_message (struct GNUNET_SERVER_Client *client,
412 456
413 457
414/** 458/**
459 * Similar to GNUNET_realloc; however clears tail part of newly allocated memory
460 *
461 * @param ptr the memory block to realloc
462 * @param size the size of ptr
463 * @param new_size the size to which ptr has to be realloc'ed
464 * @return the newly reallocated memory block
465 */
466static void *
467TESTBED_realloc (void *ptr, size_t size, size_t new_size)
468{
469 ptr = GNUNET_realloc (ptr, new_size);
470 if (new_size > size)
471 ptr = memset (ptr + size, 0, new_size - size);
472 return ptr;
473}
474
475
476/**
415 * Function to add a host to the current list of known hosts 477 * Function to add a host to the current list of known hosts
416 * 478 *
417 * @param host the host to add 479 * @param host the host to add
@@ -422,18 +484,16 @@ static int
422host_list_add (struct GNUNET_TESTBED_Host *host) 484host_list_add (struct GNUNET_TESTBED_Host *host)
423{ 485{
424 uint32_t host_id; 486 uint32_t host_id;
425 uint32_t new_size;
426 487
427 host_id = GNUNET_TESTBED_host_get_id_ (host); 488 host_id = GNUNET_TESTBED_host_get_id_ (host);
428 if (host_list_size <= host_id) 489 if (host_list_size <= host_id)
429 { 490 {
430 new_size = host_list_size + LIST_GROW_STEP; 491 host_list =
431 host_list = GNUNET_realloc (host_list, 492 TESTBED_realloc (host_list,
432 sizeof (struct GNUNET_TESTBED_Host *) 493 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size,
433 * new_size); 494 sizeof (struct GNUNET_TESTBED_Host *) *
434 memset (&host_list[host_list_size], 0, 495 (host_list_size + LIST_GROW_STEP));
435 sizeof (struct Slave *) * LIST_GROW_STEP); 496 host_list_size += LIST_GROW_STEP;
436 host_list_size = new_size;
437 } 497 }
438 if (NULL != host_list[host_id]) 498 if (NULL != host_list[host_id])
439 { 499 {
@@ -453,16 +513,14 @@ host_list_add (struct GNUNET_TESTBED_Host *host)
453static void 513static void
454route_list_add (struct Route *route) 514route_list_add (struct Route *route)
455{ 515{
456 uint32_t new_size;
457
458 if (route->dest >= route_list_size) 516 if (route->dest >= route_list_size)
459 { 517 {
460 new_size = route_list_size + LIST_GROW_STEP; 518 route_list =
461 route_list = GNUNET_realloc (route_list, sizeof (struct Route *) 519 TESTBED_realloc (route_list,
462 * new_size); 520 sizeof (struct Route *) * route_list_size,
463 memset (&route_list[route_list_size], 0, 521 sizeof (struct Route *) *
464 sizeof (struct Slave *) * LIST_GROW_STEP); 522 (route_list_size + LIST_GROW_STEP));
465 route_list_size = new_size; 523 route_list_size += LIST_GROW_STEP;
466 } 524 }
467 GNUNET_assert (NULL == route_list[route->dest]); 525 GNUNET_assert (NULL == route_list[route->dest]);
468 route_list[route->dest] = route; 526 route_list[route->dest] = route;
@@ -477,16 +535,13 @@ route_list_add (struct Route *route)
477static void 535static void
478slave_list_add (struct Slave *slave) 536slave_list_add (struct Slave *slave)
479{ 537{
480 uint32_t new_size;
481
482 if (slave->host_id >= slave_list_size) 538 if (slave->host_id >= slave_list_size)
483 { 539 {
484 new_size = slave_list_size + LIST_GROW_STEP; 540 slave_list = TESTBED_realloc (slave_list,
485 slave_list = GNUNET_realloc (slave_list, sizeof (struct Slave *) 541 sizeof (struct Slave *) *slave_list_size,
486 * new_size); 542 sizeof (struct Slave *) *
487 memset (&slave_list[slave_list_size], 0, 543 (slave_list_size) + LIST_GROW_STEP);
488 sizeof (struct Slave *) * LIST_GROW_STEP); 544 slave_list_size += LIST_GROW_STEP;
489 slave_list_size = new_size;
490 } 545 }
491 GNUNET_assert (NULL == slave_list[slave->host_id]); 546 GNUNET_assert (NULL == slave_list[slave->host_id]);
492 slave_list[slave->host_id] = slave; 547 slave_list[slave->host_id] = slave;
@@ -494,6 +549,27 @@ slave_list_add (struct Slave *slave)
494 549
495 550
496/** 551/**
552 * Adds a peer to the peer array
553 *
554 * @param route the route to add
555 */
556static void
557peer_list_add (struct Peer *peer)
558{
559 if (peer->id >= peer_list_size)
560 {
561 peer_list = TESTBED_realloc (peer_list,
562 sizeof (struct Peer *) *peer_list_size,
563 sizeof (struct Peer *) *
564 (peer_list_size) + LIST_GROW_STEP);
565 peer_list_size += LIST_GROW_STEP;
566 }
567 GNUNET_assert (NULL == peer_list[peer->id]);
568 peer_list[peer->id] = peer;
569}
570
571
572/**
497 * Routes message to a host given its host_id 573 * Routes message to a host given its host_id
498 * 574 *
499 * @param host_id the id of the destination host 575 * @param host_id the id of the destination host
@@ -749,6 +825,7 @@ int ss_exists_iterator (void *cls,
749 return GNUNET_YES; 825 return GNUNET_YES;
750} 826}
751 827
828
752/** 829/**
753 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages 830 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
754 * 831 *
@@ -993,6 +1070,93 @@ handle_link_controllers (void *cls,
993 1070
994 1071
995/** 1072/**
1073 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1074 *
1075 * @param cls NULL
1076 * @param client identification of the client
1077 * @param message the actual message
1078 */
1079static void
1080handle_peer_create (void *cls,
1081 struct GNUNET_SERVER_Client *client,
1082 const struct GNUNET_MessageHeader *message)
1083{
1084 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1085 struct GNUNET_CONFIGURATION_Handle *cfg;
1086 char *config;
1087 size_t dest_size;
1088 uint16_t msize;
1089 uint16_t config_size;
1090
1091
1092 msize = ntohs (message->size);
1093 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1094 {
1095 GNUNET_break (0); /* We need configuration */
1096 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1097 return;
1098 }
1099 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1100 if (ntohs (msg->host_id) == master_context->host_id)
1101 {
1102 struct Peer *peer;
1103 char *emsg;
1104
1105 /* We are responsidble for this peer */
1106 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1107 config_size = ntohl (msg->config_size);
1108 config = GNUNET_malloc (msg->config_size);
1109 if (Z_OK != uncompress ((Bytef *) config, (uLongf *) &dest_size,
1110 (const Bytef *) &msg[1], (uLong) msize))
1111 {
1112 GNUNET_break (0); /* uncompression error */
1113 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1114 return;
1115 }
1116 if (config_size == dest_size)
1117 {
1118 GNUNET_break (0);/* Uncompressed config size mismatch */
1119 GNUNET_free (config);
1120 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1121 return;
1122 }
1123 cfg = GNUNET_CONFIGURATION_create ();
1124 if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size,
1125 GNUNET_NO))
1126 {
1127 GNUNET_break (0); /* Configuration parsing error */
1128 GNUNET_free (config);
1129 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1130 return;
1131 }
1132 GNUNET_free (config);
1133 peer = GNUNET_malloc (sizeof (struct Peer));
1134 peer->cfg = cfg;
1135 peer->id = ntohl (msg->peer_id);
1136 peer->peer = GNUNET_TESTING_peer_configure (test_system, peer->cfg,
1137 peer->id,
1138 NULL /* Peer id */,
1139 &emsg);
1140 if (NULL == peer->peer)
1141 {
1142 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1143 GNUNET_free (emsg);
1144 GNUNET_break (0);
1145 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1146 return;
1147 }
1148 peer_list_add (peer);
1149 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1150 return;
1151 }
1152
1153 /* Forward the peer to other host */
1154 GNUNET_break (0);
1155 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1156}
1157
1158
1159/**
996 * Iterator over hash map entries. 1160 * Iterator over hash map entries.
997 * 1161 *
998 * @param cls closure 1162 * @param cls closure
@@ -1035,6 +1199,7 @@ shutdown_task (void *cls,
1035 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator, 1199 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
1036 NULL); 1200 NULL);
1037 GNUNET_CONTAINER_multihashmap_destroy (ss_map); 1201 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
1202 GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
1038 if (NULL != fh) 1203 if (NULL != fh)
1039 { 1204 {
1040 GNUNET_DISK_file_close (fh); 1205 GNUNET_DISK_file_close (fh);
@@ -1127,6 +1292,7 @@ testbed_run (void *cls,
1127 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0}, 1292 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
1128 {&handle_link_controllers, NULL, 1293 {&handle_link_controllers, NULL,
1129 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0}, 1294 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
1295 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
1130 {NULL} 1296 {NULL}
1131 }; 1297 };
1132 1298
@@ -1136,6 +1302,8 @@ testbed_run (void *cls,
1136 &client_disconnect_cb, 1302 &client_disconnect_cb,
1137 NULL); 1303 NULL);
1138 ss_map = GNUNET_CONTAINER_multihashmap_create (5); 1304 ss_map = GNUNET_CONTAINER_multihashmap_create (5);
1305 test_system = GNUNET_TESTING_system_create ("testbed_peers", NULL);
1306
1139 fh = GNUNET_DISK_get_handle_from_native (stdin); 1307 fh = GNUNET_DISK_get_handle_from_native (stdin);
1140 if (NULL == fh) 1308 if (NULL == fh)
1141 shutdown_task_id = 1309 shutdown_task_id =
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index 70c921a9f..fff76f2ec 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -207,6 +207,11 @@ struct GNUNET_TESTBED_PeerCreateMessage
207 */ 207 */
208 uint32_t peer_id GNUNET_PACKED; 208 uint32_t peer_id GNUNET_PACKED;
209 209
210 /**
211 * Size of the uncompressed configuration
212 */
213 uint32_t config_size GNUNET_PACKED;
214
210 /* followed by serialized peer configuration; 215 /* followed by serialized peer configuration;
211 gzip'ed configuration file in INI format */ 216 gzip'ed configuration file in INI format */
212 217
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 1ec827e37..844510cda 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -156,6 +156,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
156 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); 156 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
157 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host)); 157 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host));
158 msg->peer_id = htonl (peer->unique_id); 158 msg->peer_id = htonl (peer->unique_id);
159 msg->config_size = htonl (c_size);
159 GNUNET_TESTBED_queue_message (controller, 160 GNUNET_TESTBED_queue_message (controller,
160 (struct GNUNET_MessageHeader *) msg); 161 (struct GNUNET_MessageHeader *) msg);
161 return peer; 162 return peer;