/** * Function to call to start a peer_create type operation once all * queues the operation is part of declare that the * operation can be activated. * * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void opstart_peer_create (void *cls) { struct OperationContext *opc = cls; struct PeerCreateData *data; struct GNUNET_TESTBED_PeerCreateMessage *msg; char *config; char *xconfig; size_t c_size; size_t xc_size; uint16_t msize; GNUNET_assert (OP_PEER_CREATE == opc->type); data = opc->data; GNUNET_assert (NULL != data); GNUNET_assert (NULL != data->peer); opc->state = OPC_STATE_STARTED; config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size); xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); GNUNET_free (config); msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage); msg = GNUNET_realloc (xconfig, msize); memmove (&msg[1], msg, xc_size); msg->header.size = htons (msize); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); msg->operation_id = GNUNET_htonll (opc->id); msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); msg->peer_id = htonl (data->peer->unique_id); msg->config_size = htonl (c_size); GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); }
/** * Function called when a peer get information operation is ready * * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void opstart_peer_getinfo (void *cls) { struct OperationContext *opc = cls; struct PeerInfoData *data; struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; data = opc->data; GNUNET_assert (NULL != data); opc->state = OPC_STATE_STARTED; msg = GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, opc->id); GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); }
/** * Function called when a peer destroy operation is ready * * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void opstart_peer_destroy (void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_Peer *peer; struct GNUNET_TESTBED_PeerDestroyMessage *msg; GNUNET_assert (OP_PEER_DESTROY == opc->type); peer = opc->data; GNUNET_assert (NULL != peer); opc->state = OPC_STATE_STARTED; msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER); msg->peer_id = htonl (peer->unique_id); msg->operation_id = GNUNET_htonll (opc->id); GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); }
/** * Function called when a overlay connect operation is ready * * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void opstart_overlay_connect (void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_OverlayConnectMessage *msg; struct OverlayConnectData *data; opc->state = OPC_STATE_STARTED; data = opc->data; GNUNET_assert (NULL != data); msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)); msg->header.size = htons (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT); msg->peer1 = htonl (data->p1->unique_id); msg->peer2 = htonl (data->p2->unique_id); msg->operation_id = GNUNET_htonll (opc->id); msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); }
/** * Function called when a peer stop operation is ready * * @param cls the closure from GNUNET_TESTBED_operation_create_() */ static void opstart_peer_stop (void *cls) { struct OperationContext *opc = cls; struct GNUNET_TESTBED_PeerStopMessage *msg; struct PeerEventData *data; struct GNUNET_TESTBED_Peer *peer; GNUNET_assert (NULL != opc->data); data = opc->data; GNUNET_assert (NULL != data->peer); peer = data->peer; GNUNET_assert (PS_STARTED == peer->state); opc->state = OPC_STATE_STARTED; msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER); msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); msg->peer_id = htonl (peer->unique_id); msg->operation_id = GNUNET_htonll (opc->id); GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); }
/** * Register a host with the controller * * @param controller the controller handle * @param host the host to register * @param cc the completion callback to call to inform the status of * registration. After calling this callback the registration handle * will be invalid. Cannot be NULL. * @param cc_cls the closure for the cc * @return handle to the host registration which can be used to cancel the * registration */ struct GNUNET_TESTBED_HostRegistrationHandle * GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_HostRegistrationCompletion cc, void *cc_cls) { struct GNUNET_TESTBED_HostRegistrationHandle *rh; struct GNUNET_TESTBED_AddHostMessage *msg; const char *username; const char *hostname; char *config; char *cconfig; void *ptr; size_t cc_size; size_t config_size; uint16_t msg_size; uint16_t username_length; uint16_t hostname_length; if (NULL != controller->rh) return NULL; hostname = GNUNET_TESTBED_host_get_hostname (host); if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) { LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n", (NULL == hostname) ? "localhost" : hostname); return NULL; } rh = GNUNET_new (struct GNUNET_TESTBED_HostRegistrationHandle); rh->host = host; rh->c = controller; GNUNET_assert (NULL != cc); rh->cc = cc; rh->cc_cls = cc_cls; controller->rh = rh; username = GNUNET_TESTBED_host_get_username_ (host); username_length = 0; if (NULL != username) username_length = strlen (username); GNUNET_assert (NULL != hostname); /* Hostname must be present */ hostname_length = strlen (hostname); GNUNET_assert (NULL != host->cfg); config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size); cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); GNUNET_free (config); msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage)); msg_size += username_length; msg_size += hostname_length; msg_size += cc_size; msg = GNUNET_malloc (msg_size); msg->header.size = htons (msg_size); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host)); ptr = &msg[1]; if (NULL != username) { msg->username_length = htons (username_length); GNUNET_memcpy (ptr, username, username_length); ptr += username_length; } msg->hostname_length = htons (hostname_length); GNUNET_memcpy (ptr, hostname, hostname_length); ptr += hostname_length; msg->config_size = htons (config_size); GNUNET_memcpy (ptr, cconfig, cc_size); ptr += cc_size; GNUNET_assert ((ptr - (void *) msg) == msg_size); GNUNET_free (cconfig); GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg); return rh; }