/** * 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); }
/** * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages * * @param cls NULL * @param client identification of the client * @param message the actual message */ static void handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; struct Slave *slave; struct GNUNET_TESTBED_SlaveConfiguration *reply; const struct GNUNET_CONFIGURATION_Handle *cfg; char *config; char *xconfig; size_t config_size; size_t xconfig_size; size_t reply_size; uint64_t op_id; uint32_t slave_id; msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message; slave_id = ntohl (msg->slave_id); op_id = GNUNET_ntohll (msg->operation_id); if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id])) { /* FIXME: Add forwardings for this type of message here.. */ GST_send_operation_fail_msg (client, op_id, "Slave not found"); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } slave = GST_slave_list[slave_id]; GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id]))); config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); xconfig_size = GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); GNUNET_free (config); reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration); GNUNET_break (reply_size <= UINT16_MAX); GNUNET_break (config_size <= UINT16_MAX); reply = GNUNET_realloc (xconfig, reply_size); (void) memmove (&reply[1], reply, xconfig_size); reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); reply->header.size = htons ((uint16_t) reply_size); reply->slave_id = msg->slave_id; reply->operation_id = msg->operation_id; reply->config_size = htons ((uint16_t) config_size); GST_queue_message (client, &reply->header); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
/** * 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; }