2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file testbed/testbed_api.c
23 * @brief API for accessing the GNUnet testing service.
24 * This library is supposed to make it easier to write
25 * testcases and script large-scale benchmarks.
26 * @author Christian Grothoff
27 * @author Sree Harsha Totakura
32 #include "gnunet_testbed_service.h"
33 #include "gnunet_core_service.h"
34 #include "gnunet_constants.h"
35 #include "gnunet_transport_service.h"
36 #include "gnunet_hello_lib.h"
40 #include "testbed_api.h"
41 #include "testbed_api_hosts.h"
42 #include "testbed_api_peers.h"
43 #include "testbed_api_operations.h"
46 * Generic logging shorthand
48 #define LOG(kind, ...) \
49 GNUNET_log_from (kind, "testbed-api", __VA_ARGS__);
54 #define LOG_DEBUG(...) \
55 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
58 * Relative time seconds shorthand
60 #define TIME_REL_SECS(sec) \
61 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
65 * Default server message sending retry timeout
67 #define TIMEOUT_REL TIME_REL_SECS(1)
71 * The message queue for sending messages to the controller service
76 * The message to be sent
78 struct GNUNET_MessageHeader *msg;
81 * next pointer for DLL
83 struct MessageQueue *next;
86 * prev pointer for DLL
88 struct MessageQueue *prev;
93 * Structure for a controller link
98 * The next ptr for DLL
100 struct ControllerLink *next;
103 * The prev ptr for DLL
105 struct ControllerLink *prev;
108 * The host which will be referred in the peer start request. This is the
109 * host where the peer should be started
111 struct GNUNET_TESTBED_Host *delegated_host;
114 * The host which will contacted to delegate the peer start request
116 struct GNUNET_TESTBED_Host *slave_host;
119 * The configuration to be used to connect to slave host
121 const struct GNUNET_CONFIGURATION_Handle *slave_cfg;
124 * GNUNET_YES if the slave should be started (and stopped) by us; GNUNET_NO
125 * if we are just allowed to use the slave via TCP/IP
132 * handle for host registration
134 struct GNUNET_TESTBED_HostRegistrationHandle
137 * The host being registered
139 struct GNUNET_TESTBED_Host *host;
142 * The controller at which this host is being registered
144 struct GNUNET_TESTBED_Controller *c;
147 * The Registartion completion callback
149 GNUNET_TESTBED_HostRegistrationCompletion cc;
152 * The closure for above callback
159 * Context data for forwarded Operation
161 struct ForwardedOperationData
165 * The callback to call when reply is available
167 GNUNET_CLIENT_MessageHandler cc;
170 * The closure for the above callback
178 * Returns the operation context with the given id if found in the Operation
179 * context queues of the controller
181 * @param c the controller whose queues are searched
182 * @param id the id which has to be checked
183 * @return the matching operation context; NULL if no match found
185 static struct OperationContext *
186 find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
188 struct OperationContext *opc;
190 for (opc = c->ocq_head; NULL != opc; opc = opc->next)
200 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
201 * controller (testbed service)
203 * @param c the controller handler
204 * @param msg message received
205 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
209 handle_addhostconfirm (struct GNUNET_TESTBED_Controller *c,
210 const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
212 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
221 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
223 LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
224 GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id));
228 msg_size = ntohs (msg->header.size);
229 if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size)
231 LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
232 GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c);
233 rh->cc (rh->cc_cls, NULL);
237 /* We have an error message */
238 emsg = (char *) &msg[1];
239 if ('\0' != emsg[msg_size -
240 sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)])
246 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"),
247 ntohl (msg->host_id), emsg);
248 rh->cc (rh->cc_cls, emsg);
255 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
256 * controller (testbed service)
258 * @param c the controller handler
259 * @param msg message received
260 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
264 handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
266 GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg)
268 struct OperationContext *opc;
269 struct GNUNET_TESTBED_EventInformation *event;
272 op_id = GNUNET_ntohll (msg->operation_id);
273 LOG_DEBUG ("Operation %ul successful\n", op_id);
274 if (NULL == (opc = find_opc (c, op_id)))
276 LOG_DEBUG ("Operation not found\n");
280 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
281 event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation));
283 event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
288 struct ForwardedOperationData *fo_data;
291 if (NULL != fo_data->cc)
292 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
293 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
294 GNUNET_free (fo_data);
299 case OP_PEER_DESTROY:
301 struct GNUNET_TESTBED_Peer *peer;
308 case OP_LINK_CONTROLLERS:
315 event->details.operation_finished.operation = opc->op;
316 event->details.operation_finished.op_cls = NULL;
317 event->details.operation_finished.emsg = NULL;
318 event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC;
319 event->details.operation_finished.op_result.generic = NULL;
321 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
322 opc->state = OPC_STATE_FINISHED;
326 c->cc (c->cc_cls, event);
334 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS message from
335 * controller (testbed service)
337 * @param c the controller handler
338 * @param msg message received
339 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
343 handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
345 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
347 struct OperationContext *opc;
348 struct PeerCreateData *data;
349 struct GNUNET_TESTBED_Peer *peer;
350 GNUNET_TESTBED_PeerCreateCallback cb;
354 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)
355 == ntohs (msg->header.size));
356 op_id = GNUNET_ntohll (msg->operation_id);
357 if (NULL == (opc = find_opc (c, op_id)))
359 LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
362 if (OP_FORWARDED == opc->type)
364 struct ForwardedOperationData *fo_data;
367 if (NULL != fo_data->cc)
368 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
369 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
370 GNUNET_free (fo_data);
374 GNUNET_assert (OP_PEER_CREATE == opc->type);
375 GNUNET_assert (NULL != opc->data);
377 GNUNET_assert (NULL != data->peer);
379 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
380 peer->state = PS_CREATED;
383 GNUNET_free (opc->data);
384 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
385 opc->state = OPC_STATE_FINISHED;
387 cb (cls, peer, NULL);
393 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT message from
394 * controller (testbed service)
396 * @param c the controller handler
397 * @param msg message received
398 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
402 handle_peer_event (struct GNUNET_TESTBED_Controller *c,
403 const struct GNUNET_TESTBED_PeerEventMessage *msg)
405 struct OperationContext *opc;
406 struct GNUNET_TESTBED_Peer *peer;
407 struct GNUNET_TESTBED_EventInformation event;
410 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage)
411 == ntohs (msg->header.size));
412 op_id = GNUNET_ntohll (msg->operation_id);
413 if (NULL == (opc = find_opc (c, op_id)))
415 LOG_DEBUG ("Operation not found\n");
418 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
420 GNUNET_assert (NULL != peer);
421 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
424 case GNUNET_TESTBED_ET_PEER_START:
425 peer->state = PS_STARTED;
426 event.details.peer_start.host = peer->host;
427 event.details.peer_start.peer = peer;
429 case GNUNET_TESTBED_ET_PEER_STOP:
430 peer->state = PS_STOPPED;
431 event.details.peer_stop.peer = peer;
434 GNUNET_assert (0); /* We should never reach this state */
436 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
437 opc->state = OPC_STATE_FINISHED;
438 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP)
442 c->cc (c->cc_cls, &event);
449 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT message from
450 * controller (testbed service)
452 * @param c the controller handler
453 * @param msg message received
454 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
458 handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
459 const struct GNUNET_TESTBED_ConnectionEventMessage *msg)
461 struct OperationContext *opc;
462 struct OverlayConnectData *data;
463 struct GNUNET_TESTBED_EventInformation event;
466 op_id = GNUNET_ntohll (msg->operation_id);
467 if (NULL == (opc = find_opc (c, op_id)))
469 LOG_DEBUG ("Operation not found\n");
473 GNUNET_assert (NULL != data);
474 GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id)
475 && (ntohl (msg->peer2) == data->p2->unique_id));
476 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
479 case GNUNET_TESTBED_ET_CONNECT:
480 event.details.peer_connect.peer1 = data->p1;
481 event.details.peer_connect.peer2 = data->p2;
483 case GNUNET_TESTBED_ET_DISCONNECT:
484 GNUNET_assert (0); /* FIXME: implement */
487 GNUNET_assert (0); /* Should never reach here */
490 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
491 opc->state = OPC_STATE_FINISHED;
493 if (0 != ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT)
497 c->cc (c->cc_cls, &event);
504 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG message from
505 * controller (testbed service)
507 * @param c the controller handler
508 * @param msg message received
509 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
513 handle_peer_config (struct GNUNET_TESTBED_Controller *c,
514 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
516 struct OperationContext *opc;
517 struct GNUNET_TESTBED_Peer *peer;
518 struct PeerInfoData *data;
519 struct PeerInfoData2 *response_data;
520 struct GNUNET_TESTBED_EventInformation info;
523 op_id = GNUNET_ntohll (msg->operation_id);
524 if (NULL == (opc = find_opc (c, op_id)))
526 LOG_DEBUG ("Operation not found\n");
530 GNUNET_assert (NULL != data);
532 GNUNET_assert (NULL != peer);
533 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
534 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
536 LOG_DEBUG ("Skipping operation callback as flag not set\n");
539 response_data = GNUNET_malloc (sizeof (struct PeerInfoData2));
540 response_data->pit = data->pit;
543 info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
544 info.details.operation_finished.operation = opc->op;
545 info.details.operation_finished.op_cls = NULL;
546 info.details.operation_finished.emsg = NULL;
547 info.details.operation_finished.pit = response_data->pit;
548 switch (response_data->pit)
550 case GNUNET_TESTBED_PIT_IDENTITY:
552 struct GNUNET_PeerIdentity *peer_identity;
554 peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
555 (void) memcpy (peer_identity, &msg->peer_identity,
556 sizeof (struct GNUNET_PeerIdentity));
557 response_data->details.peer_identity = peer_identity;
558 info.details.operation_finished.op_result.pid = peer_identity;
561 case GNUNET_TESTBED_PIT_CONFIGURATION:
563 struct GNUNET_CONFIGURATION_Handle *cfg;
569 config_size = (uLong) ntohs (msg->config_size);
570 config = GNUNET_malloc (config_size);
571 msize = ntohs (msg->header.size);
572 msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
573 if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size,
574 (const Bytef *) &msg[1], (uLong) msize)))
576 cfg = GNUNET_CONFIGURATION_create (); /* Freed in oprelease_peer_getinfo */
577 GNUNET_assert (GNUNET_OK ==
578 GNUNET_CONFIGURATION_deserialize (cfg, config,
579 (size_t) config_size,
581 GNUNET_free (config);
582 response_data->details.cfg = cfg;
583 info.details.operation_finished.op_result.cfg = cfg;
586 case GNUNET_TESTBED_PIT_GENERIC:
587 GNUNET_assert (0); /* never reach here */
590 opc->data = response_data;
591 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
592 opc->state = OPC_STATE_FINISHED;
593 c->cc (c->cc_cls, &info);
599 * Handler for messages from controller (testbed service)
601 * @param cls the controller handler
602 * @param msg message received, NULL on timeout or fatal error
605 message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
607 struct GNUNET_TESTBED_Controller *c = cls;
611 c->in_receive = GNUNET_NO;
612 /* FIXME: Add checks for message integrity */
615 LOG_DEBUG ("Receive timed out or connection to service dropped\n");
619 msize = ntohs (msg->size);
620 switch (ntohs (msg->type))
622 case GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM:
623 GNUNET_assert (msize >= sizeof (struct
624 GNUNET_TESTBED_HostConfirmedMessage));
626 handle_addhostconfirm (c, (const struct GNUNET_TESTBED_HostConfirmedMessage *) msg);
628 case GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS:
630 (msize == sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage));
632 handle_opsuccess (c, (const struct
633 GNUNET_TESTBED_GenericOperationSuccessEventMessage
636 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS:
637 GNUNET_assert (msize ==
638 sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
640 handle_peer_create_success
641 (c, (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *)msg);
643 case GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT:
644 GNUNET_assert (msize == sizeof (struct GNUNET_TESTBED_PeerEventMessage));
646 handle_peer_event (c, (const struct GNUNET_TESTBED_PeerEventMessage *) msg);
649 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG:
650 GNUNET_assert (msize >=
651 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage));
654 (c, (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
657 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT:
658 GNUNET_assert (msize ==
659 sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
661 handle_peer_conevent (c, (const struct
662 GNUNET_TESTBED_ConnectionEventMessage *) msg);
667 if ((GNUNET_OK == status) && (GNUNET_NO == c->in_receive))
669 c->in_receive = GNUNET_YES;
670 GNUNET_CLIENT_receive (c->client, &message_handler, c,
671 GNUNET_TIME_UNIT_FOREVER_REL);
677 * Function called to notify a client about the connection begin ready to queue
678 * more data. "buf" will be NULL and "size" zero if the connection was closed
679 * for writing in the meantime.
682 * @param size number of bytes available in buf
683 * @param buf where the callee should write the message
684 * @return number of bytes written to buf
687 transmit_ready_notify (void *cls, size_t size, void *buf)
689 struct GNUNET_TESTBED_Controller *c = cls;
690 struct MessageQueue *mq_entry;
693 mq_entry = c->mq_head;
694 GNUNET_assert (NULL != mq_entry);
695 if ((0 == size) && (NULL == buf)) /* Timeout */
697 LOG_DEBUG ("Message sending timed out -- retrying\n");
699 GNUNET_CLIENT_notify_transmit_ready (c->client,
700 ntohs (mq_entry->msg->size),
702 GNUNET_YES, &transmit_ready_notify,
706 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
707 size = ntohs (mq_entry->msg->size);
708 memcpy (buf, mq_entry->msg, size);
709 LOG_DEBUG ("Message of type: %u and size: %u sent\n",
710 ntohs (mq_entry->msg->type), size);
711 GNUNET_free (mq_entry->msg);
712 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry);
713 GNUNET_free (mq_entry);
714 mq_entry = c->mq_head;
715 if (NULL != mq_entry)
717 GNUNET_CLIENT_notify_transmit_ready (c->client,
718 ntohs (mq_entry->msg->size),
720 GNUNET_YES, &transmit_ready_notify,
722 if (GNUNET_NO == c->in_receive)
724 c->in_receive = GNUNET_YES;
725 GNUNET_CLIENT_receive (c->client, &message_handler, c,
726 GNUNET_TIME_UNIT_FOREVER_REL);
733 * Queues a message in send queue for sending to the service
735 * @param controller the handle to the controller
736 * @param msg the message to queue
739 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
740 struct GNUNET_MessageHeader *msg)
742 struct MessageQueue *mq_entry;
746 type = ntohs (msg->type);
747 size = ntohs (msg->size);
748 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
749 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
750 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
752 LOG (GNUNET_ERROR_TYPE_DEBUG,
753 "Queueing message of type %u, size %u for sending\n", type,
755 GNUNET_CONTAINER_DLL_insert_tail (controller->mq_head, controller->mq_tail,
757 if (NULL == controller->th)
759 GNUNET_CLIENT_notify_transmit_ready (controller->client, size,
761 GNUNET_YES, &transmit_ready_notify,
767 * Sends the given message as an operation. The given callback is called when a
768 * reply for the operation is available. Call
769 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
770 * operation context if the cc hasn't been called
772 * @param controller the controller to which the message has to be sent
773 * @param operation_id the operation id of the message
774 * @param msg the message to send
775 * @param cc the callback to call when reply is available
776 * @param cc_cls the closure for the above callback
777 * @return the operation context which can be used to cancel the forwarded
780 struct OperationContext *
781 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
783 uint64_t operation_id,
784 const struct GNUNET_MessageHeader *msg,
785 GNUNET_CLIENT_MessageHandler cc,
788 struct OperationContext *opc;
789 struct ForwardedOperationData *data;
790 struct GNUNET_MessageHeader *dup_msg;
793 data = GNUNET_malloc (sizeof (struct ForwardedOperationData));
795 data->cc_cls = cc_cls;
796 opc = GNUNET_malloc (sizeof (struct OperationContext));
798 opc->type = OP_FORWARDED;
800 opc->id = operation_id;
801 msize = ntohs (msg->size);
802 dup_msg = GNUNET_malloc (msize);
803 (void) memcpy (dup_msg, msg, msize);
804 GNUNET_TESTBED_queue_message_ (opc->c, dup_msg);
805 GNUNET_CONTAINER_DLL_insert_tail (controller->ocq_head,
806 controller->ocq_tail, opc);
812 * Function to cancel an operation created by simply forwarding an operation
815 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
818 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc)
820 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
821 GNUNET_free (opc->data);
827 * Handle for controller process
829 struct GNUNET_TESTBED_ControllerProc
834 struct GNUNET_HELPER_Handle *helper;
837 * The host where the helper is run
839 struct GNUNET_TESTBED_Host *host;
842 * The controller error callback
844 GNUNET_TESTBED_ControllerStatusCallback cb;
847 * The closure for the above callback
852 * The send handle for the helper
854 struct GNUNET_HELPER_SendHandle *shandle;
857 * The message corresponding to send handle
859 struct GNUNET_MessageHeader *msg;
862 * The port number for ssh; used for helpers starting ssh
867 * The ssh destination string; used for helpers starting ssh
872 * The configuration of the running testbed service
874 struct GNUNET_CONFIGURATION_Handle *cfg;
880 * Functions with this signature are called whenever a
881 * complete message is received by the tokenizer.
883 * Do not call GNUNET_SERVER_mst_destroy in callback
886 * @param client identification of the client
887 * @param message the actual message
889 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
891 static int helper_mst (void *cls, void *client,
892 const struct GNUNET_MessageHeader *message)
894 struct GNUNET_TESTBED_ControllerProc *cp = cls;
895 const struct GNUNET_TESTBED_HelperReply *msg;
896 const char *hostname;
901 msg = (const struct GNUNET_TESTBED_HelperReply *) message;
902 GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply)
903 < ntohs (msg->header.size));
904 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY
905 == ntohs (msg->header.type));
906 config_size = (uLongf) ntohs (msg->config_size);
907 xconfig_size = (uLongf) (ntohs (msg->header.size)
908 - sizeof (struct GNUNET_TESTBED_HelperReply));
909 config = GNUNET_malloc (config_size);
910 GNUNET_assert (Z_OK == uncompress ((Bytef *) config, &config_size,
911 (const Bytef *) &msg[1], xconfig_size));
912 GNUNET_assert (NULL == cp->cfg);
913 cp->cfg = GNUNET_CONFIGURATION_create ();
914 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->cfg, config,
915 config_size, GNUNET_NO));
916 GNUNET_free (config);
917 if ((NULL == cp->host) ||
918 (NULL == (hostname = GNUNET_TESTBED_host_get_hostname_ (cp->host))))
919 hostname = "localhost";
920 /* Change the hostname so that we can connect to it */
921 GNUNET_CONFIGURATION_set_value_string (cp->cfg, "testbed", "hostname",
923 cp->cb (cp->cls, cp->cfg, GNUNET_OK);
929 * Continuation function from GNUNET_HELPER_send()
932 * @param result GNUNET_OK on success,
933 * GNUNET_NO if helper process died
934 * GNUNET_SYSERR during GNUNET_HELPER_stop
937 clear_msg (void *cls, int result)
939 struct GNUNET_TESTBED_ControllerProc *cp = cls;
941 GNUNET_assert (NULL != cp->shandle);
943 GNUNET_free (cp->msg);
948 * Callback that will be called when the helper process dies. This is not called
949 * when the helper process is stoped using GNUNET_HELPER_stop()
951 * @param cls the closure from GNUNET_HELPER_start()
954 helper_exp_cb (void *cls)
956 struct GNUNET_TESTBED_ControllerProc *cp = cls;
957 GNUNET_TESTBED_ControllerStatusCallback cb;
963 GNUNET_TESTBED_controller_stop (cp);
965 cb (cb_cls, NULL, GNUNET_SYSERR);
970 * Function to call to start a link-controllers type operation once all queues
971 * the operation is part of declare that the operation can be activated.
973 * @param cls the closure from GNUNET_TESTBED_operation_create_()
976 opstart_link_controllers (void *cls)
978 struct OperationContext *opc = cls;
979 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
981 GNUNET_assert (NULL != opc->data);
984 opc->state = OPC_STATE_STARTED;
985 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
986 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
991 * Callback which will be called when link-controllers type operation is released
993 * @param cls the closure from GNUNET_TESTBED_operation_create_()
996 oprelease_link_controllers (void *cls)
998 struct OperationContext *opc = cls;
1000 if (OPC_STATE_INIT == opc->state)
1001 GNUNET_free (opc->data);
1002 if (OPC_STATE_STARTED == opc->state)
1003 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
1009 * Starts a controller process at the host. FIXME: add controller start callback
1010 * with the configuration with which the controller is started
1012 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
1013 * host when starting testbed controller at host
1014 * @param host the host where the controller has to be started; NULL for
1016 * @param cfg template configuration to use for the remote controller; the
1017 * remote controller will be started with a slightly modified
1018 * configuration (port numbers, unix domain sockets and service home
1019 * values are changed as per TESTING library on the remote host)
1020 * @param cb function called when the controller is successfully started or
1021 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
1022 * called if cb is called with GNUNET_SYSERR as status. Will never be
1023 * called in the same task as 'GNUNET_TESTBED_controller_start'
1024 * (synchronous errors will be signalled by returning NULL). This
1025 * parameter cannot be NULL.
1026 * @param cls closure for above callbacks
1027 * @return the controller process handle, NULL on errors
1029 struct GNUNET_TESTBED_ControllerProc *
1030 GNUNET_TESTBED_controller_start (const char *controller_ip,
1031 struct GNUNET_TESTBED_Host *host,
1032 const struct GNUNET_CONFIGURATION_Handle *cfg,
1033 GNUNET_TESTBED_ControllerStatusCallback cb,
1036 struct GNUNET_TESTBED_ControllerProc *cp;
1037 struct GNUNET_TESTBED_HelperInit *msg;
1039 cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
1040 if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host)))
1042 char * const binary_argv[] = {
1043 "gnunet-testbed-helper", NULL
1046 cp->helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv,
1047 &helper_mst, &helper_exp_cb, cp);
1051 char *remote_args[6 + 1];
1053 const char *username;
1054 const char *hostname;
1056 username = GNUNET_TESTBED_host_get_username_ (host);
1057 hostname = GNUNET_TESTBED_host_get_hostname_ (host);
1058 GNUNET_asprintf (&cp->port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host));
1059 if (NULL == username)
1060 GNUNET_asprintf (&cp->dst, "%s", hostname);
1062 GNUNET_asprintf (&cp->dst, "%s@%s", username, hostname);
1063 LOG_DEBUG ("Starting SSH to destination %s\n", cp->dst);
1065 remote_args[argp++] = "ssh";
1066 remote_args[argp++] = "-p";
1067 remote_args[argp++] = cp->port;
1068 remote_args[argp++] = "-q";
1069 remote_args[argp++] = cp->dst;
1070 remote_args[argp++] = "gnunet-testbed-helper";
1071 remote_args[argp++] = NULL;
1072 GNUNET_assert (argp == 6 + 1);
1073 cp->helper = GNUNET_HELPER_start ("ssh", remote_args,
1074 &helper_mst, &helper_exp_cb, cp);
1076 if (NULL == cp->helper)
1078 GNUNET_free_non_null (cp->port);
1079 GNUNET_free_non_null (cp->dst);
1086 msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg);
1087 cp->msg = &msg->header;
1088 cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO,
1090 if (NULL == cp->shandle)
1093 GNUNET_TESTBED_controller_stop (cp);
1101 * Stop the controller process (also will terminate all peers and controllers
1102 * dependent on this controller). This function blocks until the testbed has
1103 * been fully terminated (!).
1105 * @param cproc the controller process handle
1108 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
1110 if (NULL != cproc->shandle)
1111 GNUNET_HELPER_send_cancel (cproc->shandle);
1112 if (NULL != cproc->helper)
1113 GNUNET_HELPER_stop (cproc->helper);
1114 if (NULL != cproc->cfg)
1115 GNUNET_CONFIGURATION_destroy (cproc->cfg);
1116 GNUNET_free_non_null (cproc->port);
1117 GNUNET_free_non_null (cproc->dst);
1118 GNUNET_free (cproc);
1123 * Start a controller process using the given configuration at the
1126 * @param cfg configuration to use
1127 * @param host host to run the controller on; This should be the same host if
1128 * the controller was previously started with
1129 * GNUNET_TESTBED_controller_start; NULL for localhost
1130 * @param event_mask bit mask with set of events to call 'cc' for;
1131 * or-ed values of "1LL" shifted by the
1132 * respective 'enum GNUNET_TESTBED_EventType'
1133 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
1134 * @param cc controller callback to invoke on events
1135 * @param cc_cls closure for cc
1136 * @return handle to the controller
1138 struct GNUNET_TESTBED_Controller *
1139 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1140 struct GNUNET_TESTBED_Host *host,
1141 uint64_t event_mask,
1142 GNUNET_TESTBED_ControllerCallback cc,
1145 struct GNUNET_TESTBED_Controller *controller;
1146 struct GNUNET_TESTBED_InitMessage *msg;
1147 const char *controller_hostname;
1148 unsigned long long max_parallel_peer_create;
1151 GNUNET_CONFIGURATION_get_value_number (cfg, "testbed",
1152 "MAX_PARALLEL_PEER_CREATE",
1153 &max_parallel_peer_create))
1158 controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
1159 controller->cc = cc;
1160 controller->cc_cls = cc_cls;
1161 controller->event_mask = event_mask;
1162 controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
1163 controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg);
1164 if (NULL == controller->client)
1166 GNUNET_TESTBED_controller_disconnect (controller);
1171 host = GNUNET_TESTBED_host_create_by_id_ (0);
1172 if (NULL == host) /* If the above host create fails */
1174 LOG (GNUNET_ERROR_TYPE_WARNING,
1175 "Treating NULL host as localhost. Multiple references to localhost "
1176 "may break when localhost freed before calling disconnect \n");
1177 host = GNUNET_TESTBED_host_lookup_by_id_ (0);
1181 controller->aux_host = GNUNET_YES;
1184 GNUNET_assert (NULL != host);
1185 GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
1186 controller->host = host;
1187 controller->opq_peer_create =
1188 GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
1189 max_parallel_peer_create);
1190 controller_hostname = GNUNET_TESTBED_host_get_hostname_ (host);
1191 if (NULL == controller_hostname)
1192 controller_hostname = "127.0.0.1";
1193 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)
1194 + strlen (controller_hostname) + 1);
1195 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
1196 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)
1197 + strlen (controller_hostname) + 1);
1198 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1199 msg->event_mask = GNUNET_htonll (controller->event_mask);
1200 strcpy ((char *) &msg[1], controller_hostname);
1201 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *)
1208 * Configure shared services at a controller. Using this function,
1209 * you can specify that certain services (such as "resolver")
1210 * should not be run for each peer but instead be shared
1211 * across N peers on the specified host. This function
1212 * must be called before any peers are created at the host.
1214 * @param controller controller to configure
1215 * @param service_name name of the service to share
1216 * @param num_peers number of peers that should share one instance
1217 * of the specified service (1 for no sharing is the default),
1218 * use 0 to disable the service
1221 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
1222 const char *service_name,
1225 struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1226 uint16_t service_name_size;
1229 service_name_size = strlen (service_name) + 1;
1230 msg_size = sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage)
1231 + service_name_size;
1232 msg = GNUNET_malloc (msg_size);
1233 msg->header.size = htons (msg_size);
1234 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE);
1235 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host));
1236 msg->num_peers = htonl (num_peers);
1237 memcpy (&msg[1], service_name, service_name_size);
1238 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg);
1243 * disconnects from the controller.
1245 * @param controller handle to controller to stop
1248 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller)
1250 struct MessageQueue *mq_entry;
1252 if (NULL != controller->th)
1253 GNUNET_CLIENT_notify_transmit_ready_cancel (controller->th);
1254 /* Clear the message queue */
1255 while (NULL != (mq_entry = controller->mq_head))
1257 GNUNET_CONTAINER_DLL_remove (controller->mq_head,
1258 controller->mq_tail,
1260 GNUNET_free (mq_entry->msg);
1261 GNUNET_free (mq_entry);
1263 if (NULL != controller->client)
1264 GNUNET_CLIENT_disconnect (controller->client);
1265 GNUNET_CONFIGURATION_destroy (controller->cfg);
1266 if (GNUNET_YES == controller->aux_host)
1267 GNUNET_TESTBED_host_destroy (controller->host);
1268 GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_peer_create);
1269 GNUNET_free (controller);
1274 * Register a host with the controller
1276 * @param controller the controller handle
1277 * @param host the host to register
1278 * @param cc the completion callback to call to inform the status of
1279 * registration. After calling this callback the registration handle
1280 * will be invalid. Cannot be NULL.
1281 * @param cc_cls the closure for the cc
1282 * @return handle to the host registration which can be used to cancel the
1285 struct GNUNET_TESTBED_HostRegistrationHandle *
1286 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1287 struct GNUNET_TESTBED_Host *host,
1288 GNUNET_TESTBED_HostRegistrationCompletion cc,
1291 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
1292 struct GNUNET_TESTBED_AddHostMessage *msg;
1293 const char *username;
1294 const char *hostname;
1296 uint16_t user_name_length;
1298 if (NULL != controller->rh)
1300 hostname = GNUNET_TESTBED_host_get_hostname_ (host);
1301 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
1303 LOG (GNUNET_ERROR_TYPE_WARNING,
1304 "Host hostname: %s already registered\n",
1305 (NULL == hostname) ? "localhost" : hostname);
1308 rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle));
1311 GNUNET_assert (NULL != cc);
1313 rh->cc_cls = cc_cls;
1314 controller->rh = rh;
1315 username = GNUNET_TESTBED_host_get_username_ (host);
1316 msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage));
1317 user_name_length = 0;
1318 if (NULL != username)
1320 user_name_length = strlen (username) + 1;
1321 msg_size += user_name_length;
1323 /* FIXME: what happens when hostname is NULL? localhost */
1324 GNUNET_assert (NULL != hostname);
1325 msg_size += strlen (hostname) + 1;
1326 msg = GNUNET_malloc (msg_size);
1327 msg->header.size = htons (msg_size);
1328 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST);
1329 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1330 msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host));
1331 msg->user_name_length = htons (user_name_length);
1332 if (NULL != username)
1333 memcpy (&msg[1], username, user_name_length);
1334 strcpy (((void *) &msg[1]) + user_name_length, hostname);
1335 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg);
1341 * Cancel the pending registration. Note that if the registration message is
1342 * already sent to the service the cancellation has only the effect that the
1343 * registration completion callback for the registration is never called.
1345 * @param handle the registration handle to cancel
1348 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
1351 if (handle != handle->c->rh)
1356 handle->c->rh = NULL;
1357 GNUNET_free (handle);
1362 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
1363 * serialized and compressed
1365 * @param master handle to the master controller who creates the association
1366 * @param delegated_host requests to which host should be delegated; cannot be NULL
1367 * @param slave_host which host is used to run the slave controller; use NULL to
1368 * make the master controller connect to the delegated host
1369 * @param sxcfg serialized and compressed configuration
1370 * @param sxcfg_size the size scfg
1371 * @param scfg_size the size of uncompressed serialized configuration
1372 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
1373 * be started by the master controller; GNUNET_NO if we are just
1374 * allowed to use the slave via TCP/IP
1376 struct GNUNET_TESTBED_Operation *
1377 GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
1378 struct GNUNET_TESTBED_Host *delegated_host,
1379 struct GNUNET_TESTBED_Host *slave_host,
1385 struct OperationContext *opc;
1386 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1389 GNUNET_assert (GNUNET_YES ==
1390 GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
1391 if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host)))
1392 GNUNET_assert (GNUNET_YES ==
1393 GNUNET_TESTBED_is_host_registered_ (slave_host, master));
1394 msg_size = sxcfg_size + sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1395 msg = GNUNET_malloc (msg_size);
1396 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS);
1397 msg->header.size = htons (msg_size);
1398 msg->delegated_host_id = htonl (GNUNET_TESTBED_host_get_id_ (delegated_host));
1399 msg->slave_host_id = htonl (GNUNET_TESTBED_host_get_id_
1400 ((NULL != slave_host) ? slave_host : master->host));
1401 msg->config_size = htons ((uint16_t) scfg_size);
1402 msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
1403 memcpy (&msg[1], sxcfg, sxcfg_size);
1404 opc = GNUNET_malloc (sizeof (struct OperationContext));
1407 opc->type = OP_LINK_CONTROLLERS;
1408 opc->id = master->operation_counter++;
1409 opc->state = OPC_STATE_INIT;
1410 msg->operation_id = GNUNET_htonll (opc->id);
1411 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_link_controllers,
1412 &oprelease_link_controllers);
1413 GNUNET_TESTBED_operation_queue_insert_ (master->opq_peer_create, opc->op);
1419 * Compresses given configuration using zlib compress
1421 * @param config the serialized configuration
1422 * @param size the size of config
1423 * @param xconfig will be set to the compressed configuration (memory is fresly
1425 * @return the size of the xconfig
1428 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
1433 xsize = compressBound ((uLong) size);
1434 *xconfig = GNUNET_malloc (xsize);
1435 GNUNET_assert (Z_OK ==
1436 compress2 ((Bytef *)* xconfig, (uLongf *) &xsize,
1437 (const Bytef *) config, (uLongf) size,
1444 * Create a link from slave controller to delegated controller. Whenever the
1445 * master controller is asked to start a peer at the delegated controller the
1446 * request will be routed towards slave controller (if a route exists). The
1447 * slave controller will then route it to the delegated controller. The
1448 * configuration of the slave controller is given and to be used to either
1449 * create the slave controller or to connect to an existing slave controller
1450 * process. 'is_subordinate' specifies if the given slave controller should be
1451 * started and managed by the master controller, or if the slave already has a
1452 * master and this is just a secondary master that is also allowed to use the
1455 * @param master handle to the master controller who creates the association
1456 * @param delegated_host requests to which host should be delegated
1457 * @param slave_host which host is used to run the slave controller
1458 * @param slave_cfg configuration to use for the slave controller
1459 * @param is_subordinate GNUNET_YES if the slave should be started (and stopped)
1460 * by the master controller; GNUNET_NO if we are just
1461 * allowed to use the slave via TCP/IP
1462 * @return the operation handle
1464 struct GNUNET_TESTBED_Operation *
1465 GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
1466 struct GNUNET_TESTBED_Host *delegated_host,
1467 struct GNUNET_TESTBED_Host *slave_host,
1468 const struct GNUNET_CONFIGURATION_Handle *slave_cfg,
1471 struct GNUNET_TESTBED_Operation *op;
1477 GNUNET_assert (GNUNET_YES ==
1478 GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
1479 if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host)))
1480 GNUNET_assert (GNUNET_YES ==
1481 GNUNET_TESTBED_is_host_registered_ (slave_host, master));
1482 config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size);
1483 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
1484 GNUNET_free (config);
1485 GNUNET_assert ((UINT16_MAX -
1486 sizeof (struct GNUNET_TESTBED_ControllerLinkMessage))
1487 >= cc_size); /* Configuration doesn't fit in 1 message */
1488 op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host,
1489 (const char *) cconfig,
1490 cc_size, config_size, is_subordinate);
1491 GNUNET_free (cconfig);
1497 * Ask the testbed controller to write the current overlay topology to
1498 * a file. Naturally, the file will only contain a snapshot as the
1499 * topology may evolve all the time.
1501 * @param controller overlay controller to inspect
1502 * @param filename name of the file the topology should
1506 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1507 const char *filename)
1514 * Creates a helper initialization message. This function is here because we
1515 * want to use this in testing
1517 * @param cname the ip address of the controlling host
1518 * @param cfg the configuration that has to used to start the testbed service
1520 * @return the initialization message
1522 struct GNUNET_TESTBED_HelperInit *
1523 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
1524 const struct GNUNET_CONFIGURATION_Handle *cfg)
1526 struct GNUNET_TESTBED_HelperInit *msg;
1530 size_t xconfig_size;
1534 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
1535 GNUNET_assert (NULL != config);
1537 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1538 GNUNET_free (config);
1539 cname_len = strlen (cname);
1540 msg_size = xconfig_size + cname_len + 1 +
1541 sizeof (struct GNUNET_TESTBED_HelperInit);
1542 msg = GNUNET_realloc (xconfig, msg_size);
1543 (void) memmove ( ((void *) &msg[1]) + cname_len + 1, msg, xconfig_size);
1544 msg->header.size = htons (msg_size);
1545 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
1546 msg->cname_size = htons (cname_len);
1547 msg->config_size = htons (config_size);
1548 (void) strcpy ((char *) &msg[1], cname);
1554 * Cancel a pending operation. Releases all resources
1555 * of the operation and will ensure that no event
1556 * is generated for the operation. Does NOT guarantee
1557 * that the operation will be fully undone (or that
1558 * nothing ever happened).
1560 * @param operation operation to cancel
1563 GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation)
1565 GNUNET_TESTBED_operation_done (operation);
1570 * Signal that the information from an operation has been fully
1571 * processed. This function MUST be called for each event
1572 * of type 'operation_finished' to fully remove the operation
1573 * from the operation queue. After calling this function, the
1574 * 'op_result' becomes invalid (!).
1576 * @param operation operation to signal completion for
1579 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
1581 switch (operation->type)
1583 case OP_PEER_CREATE:
1584 case OP_PEER_DESTROY:
1588 case OP_OVERLAY_CONNECT:
1589 case OP_LINK_CONTROLLERS:
1590 GNUNET_TESTBED_operation_release_ (operation);
1598 /* end of testbed_api.c */